Ajoute la validation sur le modèle Individual

This commit is contained in:
Kara Diaby 2024-08-05 12:06:37 +00:00
parent 61525b6c2b
commit 88cd4a94dd
No known key found for this signature in database
GPG key ID: C4D1B0CF9F24D759

View file

@ -16,6 +16,7 @@ class Individual < ApplicationRecord
on: :update
validates :email, strict_email: true, presence: true, if: -> { dossier.for_tiers? && self.email? }, on: :update
validate :email_different_from_mandataire, on: :update
after_commit -> { dossier.index_search_terms_later }, if: -> { nom_previously_changed? || prenom_previously_changed? }
@ -31,4 +32,10 @@ class Individual < ApplicationRecord
end
def unverified_email? = !email_verified_at?
def email_different_from_mandataire
if email.present? && email.casecmp?(dossier.user.email)
errors.add(:email, :must_be_different_from_mandataire)
end
end
end