From eb9388d59f118e1a5b54086b9a9ea5f355036831 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 28 Jan 2020 13:54:00 +0000 Subject: [PATCH 1/2] dossier: ensure the routing dropdown must be selected MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A blank routing dropdown nullify the groupe_instructeur – which also removes the link between the dossier and the procedure. Fix #4717 --- app/views/shared/dossiers/_edit.html.haml | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/views/shared/dossiers/_edit.html.haml b/app/views/shared/dossiers/_edit.html.haml index b0b353520..6523e05cc 100644 --- a/app/views/shared/dossiers/_edit.html.haml +++ b/app/views/shared/dossiers/_edit.html.haml @@ -30,11 +30,22 @@ %hr - if dossier.procedure.routee? - = f.label :groupe_instructeur_id, dossier.procedure.routing_criteria_name + = f.label :groupe_instructeur_id do + = dossier.procedure.routing_criteria_name + %span.mandatory * + -# The routing dropdown has 'include_blank: false', because otherwise a blank + -# value may nullify the groupe_instructeur – and thus the link between the dossier + -# and its procedure. + -# + -# If, one day, we need to make clearer to the user that they must actually choose an + -# option, THINK TWICE before adding a blank option, and what would happen if the form is + -# saved when the blank option is selected. + -# Instead please consider other possibilities; like using CSS to gray out the default option, + -# or adding some "(please select an option)" wording aside the label of the default group. + -# CSS = f.select :groupe_instructeur_id, dossier.procedure.groupe_instructeurs.order(:label).map { |gi| [gi.label, gi.id] }, - {}, - required: true + { include_blank: false } = f.fields_for :champs, dossier.champs do |champ_form| - champ = champ_form.object From 9da4fa9f4dd96235f5c3c51c4b915c48911e4af3 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 28 Jan 2020 14:58:24 +0100 Subject: [PATCH 2/2] dossier: ensure the dossier groupe_instructeur is always present Otherwise we loose the link to the dossier's procedure, which is definitely a bad thing. --- app/models/dossier.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index a7c237bbc..bc03925bc 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -216,6 +216,7 @@ class Dossier < ApplicationRecord validates :user, presence: true validates :individual, presence: true, if: -> { procedure.for_individual? } + validates :groupe_instructeur, presence: true def update_search_terms self.search_terms = [