Skip to content

Commit

Permalink
feat(attestation): can toggle activation
Browse files Browse the repository at this point in the history
  • Loading branch information
colinux committed Jun 5, 2024
1 parent deb3b0f commit fc5dd21
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 12 deletions.
2 changes: 2 additions & 0 deletions app/components/dsfr/callout_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def theme_class
"fr-callout--brown-caramel"
when :success
"fr-callout--green-emeraude"
when :neutral
# default
else
"fr-background-alt--blue-france"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ def edit
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
Expand Down Expand Up @@ -139,7 +145,7 @@ def retrieve_attestation_template
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 12 additions & 2 deletions app/views/administrateurs/attestation_template_v2s/edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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'} }
Expand Down Expand Up @@ -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 }
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- 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 })
= turbo_stream.update "fixed_footer", render(partial: "fixed_footer", locals: { procedure: @procedure })
= turbo_stream.update "sticky-header", render(partial: "sticky_header")

= turbo_stream.show 'autosave-notice'
Expand Down
Original file line number Diff line number Diff line change
@@ -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') }

Expand All @@ -11,7 +11,7 @@
label_logo: "Ministère des specs",
label_direction: "RSPEC",
footer: "en bas",
activated: false,
activated: true,
tiptap_body: {
type: :doc,
content: [
Expand Down Expand Up @@ -147,7 +147,7 @@
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é")
Expand Down Expand Up @@ -189,7 +189,7 @@
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é")
Expand Down Expand Up @@ -232,6 +232,29 @@
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
Expand Down

0 comments on commit fc5dd21

Please sign in to comment.