From cd07ee173f1fc2b37244dcf36b69528ad36f6dbf Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Fri, 31 May 2024 10:03:23 +0200 Subject: [PATCH] feat(attestation): can reset draft attestation --- .../attestation_template_v2s_controller.rb | 7 +++++++ .../_sticky_header.html.haml | 9 ++++++-- config/routes.rb | 4 +++- ...ttestation_template_v2s_controller_spec.rb | 21 +++++++++++++++++++ .../procedure_attestation_template_spec.rb | 1 - 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/app/controllers/administrateurs/attestation_template_v2s_controller.rb b/app/controllers/administrateurs/attestation_template_v2s_controller.rb index 5ae2e63c1..13905a581 100644 --- a/app/controllers/administrateurs/attestation_template_v2s_controller.rb +++ b/app/controllers/administrateurs/attestation_template_v2s_controller.rb @@ -104,6 +104,13 @@ module Administrateurs def create = update + def reset + @procedure.attestation_templates_v2.draft&.destroy_all + + flash.notice = "Les modifications ont été réinitialisées." + redirect_to edit_admin_procedure_attestation_template_v2_path(@procedure) + end + private def ensure_feature_active diff --git a/app/views/administrateurs/attestation_template_v2s/_sticky_header.html.haml b/app/views/administrateurs/attestation_template_v2s/_sticky_header.html.haml index d5f2312d6..226a35228 100644 --- a/app/views/administrateurs/attestation_template_v2s/_sticky_header.html.haml +++ b/app/views/administrateurs/attestation_template_v2s/_sticky_header.html.haml @@ -3,8 +3,13 @@ %p.flex.justify-between.align-center.fr-text-default--warning %span = dsfr_icon("fr-icon-warning-fill fr-mr-1v") - Les modifications effectuées ne seront appliquées qu’une fois que vous aurez publié cette version de l’attestation. + Les modifications effectuées ne seront appliquées qu’à la prochaine publication. %span + + + = link_to reset_admin_procedure_attestation_template_v2_path(@procedure), class: "fr-btn fr-btn--secondary fr-ml-2w", method: :post do + Réinitialiser les modifications + %button.fr-btn.fr-ml-2w{ form: "attestation-template", name: field_name(:attestation_template, :state), value: "published", data: { 'disable-with': "Publication en cours…", controller: 'autosave-submit' } } - Publier l’attestation + Publier les modifications diff --git a/config/routes.rb b/config/routes.rb index d16b5f778..75a44fd05 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -684,7 +684,9 @@ Rails.application.routes.draw do get 'add_champ_engagement_juridique' end - resource :attestation_template_v2, only: [:show, :edit, :update, :create] + resource :attestation_template_v2, only: [:show, :edit, :update, :create] do + post :reset + end resource :dossier_submitted_message, only: [:edit, :update, :create] # ADDED TO ACCESS IT FROM THE IFRAME diff --git a/spec/controllers/administrateurs/attestation_template_v2s_controller_spec.rb b/spec/controllers/administrateurs/attestation_template_v2s_controller_spec.rb index 6541c0ddd..4e69f2a23 100644 --- a/spec/controllers/administrateurs/attestation_template_v2s_controller_spec.rb +++ b/spec/controllers/administrateurs/attestation_template_v2s_controller_spec.rb @@ -233,4 +233,25 @@ describe Administrateurs::AttestationTemplateV2sController, type: :controller do end end end + + describe 'POST reset' do + render_views + + before { + create(:attestation_template, :v2, :draft, procedure:) + } + + subject do + patch :reset, params: { procedure_id: procedure.id } + response.body + end + + it "delete draft, keep published" do + expect(procedure.attestation_templates.count).to eq(2) + expect(subject).to redirect_to(edit_admin_procedure_attestation_template_v2_path(procedure)) + expect(flash.notice).to include("réinitialisées") + expect(procedure.attestation_templates.count).to eq(1) + expect(procedure.attestation_templates.first).to eq(attestation_template) + end + end end diff --git a/spec/system/administrateurs/procedure_attestation_template_spec.rb b/spec/system/administrateurs/procedure_attestation_template_spec.rb index 2dde1080d..bab1d796f 100644 --- a/spec/system/administrateurs/procedure_attestation_template_spec.rb +++ b/spec/system/administrateurs/procedure_attestation_template_spec.rb @@ -138,7 +138,6 @@ describe 'As an administrateur, I want to manage the procedure’s attestation', expect(page).to have_field("Contenu du pied de page", with: "line1\nline2\nline3\nline4") click_on "Publier" - expect(page).to have_text("L’attestation a été publiée") expect(attestation.reload).to be_published end