@@ -1,16 +1,16 | |||||
1 |
# |
|
1 | # Redmine - project management software | |
2 |
# Copyright (C) 2006-20 |
|
2 | # Copyright (C) 2006-2011 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. | |
8 |
# |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 |
# |
|
13 | # | |
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. | |
@@ -21,7 +21,7 class Message < ActiveRecord::Base | |||||
21 | acts_as_tree :counter_cache => :replies_count, :order => "#{Message.table_name}.created_on ASC" |
|
21 | acts_as_tree :counter_cache => :replies_count, :order => "#{Message.table_name}.created_on ASC" | |
22 | acts_as_attachable |
|
22 | acts_as_attachable | |
23 | belongs_to :last_reply, :class_name => 'Message', :foreign_key => 'last_reply_id' |
|
23 | belongs_to :last_reply, :class_name => 'Message', :foreign_key => 'last_reply_id' | |
24 |
|
24 | |||
25 | acts_as_searchable :columns => ['subject', 'content'], |
|
25 | acts_as_searchable :columns => ['subject', 'content'], | |
26 | :include => {:board => :project}, |
|
26 | :include => {:board => :project}, | |
27 | :project_key => "#{Board.table_name}.project_id", |
|
27 | :project_key => "#{Board.table_name}.project_id", | |
@@ -35,32 +35,32 class Message < ActiveRecord::Base | |||||
35 | acts_as_activity_provider :find_options => {:include => [{:board => :project}, :author]}, |
|
35 | acts_as_activity_provider :find_options => {:include => [{:board => :project}, :author]}, | |
36 | :author_key => :author_id |
|
36 | :author_key => :author_id | |
37 | acts_as_watchable |
|
37 | acts_as_watchable | |
38 |
|
38 | |||
39 | attr_protected :locked, :sticky |
|
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 |
|
42 | |||
43 | after_create :add_author_as_watcher |
|
43 | after_create :add_author_as_watcher | |
44 |
|
44 | |||
45 | named_scope :visible, lambda {|*args| { :include => {:board => :project}, |
|
45 | named_scope :visible, lambda {|*args| { :include => {:board => :project}, | |
46 | :conditions => Project.allowed_to_condition(args.shift || User.current, :view_messages, *args) } } |
|
46 | :conditions => Project.allowed_to_condition(args.shift || User.current, :view_messages, *args) } } | |
47 |
|
47 | |||
48 | def visible?(user=User.current) |
|
48 | def visible?(user=User.current) | |
49 | !user.nil? && user.allowed_to?(:view_messages, project) |
|
49 | !user.nil? && user.allowed_to?(:view_messages, project) | |
50 | end |
|
50 | end | |
51 |
|
51 | |||
52 | def validate_on_create |
|
52 | def validate_on_create | |
53 | # Can not reply to a locked topic |
|
53 | # Can not reply to a locked topic | |
54 | errors.add_to_base 'Topic is locked' if root.locked? && self != root |
|
54 | errors.add_to_base 'Topic is locked' if root.locked? && self != root | |
55 | end |
|
55 | end | |
56 |
|
56 | |||
57 | def after_create |
|
57 | def after_create | |
58 | if parent |
|
58 | if parent | |
59 | parent.reload.update_attribute(:last_reply_id, self.id) |
|
59 | parent.reload.update_attribute(:last_reply_id, self.id) | |
60 | end |
|
60 | end | |
61 | board.reset_counters! |
|
61 | board.reset_counters! | |
62 | end |
|
62 | end | |
63 |
|
63 | |||
64 | def after_update |
|
64 | def after_update | |
65 | if board_id_changed? |
|
65 | if board_id_changed? | |
66 | Message.update_all("board_id = #{board_id}", ["id = ? OR parent_id = ?", root.id, root.id]) |
|
66 | Message.update_all("board_id = #{board_id}", ["id = ? OR parent_id = ?", root.id, root.id]) | |
@@ -68,19 +68,19 class Message < ActiveRecord::Base | |||||
68 | Board.reset_counters!(board_id) |
|
68 | Board.reset_counters!(board_id) | |
69 | end |
|
69 | end | |
70 | end |
|
70 | end | |
71 |
|
71 | |||
72 | def after_destroy |
|
72 | def after_destroy | |
73 | board.reset_counters! |
|
73 | board.reset_counters! | |
74 | end |
|
74 | end | |
75 |
|
75 | |||
76 | def sticky=(arg) |
|
76 | def sticky=(arg) | |
77 | write_attribute :sticky, (arg == true || arg.to_s == '1' ? 1 : 0) |
|
77 | write_attribute :sticky, (arg == true || arg.to_s == '1' ? 1 : 0) | |
78 | end |
|
78 | end | |
79 |
|
79 | |||
80 | def sticky? |
|
80 | def sticky? | |
81 | sticky == 1 |
|
81 | sticky == 1 | |
82 | end |
|
82 | end | |
83 |
|
83 | |||
84 | def project |
|
84 | def project | |
85 | board.project |
|
85 | board.project | |
86 | end |
|
86 | end | |
@@ -92,9 +92,9 class Message < ActiveRecord::Base | |||||
92 | def destroyable_by?(usr) |
|
92 | def destroyable_by?(usr) | |
93 | usr && usr.logged? && (usr.allowed_to?(:delete_messages, project) || (self.author == usr && usr.allowed_to?(:delete_own_messages, project))) |
|
93 | usr && usr.logged? && (usr.allowed_to?(:delete_messages, project) || (self.author == usr && usr.allowed_to?(:delete_own_messages, project))) | |
94 | end |
|
94 | end | |
95 |
|
95 | |||
96 | private |
|
96 | private | |
97 |
|
97 | |||
98 | def add_author_as_watcher |
|
98 | def add_author_as_watcher | |
99 | Watcher.create(:watchable => self.root, :user => author) |
|
99 | Watcher.create(:watchable => self.root, :user => author) | |
100 | end |
|
100 | end |
General Comments 0
You need to be logged in to leave comments.
Login now