From 2689bc6721e946d9d122cbbd38daf74dd9339a9a Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Mon, 29 Jul 2024 14:48:19 +0200 Subject: [PATCH 1/2] fix(attestation): build v2 draft on draft procedure when a v1 is published --- .../attestation_template_v2s_controller.rb | 8 +++++++- .../attestation_template_v2s_controller_spec.rb | 11 +++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/controllers/administrateurs/attestation_template_v2s_controller.rb b/app/controllers/administrateurs/attestation_template_v2s_controller.rb index 4585f1c39..64ea3348c 100644 --- a/app/controllers/administrateurs/attestation_template_v2s_controller.rb +++ b/app/controllers/administrateurs/attestation_template_v2s_controller.rb @@ -133,7 +133,13 @@ module Administrateurs @procedure.attestation_templates.build(version: 2, json_body: AttestationTemplate::TIPTAP_BODY_DEFAULT, activated: true, state:) end - def should_edit_draft? = !@procedure.brouillon? + def should_edit_draft? + if @procedure.brouillon? + @procedure.attestation_templates.v1.published.any? + else + true + end + end def editor_params params.required(:attestation_template).permit(:activated, :official_layout, :label_logo, :label_direction, :tiptap_body, :footer, :logo, :signature, :activated, :state) diff --git a/spec/controllers/administrateurs/attestation_template_v2s_controller_spec.rb b/spec/controllers/administrateurs/attestation_template_v2s_controller_spec.rb index e82085bc9..e7056cd67 100644 --- a/spec/controllers/administrateurs/attestation_template_v2s_controller_spec.rb +++ b/spec/controllers/administrateurs/attestation_template_v2s_controller_spec.rb @@ -142,6 +142,17 @@ describe Administrateurs::AttestationTemplateV2sController, type: :controller do expect(assigns(:attestation_template)).to be_draft expect(attestation_template.reload).to be_present end + + context 'on a draft procedure' do + let(:procedure) { create(:procedure, :draft, administrateur: admin, attestation_template:, libelle: "Ma démarche") } + + it 'build v2 as draft' do + subject + expect(assigns(:attestation_template).version).to eq(2) + expect(assigns(:attestation_template)).to be_draft + expect(attestation_template.reload).to be_present + end + end end context 'attestation template published exist without draft' do From 8d70f68146d4e2ffd3ba6caaf2a86b6d66859873 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Mon, 29 Jul 2024 14:48:35 +0200 Subject: [PATCH 2/2] fix(attestation): link to published v1 from v2 --- .../administrateurs/attestation_template_v2s/edit.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/administrateurs/attestation_template_v2s/edit.html.haml b/app/views/administrateurs/attestation_template_v2s/edit.html.haml index 7c995e6b2..22b0a0fbe 100644 --- a/app/views/administrateurs/attestation_template_v2s/edit.html.haml +++ b/app/views/administrateurs/attestation_template_v2s/edit.html.haml @@ -20,7 +20,7 @@ tout en respectant la charte de l’état. Essayez-la et donnez-nous votre avis en nous envoyant un email à #{mail_to(Current.contact_email, subject: "Feedback attestation v2")}. %br - - if !@procedure.feature_enabled?(:attestation_v2) + - if !@procedure.feature_enabled?(:attestation_v2) || @procedure.attestation_templates.v1.published.any? %strong Les attestations délivrées suivent encore l’ancien format : l’activation des attestations basées sur ce format sera bientôt disponible. %br