29 lines
605 B
Ruby
29 lines
605 B
Ruby
|
class CommentaireGroupeGestionnaire < ApplicationRecord
|
||
|
include Discard::Model
|
||
|
belongs_to :groupe_gestionnaire
|
||
|
belongs_to :gestionnaire, optional: true
|
||
|
belongs_to :sender, polymorphic: true
|
||
|
|
||
|
validates :body, presence: { message: "ne peut être vide" }
|
||
|
|
||
|
def soft_deletable?(connected_user)
|
||
|
sent_by?(connected_user) && sent_by_gestionnaire? && !discarded?
|
||
|
end
|
||
|
|
||
|
def soft_delete!
|
||
|
discard!
|
||
|
end
|
||
|
|
||
|
def sent_by_gestionnaire?
|
||
|
gestionnaire_id.present?
|
||
|
end
|
||
|
|
||
|
def sent_by?(someone)
|
||
|
if gestionnaire
|
||
|
someone == gestionnaire
|
||
|
else
|
||
|
someone == sender
|
||
|
end
|
||
|
end
|
||
|
end
|