dossiers: make build_default_individual
explicit
It avoid the use of callbacks, and may avoid situations where an empty individual is implicitely created.
This commit is contained in:
parent
5e05556ee8
commit
b3558c497d
3 changed files with 12 additions and 8 deletions
|
@ -231,11 +231,13 @@ module Users
|
||||||
return redirect_to url_for dossiers_path
|
return redirect_to url_for dossiers_path
|
||||||
end
|
end
|
||||||
|
|
||||||
dossier = Dossier.create!(
|
dossier = Dossier.new(
|
||||||
groupe_instructeur: procedure.defaut_groupe_instructeur,
|
groupe_instructeur: procedure.defaut_groupe_instructeur,
|
||||||
user: current_user,
|
user: current_user,
|
||||||
state: Dossier.states.fetch(:brouillon)
|
state: Dossier.states.fetch(:brouillon)
|
||||||
)
|
)
|
||||||
|
dossier.build_default_individual
|
||||||
|
dossier.save!
|
||||||
|
|
||||||
if dossier.procedure.for_individual
|
if dossier.procedure.for_individual
|
||||||
redirect_to identite_dossier_path(dossier)
|
redirect_to identite_dossier_path(dossier)
|
||||||
|
|
|
@ -207,9 +207,6 @@ class Dossier < ApplicationRecord
|
||||||
delegate :france_connect_information, to: :user
|
delegate :france_connect_information, to: :user
|
||||||
|
|
||||||
before_validation :update_state_dates, if: -> { state_changed? }
|
before_validation :update_state_dates, if: -> { state_changed? }
|
||||||
before_validation :build_default_individual,
|
|
||||||
if: -> { new_record? && procedure.for_individual? && individual.blank? }
|
|
||||||
|
|
||||||
before_save :build_default_champs, if: Proc.new { groupe_instructeur_id_was.nil? }
|
before_save :build_default_champs, if: Proc.new { groupe_instructeur_id_was.nil? }
|
||||||
before_save :update_search_terms
|
before_save :update_search_terms
|
||||||
|
|
||||||
|
@ -241,10 +238,12 @@ class Dossier < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_default_individual
|
def build_default_individual
|
||||||
self.individual = if france_connect_information.present?
|
if procedure.for_individual? && individual.blank?
|
||||||
Individual.from_france_connect(france_connect_information)
|
self.individual = if france_connect_information.present?
|
||||||
else
|
Individual.from_france_connect(france_connect_information)
|
||||||
Individual.new
|
else
|
||||||
|
Individual.new
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -15,9 +15,12 @@ FactoryBot.define do
|
||||||
procedure = create(:procedure, :published, :with_type_de_champ, :with_type_de_champ_private)
|
procedure = create(:procedure, :published, :with_type_de_champ, :with_type_de_champ_private)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Assign the procedure to the dossier through the groupe_instructeur
|
||||||
if dossier.groupe_instructeur.nil?
|
if dossier.groupe_instructeur.nil?
|
||||||
dossier.groupe_instructeur = procedure.defaut_groupe_instructeur
|
dossier.groupe_instructeur = procedure.defaut_groupe_instructeur
|
||||||
end
|
end
|
||||||
|
|
||||||
|
dossier.build_default_individual
|
||||||
end
|
end
|
||||||
|
|
||||||
trait :with_entreprise do
|
trait :with_entreprise do
|
||||||
|
|
Loading…
Add table
Reference in a new issue