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-2017 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



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

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)


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

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)


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

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



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

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

#projectObject



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

def project
  board.project
end

#reset_counters!Object

Since:

  • 2.1.0



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

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



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

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

#sticky?Boolean

Returns:

  • (Boolean)

Since:

  • 0.6.1



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

def sticky?
  sticky == 1
end

#update_messages_boardObject

Since:

  • 1.3.0



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

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)

Since:

  • 0.9.0



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

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