blob: e1aae6c9462ec0b251f9625786be1ba3974c5046 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
class ChatMessage < ApplicationRecord
belongs_to :chat_room
belongs_to :sender, class_name: "Character", optional: true
belongs_to :target, class_name: "Character", optional: true
validates :body, length: { minimum: 1, maximum: 255 }
validate :sender_has_access
private
def sender_has_access
if sender && !sender.user.has_permission_or_higher?(self.chat_room.permission_level)
errors.add(:chat, "You don't have permission to send that chat.")
end
end
end
|