Class: Document

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Redmine::SafeAttributes
Defined in:
app/models/document.rb

Overview

– copyright ChiliProject is a project management system.

Copyright (C) 2010-2013 the ChiliProject Team

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

See doc/COPYRIGHT.rdoc for more details. ++

Instance Method Summary collapse

Methods included from Redmine::SafeAttributes

#delete_unsafe_attributes, included, #safe_attribute_names, #safe_attributes=

Instance Method Details

#after_initializeObject


42
43
44
45
46
47
48
# File 'app/models/document.rb', line 42

def after_initialize
  if new_record? && DocumentCategory.default.present?
    # FIXME: on Rails 3 use this instead
    # self.category ||= DocumentCategory.default
    self.category_id = DocumentCategory.default.id if self.category_id == 0
  end
end

#recipientsObject


58
59
60
61
62
# File 'app/models/document.rb', line 58

def recipients
  mails = super # from acts_as_event
  mails += watcher_recipients
  mails.uniq
end

#updated_onObject


50
51
52
53
54
55
56
# File 'app/models/document.rb', line 50

def updated_on
  unless @updated_on
    a = attachments.find(:first, :order => 'created_on DESC')
    @updated_on = (a && a.created_on) || created_on
  end
  @updated_on
end

#visible?(user = User.current) ⇒ Boolean

Returns:

  • (Boolean)

38
39
40
# File 'app/models/document.rb', line 38

def visible?(user=User.current)
  !user.nil? && user.allowed_to?(:view_documents, project)
end