Class: Message

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/message.rb

Overview

redMine - project management software Copyright (C) 2006-2007 Jean-Philippe Lang

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Instance Method Summary collapse

Instance Method Details

#after_createObject



57
58
59
60
61
62
# File 'app/models/message.rb', line 57

def after_create
  if parent
    parent.reload.update_attribute(:last_reply_id, self.id)
  end
  board.reset_counters!
end

#after_destroyObject



72
73
74
# File 'app/models/message.rb', line 72

def after_destroy
  board.reset_counters!
end

#after_updateObject



64
65
66
67
68
69
70
# File 'app/models/message.rb', line 64

def after_update
  if board_id_changed?
    Message.update_all("board_id = #{board_id}", ["id = ? OR parent_id = ?", root.id, root.id])
    Board.reset_counters!(board_id_was)
    Board.reset_counters!(board_id)
  end
end

#destroyable_by?(usr) ⇒ Boolean



92
93
94
# File 'app/models/message.rb', line 92

def destroyable_by?(usr)
  usr && usr.logged? && (usr.allowed_to?(:delete_messages, project) || (self.author == usr && usr.allowed_to?(:delete_own_messages, project)))
end

#editable_by?(usr) ⇒ Boolean



88
89
90
# File 'app/models/message.rb', line 88

def editable_by?(usr)
  usr && usr.logged? && (usr.allowed_to?(:edit_messages, project) || (self.author == usr && usr.allowed_to?(:edit_own_messages, project)))
end

#projectObject



84
85
86
# File 'app/models/message.rb', line 84

def project
  board.project
end

#sticky=(arg) ⇒ Object



76
77
78
# File 'app/models/message.rb', line 76

def sticky=(arg)
  write_attribute :sticky, (arg == true || arg.to_s == '1' ? 1 : 0)
end

#sticky?Boolean



80
81
82
# File 'app/models/message.rb', line 80

def sticky?
  sticky == 1
end

#validate_on_createObject



52
53
54
55
# File 'app/models/message.rb', line 52

def validate_on_create
  # Can not reply to a locked topic
  errors.add_to_base 'Topic is locked' if root.locked? && self != root
end

#visible?(user = User.current) ⇒ Boolean



48
49
50
# File 'app/models/message.rb', line 48

def visible?(user=User.current)
  !user.nil? && user.allowed_to?(:view_messages, project)
end