diff --git a/app/models/individual.rb b/app/models/individual.rb index fd940639177..664e586ad86 100644 --- a/app/models/individual.rb +++ b/app/models/individual.rb @@ -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 @@ def self.from_france_connect(fc_information) 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