You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

document.rb 2.4 kB

13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2013 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. class Document < ActiveRecord::Base
  18. include Redmine::SafeAttributes
  19. belongs_to :project
  20. belongs_to :user
  21. belongs_to :category, :class_name => "DocumentCategory", :foreign_key => "category_id"
  22. before_save :be_user_score # user_score
  23. acts_as_attachable :delete_permission => :delete_documents
  24. acts_as_searchable :columns => ['title', "#{table_name}.description"], :include => :project
  25. acts_as_event :title => Proc.new {|o| "#{l(:label_document)}: #{o.title}"},
  26. :author => Proc.new {|o| o.attachments.reorder("#{Attachment.table_name}.created_on ASC").first.try(:author) },
  27. :url => Proc.new {|o| {:controller => 'documents', :action => 'show', :id => o.id}}
  28. acts_as_activity_provider :find_options => {:include => :project}
  29. validates_presence_of :project, :title, :category
  30. validates_length_of :title, :maximum => 60
  31. scope :visible, lambda {|*args|
  32. includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_documents, *args))
  33. }
  34. safe_attributes 'category_id', 'title', 'description'
  35. def visible?(user=User.current)
  36. !user.nil? && user.allowed_to?(:view_documents, project)
  37. end
  38. def initialize(attributes=nil, *args)
  39. super
  40. if new_record?
  41. self.category ||= DocumentCategory.default
  42. end
  43. end
  44. def updated_on
  45. unless @updated_on
  46. a = attachments.last
  47. @updated_on = (a && a.created_on) || created_on
  48. end
  49. @updated_on
  50. end
  51. # update user score
  52. def be_user_score
  53. if self.new_record?
  54. UserScore.project(:push_document, self.user, { document_id: self.id })
  55. end
  56. end
  57. end

软件技术创新是当今国家整体创新能力的重要基础和发展引擎。近年来,大众参与的软件创新与创业活动已经成为网络时代软件开发和应用的新形态,正在快速改变着全球软件创新模式和软件产业格局。 ...