2018-03-06 13:44:29 +01:00
|
|
|
class Individual < ApplicationRecord
|
2023-11-22 18:16:41 +01:00
|
|
|
enum notification_method: {
|
|
|
|
email: 'email',
|
|
|
|
no_notification: 'no_notification'
|
|
|
|
}
|
|
|
|
|
2020-07-20 16:53:25 +02:00
|
|
|
belongs_to :dossier, optional: false
|
2016-08-30 11:18:43 +02:00
|
|
|
|
2018-03-06 13:44:29 +01:00
|
|
|
validates :dossier_id, uniqueness: true
|
2018-02-08 17:13:15 +01:00
|
|
|
validates :gender, presence: true, allow_nil: false, on: :update
|
|
|
|
validates :nom, presence: true, allow_blank: false, allow_nil: false, on: :update
|
|
|
|
validates :prenom, presence: true, allow_blank: false, allow_nil: false, on: :update
|
2023-11-22 18:16:41 +01:00
|
|
|
validates :notification_method, presence: true,
|
|
|
|
inclusion: { in: notification_methods.keys },
|
|
|
|
if: -> { dossier.for_tiers? },
|
|
|
|
on: :update
|
|
|
|
|
|
|
|
validates :email, presence: true, if: -> { dossier.for_tiers? && self.email? }, on: :update
|
2019-08-01 09:34:26 +02:00
|
|
|
|
2024-04-25 17:57:55 +02:00
|
|
|
after_commit -> { dossier.index_search_terms_later }, if: -> { nom_previously_changed? || prenom_previously_changed? }
|
2024-04-25 17:44:28 +02:00
|
|
|
|
2020-12-08 21:30:54 +01:00
|
|
|
GENDER_MALE = "M."
|
|
|
|
GENDER_FEMALE = 'Mme'
|
2019-08-01 09:34:26 +02:00
|
|
|
|
2020-01-07 16:36:04 +01:00
|
|
|
def self.from_france_connect(fc_information)
|
|
|
|
new(
|
2019-08-01 09:34:26 +02:00
|
|
|
nom: fc_information.family_name,
|
|
|
|
prenom: fc_information.given_name,
|
|
|
|
gender: fc_information.gender == 'female' ? GENDER_FEMALE : GENDER_MALE
|
|
|
|
)
|
|
|
|
end
|
2016-08-30 11:18:43 +02:00
|
|
|
end
|