Merge pull request #4407 from betagouv/usager_use_groupe_instruction
Rajoute la liste déroulante qui permet à l'usager d'utiliser le routage
This commit is contained in:
commit
ee6f0db5fb
9 changed files with 44 additions and 10 deletions
|
@ -282,13 +282,14 @@ module Users
|
|||
end
|
||||
|
||||
# FIXME: require(:dossier) when all the champs are united
|
||||
def champs_params
|
||||
params.permit(dossier: {
|
||||
def champs_and_groupe_instructeurs_params
|
||||
params.permit(dossier: [
|
||||
:groupe_instructeur_id,
|
||||
champs_attributes: [
|
||||
:id, :value, :primary_value, :secondary_value, :piece_justificative_file, value: [],
|
||||
champs_attributes: [:id, :_destroy, :value, :primary_value, :secondary_value, :piece_justificative_file, value: []]
|
||||
]
|
||||
})
|
||||
])
|
||||
end
|
||||
|
||||
def dossier
|
||||
|
@ -302,7 +303,7 @@ module Users
|
|||
def update_dossier_and_compute_errors
|
||||
errors = []
|
||||
|
||||
if champs_params[:dossier] && !@dossier.update(champs_params[:dossier])
|
||||
if champs_and_groupe_instructeurs_params[:dossier] && !@dossier.update(champs_and_groupe_instructeurs_params[:dossier])
|
||||
errors += @dossier.errors.full_messages
|
||||
end
|
||||
|
||||
|
|
|
@ -197,7 +197,7 @@ class Dossier < ApplicationRecord
|
|||
|
||||
before_validation :update_state_dates, if: -> { state_changed? }
|
||||
|
||||
before_save :build_default_champs, if: Proc.new { groupe_instructeur_id_changed? }
|
||||
before_save :build_default_champs, if: Proc.new { groupe_instructeur_id_was.nil? }
|
||||
before_save :build_default_individual, if: Proc.new { procedure.for_individual? }
|
||||
before_save :update_search_terms
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ class Procedure < ApplicationRecord
|
|||
has_one :refused_mail, class_name: "Mails::RefusedMail", dependent: :destroy
|
||||
has_one :without_continuation_mail, class_name: "Mails::WithoutContinuationMail", dependent: :destroy
|
||||
|
||||
has_one :defaut_groupe_instructeur, -> { where(label: GroupeInstructeur::DEFAULT_LABEL) }, class_name: 'GroupeInstructeur', inverse_of: :procedure
|
||||
has_one :defaut_groupe_instructeur, -> { order(:id) }, class_name: 'GroupeInstructeur', inverse_of: :procedure
|
||||
|
||||
has_one_attached :logo
|
||||
has_one_attached :notice
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
%h2 Formulaire
|
||||
|
||||
- champs = @dossier.champs
|
||||
- if champs.any?
|
||||
- if champs.any? || @dossier.procedure.routee?
|
||||
= render partial: "shared/dossiers/champs", locals: { champs: champs, dossier: @dossier, demande_seen_at: nil, profile: 'instructeur' }
|
||||
|
||||
%h2 Annotations privées
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
%table.table.vertical.dossier-champs
|
||||
%tbody
|
||||
- if dossier.procedure.routee?
|
||||
%th= dossier.procedure.routing_criteria_name
|
||||
%td= dossier.groupe_instructeur.label
|
||||
%td
|
||||
= render partial: "shared/dossiers/champ_row", locals: { champs: champs, demande_seen_at: demande_seen_at, profile: profile, repetition: false }
|
||||
|
|
|
@ -23,6 +23,6 @@
|
|||
|
||||
.tab-title Formulaire
|
||||
- champs = dossier.champs.includes(:type_de_champ)
|
||||
- if champs.any?
|
||||
- if champs.any? || dossier.procedure.routee?
|
||||
.card
|
||||
= render partial: "shared/dossiers/champs", locals: { champs: champs, demande_seen_at: demande_seen_at, profile: profile }
|
||||
= render partial: "shared/dossiers/champs", locals: { champs: champs, dossier: dossier, demande_seen_at: demande_seen_at, profile: profile }
|
||||
|
|
|
@ -26,6 +26,13 @@
|
|||
|
||||
%hr
|
||||
|
||||
- if dossier.procedure.routee?
|
||||
= f.label :groupe_instructeur_id, dossier.procedure.routing_criteria_name
|
||||
= f.select :groupe_instructeur_id,
|
||||
dossier.procedure.groupe_instructeurs.order(:label).map { |gi| [gi.label, gi.id] },
|
||||
{},
|
||||
required: true
|
||||
|
||||
= f.fields_for :champs, dossier.champs do |champ_form|
|
||||
- champ = champ_form.object
|
||||
= render partial: "shared/dossiers/editable_champs/editable_champ",
|
||||
|
|
|
@ -74,6 +74,12 @@ FactoryBot.define do
|
|||
end
|
||||
end
|
||||
|
||||
trait :routee do
|
||||
after(:create) do |procedure, _evaluator|
|
||||
procedure.groupe_instructeurs.create(label: '2nd groupe')
|
||||
end
|
||||
end
|
||||
|
||||
trait :for_individual do
|
||||
after(:build) do |procedure, _evaluator|
|
||||
procedure.for_individual = true
|
||||
|
|
|
@ -8,7 +8,7 @@ describe 'shared/dossiers/champs.html.haml', type: :view do
|
|||
allow(view).to receive(:current_instructeur).and_return(instructeur)
|
||||
end
|
||||
|
||||
subject { render 'shared/dossiers/champs.html.haml', champs: champs, demande_seen_at: demande_seen_at, profile: nil }
|
||||
subject { render 'shared/dossiers/champs.html.haml', champs: champs, dossier: dossier, demande_seen_at: demande_seen_at, profile: nil }
|
||||
|
||||
context "there are some champs" do
|
||||
let(:dossier) { create(:dossier) }
|
||||
|
@ -54,6 +54,21 @@ describe 'shared/dossiers/champs.html.haml', type: :view do
|
|||
end
|
||||
end
|
||||
|
||||
context "with a routed procedure" do
|
||||
let(:procedure) do
|
||||
create(:procedure,
|
||||
:routee,
|
||||
routing_criteria_name: 'departement')
|
||||
end
|
||||
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||
let(:champs) { [] }
|
||||
|
||||
it "renders the routing criteria name and its value" do
|
||||
expect(subject).to include(procedure.routing_criteria_name)
|
||||
expect(subject).to include(dossier.groupe_instructeur.label)
|
||||
end
|
||||
end
|
||||
|
||||
context "with a dossier champ, but we are not authorized to acces the dossier" do
|
||||
let(:dossier) { create(:dossier) }
|
||||
let(:champ) { create(:champ, :dossier_link, value: dossier.id) }
|
||||
|
@ -65,6 +80,7 @@ describe 'shared/dossiers/champs.html.haml', type: :view do
|
|||
end
|
||||
|
||||
context "with a dossier_link champ but without value" do
|
||||
let(:dossier) { create(:dossier) }
|
||||
let(:champ) { create(:champ, :dossier_link, value: nil) }
|
||||
let(:champs) { [champ] }
|
||||
|
||||
|
|
Loading…
Reference in a new issue