Class: Message

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

Overview

Redmine - project management software Copyright (C) 2006-2016 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.

Since:

  • 0.5.1

Instance Method Summary collapse

Methods included from Redmine::SafeAttributes

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

Instance Method Details

#cannot_reply_to_locked_topicObject

Since:

  • 1.3.0



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

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)


102
103
104
# File 'app/models/message.rb', line 102

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)


98
99
100
# File 'app/models/message.rb', line 98

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

Since:

  • 3.0.0



106
107
108
# File 'app/models/message.rb', line 106

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

#projectObject



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

def project
  board.project
end

#reset_counters!Object

Since:

  • 2.1.0



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

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

Since:

  • 0.9.0



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

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

#sticky?Boolean

Returns:

  • (Boolean)

Since:

  • 0.6.1



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

def sticky?
  sticky == 1
end

#update_messages_boardObject

Since:

  • 1.3.0



71
72
73
74
75
76
77
# File 'app/models/message.rb', line 71

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

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

Returns:

  • (Boolean)

Since:

  • 0.9.0



62
63
64
# File 'app/models/message.rb', line 62

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