Class: Message

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

Overview

Redmine - project management software Copyright © 2006-2022 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

Methods included from Redmine::SafeAttributes

#delete_unsafe_attributes, included, #safe_attribute?, #safe_attribute_names, #safe_attributes=

Instance Method Details

#cannot_reply_to_locked_topicObject



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

def cannot_reply_to_locked_topic
  # Can not reply to a locked topic
  errors.add :base, 'Topic is locked' if root.locked? && self != root
end

#destroyable_by?(usr) ⇒ Boolean

Returns:

  • (Boolean)


116
117
118
# File 'app/models/message.rb', line 116

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

Returns:

  • (Boolean)


112
113
114
# File 'app/models/message.rb', line 112

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

#notified_usersObject



120
121
122
# File 'app/models/message.rb', line 120

def notified_users
  project.notified_users.reject {|user| !visible?(user)}
end

#projectObject



108
109
110
# File 'app/models/message.rb', line 108

def project
  board.project
end

#reset_counters!Object



93
94
95
96
97
98
# File 'app/models/message.rb', line 93

def reset_counters!
  if parent && parent.id
    Message.where({:id => parent.id}).update_all({:last_reply_id => parent.children.maximum(:id)})
  end
  board.reset_counters!
end

#sticky=(arg) ⇒ Object



100
101
102
# File 'app/models/message.rb', line 100

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

#sticky?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'app/models/message.rb', line 104

def sticky?
  sticky == 1
end

#update_messages_boardObject



85
86
87
88
89
90
91
# File 'app/models/message.rb', line 85

def update_messages_board
  if saved_change_to_board_id?
    Message.where(["id = ? OR parent_id = ?", root.id, root.id]).update_all({:board_id => board_id})
    Board.reset_counters!(board_id_before_last_save)
    Board.reset_counters!(board_id)
  end
end

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

Returns:

  • (Boolean)


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

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