comparison app/models/message.rb @ 929:5f33065ddc4b redmine-1.3

Update to Redmine SVN rev 9414 on 1.3-stable branch
author Chris Cannam
date Wed, 27 Jun 2012 14:54:18 +0100
parents cbb26bc654de
children 433d4f72a19b
comparison
equal deleted inserted replaced
909:cbb26bc654de 929:5f33065ddc4b
14 # You should have received a copy of the GNU General Public License 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 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. 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 class Message < ActiveRecord::Base 18 class Message < ActiveRecord::Base
19 include Redmine::SafeAttributes
19 belongs_to :board 20 belongs_to :board
20 belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' 21 belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
21 acts_as_tree :counter_cache => :replies_count, :order => "#{Message.table_name}.created_on ASC" 22 acts_as_tree :counter_cache => :replies_count, :order => "#{Message.table_name}.created_on ASC"
22 acts_as_attachable 23 acts_as_attachable
23 belongs_to :last_reply, :class_name => 'Message', :foreign_key => 'last_reply_id' 24 belongs_to :last_reply, :class_name => 'Message', :foreign_key => 'last_reply_id'
34 35
35 acts_as_activity_provider :find_options => {:include => [{:board => :project}, :author]}, 36 acts_as_activity_provider :find_options => {:include => [{:board => :project}, :author]},
36 :author_key => :author_id 37 :author_key => :author_id
37 acts_as_watchable 38 acts_as_watchable
38 39
39 attr_protected :locked, :sticky
40 validates_presence_of :board, :subject, :content 40 validates_presence_of :board, :subject, :content
41 validates_length_of :subject, :maximum => 255 41 validates_length_of :subject, :maximum => 255
42 validate :cannot_reply_to_locked_topic, :on => :create 42 validate :cannot_reply_to_locked_topic, :on => :create
43 43
44 after_create :add_author_as_watcher, :update_parent_last_reply 44 after_create :add_author_as_watcher, :update_parent_last_reply
45 after_update :update_messages_board 45 after_update :update_messages_board
46 after_destroy :reset_board_counters 46 after_destroy :reset_board_counters
47 47
48 named_scope :visible, lambda {|*args| { :include => {:board => :project}, 48 named_scope :visible, lambda {|*args| { :include => {:board => :project},
49 :conditions => Project.allowed_to_condition(args.shift || User.current, :view_messages, *args) } } 49 :conditions => Project.allowed_to_condition(args.shift || User.current, :view_messages, *args) } }
50
51 safe_attributes 'subject', 'content'
52 safe_attributes 'locked', 'sticky', 'board_id',
53 :if => lambda {|message, user|
54 user.allowed_to?(:edit_messages, message.project)
55 }
50 56
51 def visible?(user=User.current) 57 def visible?(user=User.current)
52 !user.nil? && user.allowed_to?(:view_messages, project) 58 !user.nil? && user.allowed_to?(:view_messages, project)
53 end 59 end
54 60