2023-10-24 17:45:20 +02:00
|
|
|
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" }
|
|
|
|
|
2023-10-26 10:51:37 +02:00
|
|
|
before_create :set_emails
|
|
|
|
|
2023-10-24 17:45:20 +02:00
|
|
|
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
|
2023-10-26 10:51:37 +02:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_emails
|
|
|
|
self.sender_email = sender.email
|
|
|
|
self.gestionnaire_email = gestionnaire&.email
|
|
|
|
end
|
2023-10-24 17:45:20 +02:00
|
|
|
end
|