Mercurial > hg > soundsoftware-site
comparison app/models/message.rb @ 1295:622f24f53b42 redmine-2.3
Update to Redmine SVN revision 11972 on 2.3-stable branch
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:02:21 +0100 |
parents | 433d4f72a19b |
children |
comparison
equal
deleted
inserted
replaced
1294:3e4c3460b6ca | 1295:622f24f53b42 |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2012 Jean-Philippe Lang | 2 # Copyright (C) 2006-2013 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. |
27 :include => {:board => :project}, | 27 :include => {:board => :project}, |
28 :project_key => "#{Board.table_name}.project_id", | 28 :project_key => "#{Board.table_name}.project_id", |
29 :date_column => "#{table_name}.created_on" | 29 :date_column => "#{table_name}.created_on" |
30 acts_as_event :title => Proc.new {|o| "#{o.board.name}: #{o.subject}"}, | 30 acts_as_event :title => Proc.new {|o| "#{o.board.name}: #{o.subject}"}, |
31 :description => :content, | 31 :description => :content, |
32 :group => :parent, | |
32 :type => Proc.new {|o| o.parent_id.nil? ? 'message' : 'reply'}, | 33 :type => Proc.new {|o| o.parent_id.nil? ? 'message' : 'reply'}, |
33 :url => Proc.new {|o| {:controller => 'messages', :action => 'show', :board_id => o.board_id}.merge(o.parent_id.nil? ? {:id => o.id} : | 34 :url => Proc.new {|o| {:controller => 'messages', :action => 'show', :board_id => o.board_id}.merge(o.parent_id.nil? ? {:id => o.id} : |
34 {:id => o.parent_id, :r => o.id, :anchor => "message-#{o.id}"})} | 35 {:id => o.parent_id, :r => o.id, :anchor => "message-#{o.id}"})} |
35 | 36 |
36 acts_as_activity_provider :find_options => {:include => [{:board => :project}, :author]}, | 37 acts_as_activity_provider :find_options => {:include => [{:board => :project}, :author]}, |
43 | 44 |
44 after_create :add_author_as_watcher, :reset_counters! | 45 after_create :add_author_as_watcher, :reset_counters! |
45 after_update :update_messages_board | 46 after_update :update_messages_board |
46 after_destroy :reset_counters! | 47 after_destroy :reset_counters! |
47 | 48 |
48 scope :visible, lambda {|*args| { :include => {:board => :project}, | 49 scope :visible, lambda {|*args| |
49 :conditions => Project.allowed_to_condition(args.shift || User.current, :view_messages, *args) } } | 50 includes(:board => :project).where(Project.allowed_to_condition(args.shift || User.current, :view_messages, *args)) |
51 } | |
50 | 52 |
51 safe_attributes 'subject', 'content' | 53 safe_attributes 'subject', 'content' |
52 safe_attributes 'locked', 'sticky', 'board_id', | 54 safe_attributes 'locked', 'sticky', 'board_id', |
53 :if => lambda {|message, user| | 55 :if => lambda {|message, user| |
54 user.allowed_to?(:edit_messages, message.project) | 56 user.allowed_to?(:edit_messages, message.project) |
63 errors.add :base, 'Topic is locked' if root.locked? && self != root | 65 errors.add :base, 'Topic is locked' if root.locked? && self != root |
64 end | 66 end |
65 | 67 |
66 def update_messages_board | 68 def update_messages_board |
67 if board_id_changed? | 69 if board_id_changed? |
68 Message.update_all("board_id = #{board_id}", ["id = ? OR parent_id = ?", root.id, root.id]) | 70 Message.update_all({:board_id => board_id}, ["id = ? OR parent_id = ?", root.id, root.id]) |
69 Board.reset_counters!(board_id_was) | 71 Board.reset_counters!(board_id_was) |
70 Board.reset_counters!(board_id) | 72 Board.reset_counters!(board_id) |
71 end | 73 end |
72 end | 74 end |
73 | 75 |