comparison app/models/document.rb @ 1338:25603efa57b5

Merge from live branch
author Chris Cannam
date Thu, 20 Jun 2013 13:14:14 +0100
parents 433d4f72a19b
children 622f24f53b42 261b3d9a4903
comparison
equal deleted inserted replaced
1209:1b1138f6f55e 1338:25603efa57b5
1 # RedMine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
28 acts_as_activity_provider :find_options => {:include => :project} 28 acts_as_activity_provider :find_options => {:include => :project}
29 29
30 validates_presence_of :project, :title, :category 30 validates_presence_of :project, :title, :category
31 validates_length_of :title, :maximum => 60 31 validates_length_of :title, :maximum => 60
32 32
33 named_scope :visible, lambda {|*args| { :include => :project, 33 scope :visible, lambda {|*args| { :include => :project,
34 :conditions => Project.allowed_to_condition(args.shift || User.current, :view_documents, *args) } } 34 :conditions => Project.allowed_to_condition(args.shift || User.current, :view_documents, *args) } }
35 35
36 safe_attributes 'category_id', 'title', 'description' 36 safe_attributes 'category_id', 'title', 'description'
37 37
38 def visible?(user=User.current) 38 def visible?(user=User.current)
39 !user.nil? && user.allowed_to?(:view_documents, project) 39 !user.nil? && user.allowed_to?(:view_documents, project)
40 end 40 end
41 41
42 def after_initialize 42 def initialize(attributes=nil, *args)
43 super
43 if new_record? 44 if new_record?
44 self.category ||= DocumentCategory.default 45 self.category ||= DocumentCategory.default
45 end 46 end
46 end 47 end
47 48
48 def updated_on 49 def updated_on
49 unless @updated_on 50 unless @updated_on
50 a = attachments.find(:first, :order => 'created_on DESC') 51 a = attachments.last
51 @updated_on = (a && a.created_on) || created_on 52 @updated_on = (a && a.created_on) || created_on
52 end 53 end
53 @updated_on 54 @updated_on
54 end 55 end
55 end 56 end