diff --git a/app/components/dsfr/callout_component.rb b/app/components/dsfr/callout_component.rb index 2d394d939..3e343011b 100644 --- a/app/components/dsfr/callout_component.rb +++ b/app/components/dsfr/callout_component.rb @@ -26,6 +26,8 @@ class Dsfr::CalloutComponent < ApplicationComponent "fr-callout--brown-caramel" when :success "fr-callout--green-emeraude" + when :neutral + # default else "fr-background-alt--blue-france" end diff --git a/app/controllers/administrateurs/attestation_template_v2s_controller.rb b/app/controllers/administrateurs/attestation_template_v2s_controller.rb index 13905a581..6e3447f70 100644 --- a/app/controllers/administrateurs/attestation_template_v2s_controller.rb +++ b/app/controllers/administrateurs/attestation_template_v2s_controller.rb @@ -60,6 +60,12 @@ module Administrateurs def update attestation_params = editor_params + # toggle activation + if @attestation_template.persisted? && @attestation_template.activated? != cast_bool(attestation_params[:activated]) + @procedure.attestation_templates.v2.update_all(activated: attestation_params[:activated]) + render :update && return + end + if @attestation_template.published? @attestation_template = @attestation_template.dup @attestation_template.state = :draft @@ -123,7 +129,7 @@ module Administrateurs end def editor_params - params.required(:attestation_template).permit(:official_layout, :label_logo, :label_direction, :tiptap_body, :footer, :logo, :signature, :activated, :state) + params.required(:attestation_template).permit(:activated, :official_layout, :label_logo, :label_direction, :tiptap_body, :footer, :logo, :signature, :activated, :state) end end end diff --git a/app/views/administrateurs/attestation_template_v2s/_fixed_footer.html.haml b/app/views/administrateurs/attestation_template_v2s/_fixed_footer.html.haml index 67d778563..e66ef2949 100644 --- a/app/views/administrateurs/attestation_template_v2s/_fixed_footer.html.haml +++ b/app/views/administrateurs/attestation_template_v2s/_fixed_footer.html.haml @@ -6,8 +6,4 @@ Revenir à l’écran de gestion .fr-col-12.fr-col-md-8.text-right - - - if attestation_template.published? - %p.fr-hint-text Cette attestation est actuellement délivrée aux usagers. - %span#autosave-notice diff --git a/app/views/administrateurs/attestation_template_v2s/edit.html.haml b/app/views/administrateurs/attestation_template_v2s/edit.html.haml index 0630f4cd4..43eb99c8e 100644 --- a/app/views/administrateurs/attestation_template_v2s/edit.html.haml +++ b/app/views/administrateurs/attestation_template_v2s/edit.html.haml @@ -36,13 +36,23 @@ L’attestation est émise au moment où un dossier est accepté, elle est jointe à l’email d’accusé d’acceptation. Elle est également disponible au téléchargement depuis l’espace personnel de l’usager. + .fr-fieldset__element + = render Dsfr::CalloutComponent.new(title: "Activation de la délivrance de l’attestation", theme: :neutral) do |c| + - c.with_html_body do + .fr-toggle.fr-toggle--label-left + = f.check_box :activated, class: "fr-toggle__input", id: dom_id(@attestation_template, :activated) + %label.fr-toggle__label{ for: dom_id(@attestation_template, :activated), + data: { fr_checked_label: "Activée", fr_unchecked_label: "Désactivée" } } + Activer cette option permet la délivrance automatique de l’attestation dès l’acceptation du dossier. + Désactiver cette option arrête immédiatement l’émission de nouvelles attestations. + .fr-fieldset__element %h2.fr-h4 En-tête .fr-fieldset__element .fr-toggle.fr-toggle--label-left = f.check_box :official_layout, class: "fr-toggle__input", id: dom_id(@attestation_template, :official_layout), data: { "attestation-target": "layoutToggle"} - %label.fr-toggle__label{ for: dom_id(@attestation_template, :official_layout), data: { fr_checked_label: "Activé", fr_unchecked_label: "Désactivé" } } + %label.fr-toggle__label{ for: dom_id(@attestation_template, :official_layout), data: { fr_checked_label: "Oui", fr_unchecked_label: "Non" } } Je souhaite générer une attestation à la charte de l’état (logo avec Marianne) .fr-fieldset__element{ class: class_names("hidden" => !@attestation_template.official_layout?), data: { "attestation-target": 'logoMarianneLabelFieldset'} } @@ -125,4 +135,4 @@ .padded-fixed-footer .fixed-footer#fixed_footer - = render partial: "fixed_footer", locals: { procedure: @procedure, attestation_template: @attestation_template } + = render partial: "fixed_footer", locals: { procedure: @procedure } diff --git a/app/views/administrateurs/attestation_template_v2s/update.turbo_stream.haml b/app/views/administrateurs/attestation_template_v2s/update.turbo_stream.haml index 0bf0da34a..4941218fb 100644 --- a/app/views/administrateurs/attestation_template_v2s/update.turbo_stream.haml +++ b/app/views/administrateurs/attestation_template_v2s/update.turbo_stream.haml @@ -1,5 +1,4 @@ -- if @attestation_template.previously_new_record? || @attestation_template.state_changed? - = turbo_stream.update "fixed_footer", render(partial: "fixed_footer", locals: { procedure: @procedure, attestation_template: @attestation_template }) +- if @attestation_template.draft? = turbo_stream.update "sticky-header", render(partial: "sticky_header") = turbo_stream.show 'autosave-notice' diff --git a/spec/controllers/administrateurs/attestation_template_v2s_controller_spec.rb b/spec/controllers/administrateurs/attestation_template_v2s_controller_spec.rb index 4e69f2a23..4fbb4ccfd 100644 --- a/spec/controllers/administrateurs/attestation_template_v2s_controller_spec.rb +++ b/spec/controllers/administrateurs/attestation_template_v2s_controller_spec.rb @@ -1,7 +1,7 @@ describe Administrateurs::AttestationTemplateV2sController, type: :controller do let(:admin) { create(:administrateur) } let(:attestation_template) { build(:attestation_template, :v2) } - let!(:procedure) { create(:procedure, administrateur: admin, attestation_template: attestation_template, libelle: "Ma démarche") } + let(:procedure) { create(:procedure, administrateur: admin, attestation_template:, libelle: "Ma démarche") } let(:logo) { fixture_file_upload('spec/fixtures/files/white.png', 'image/png') } let(:signature) { fixture_file_upload('spec/fixtures/files/black.png', 'image/png') } @@ -11,7 +11,7 @@ describe Administrateurs::AttestationTemplateV2sController, type: :controller do label_logo: "Ministère des specs", label_direction: "RSPEC", footer: "en bas", - activated: false, + activated: true, tiptap_body: { type: :doc, content: [ @@ -147,7 +147,7 @@ describe Administrateurs::AttestationTemplateV2sController, type: :controller do expect(attestation_template.label_logo).to eq("Ministère des specs") expect(attestation_template.label_direction).to eq("RSPEC") expect(attestation_template.footer).to eq("en bas") - expect(attestation_template.activated).to eq(false) + expect(attestation_template.activated).to eq(true) expect(attestation_template.tiptap_body).to eq(update_params[:tiptap_body]) expect(response.body).to include("Formulaire enregistré") @@ -189,7 +189,7 @@ describe Administrateurs::AttestationTemplateV2sController, type: :controller do expect(attestation_template.label_logo).to eq("Ministère des specs") expect(attestation_template.label_direction).to eq("RSPEC") expect(attestation_template.footer).to eq("en bas") - expect(attestation_template.activated).to eq(false) + expect(attestation_template.activated).to eq(true) expect(attestation_template.tiptap_body).to eq(update_params[:tiptap_body]) expect(response.body).to include("Formulaire enregistré") @@ -232,6 +232,29 @@ describe Administrateurs::AttestationTemplateV2sController, type: :controller do end end end + + context 'toggle activation' do + let(:update_params) { super().merge(activated: false) } + + it 'toggle attribute of current published attestation' do + subject + expect(procedure.attestation_templates.v2.count).to eq(1) + expect(procedure.attestation_templates.v2.first.activated?).to eq(false) + expect(flash.notice).to be_nil + end + + context 'when there is a draft' do + before { + create(:attestation_template, :v2, :draft, procedure:) + } + + it 'toggle attribute of both draft & published v2 attestations' do + subject + expect(procedure.attestation_templates.v2.count).to eq(2) + expect(procedure.attestation_templates.v2.all?(&:activated?)).to eq(false) + end + end + end end describe 'POST reset' do