2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
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
|
|
|
|
|
2023-12-10 18:25:58 +01:00
|
|
|
def sent_by_system?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2023-10-24 17:45:20 +02:00
|
|
|
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
|