Class: Message

Inherits:
ActiveRecord::Base 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

Methods inherited from ActiveRecord::Base

quoted_table_name

Instance Method Details

- (Object) after_create



54
55
56
57
58
59
# File 'app/models/message.rb', line 54

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

- (Object) after_destroy



69
70
71
# File 'app/models/message.rb', line 69

def after_destroy
  board.reset_counters!
end

- (Object) after_update



61
62
63
64
65
66
67
# File 'app/models/message.rb', line 61

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

- (Boolean) destroyable_by?(usr)

Returns:

  • (Boolean)


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

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

- (Boolean) editable_by?(usr)

Returns:

  • (Boolean)


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

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

- (Object) project



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

def project
  board.project
end

- (Object) sticky=(arg)



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

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

- (Boolean) sticky?

Returns:

  • (Boolean)


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

def sticky?
  sticky == 1
end

- (Object) validate_on_create



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

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

- (Boolean) visible?(user = User.current)

Returns:

  • (Boolean)


45
46
47
# File 'app/models/message.rb', line 45

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