diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-11-24 12:25:07 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-11-24 12:25:07 +0000 |
commit | 29b3614bcb759214bb1aba77c27ac11c8ef6b15b (patch) | |
tree | 1783bd1f65552a4e2cea332bda9f42b1831d4e78 /app/models | |
parent | 866e9e2503713c67fd33b389d4e840c04ce1562d (diff) | |
download | redmine-29b3614bcb759214bb1aba77c27ac11c8ef6b15b.tar.gz redmine-29b3614bcb759214bb1aba77c27ac11c8ef6b15b.zip |
Forums enhancements:
* messages can now be edited/deleted (explicit permissions need to be given)
* topics can be locked so that no reply can be added (only by users allowed to edit messages)
* topics can be marked as sticky so that they always appear at the top of the list (only by users allowed to edit messages)
git-svn-id: http://redmine.rubyforge.org/svn/trunk@926 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/message.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/app/models/message.rb b/app/models/message.rb index 909c06a9e..038665cce 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -30,9 +30,15 @@ class Message < ActiveRecord::Base :description => :content, :url => Proc.new {|o| {:controller => 'messages', :action => 'show', :board_id => o.board_id, :id => o.id}} + attr_protected :locked, :sticky validates_presence_of :subject, :content validates_length_of :subject, :maximum => 255 + def validate_on_create + # Can not reply to a locked topic + errors.add_to_base 'Topic is locked' if root.locked? + end + def after_create board.update_attribute(:last_message_id, self.id) board.increment! :messages_count @@ -43,6 +49,18 @@ class Message < ActiveRecord::Base end end + def after_destroy + # The following line is required so that the previous counter + # updates (due to children removal) are not overwritten + board.reload + board.decrement! :messages_count + board.decrement! :topics_count unless parent + end + + def sticky? + sticky == 1 + end + def project board.project end |