feat(attestation): can reset draft attestation

This commit is contained in:
Colin Darie 2024-05-31 10:03:23 +02:00
parent a540f8dccb
commit cd07ee173f
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
5 changed files with 38 additions and 4 deletions

View file

@ -104,6 +104,13 @@ module Administrateurs
def create = update 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 private
def ensure_feature_active def ensure_feature_active

View file

@ -3,8 +3,13 @@
%p.flex.justify-between.align-center.fr-text-default--warning %p.flex.justify-between.align-center.fr-text-default--warning
%span %span
= dsfr_icon("fr-icon-warning-fill fr-mr-1v") = dsfr_icon("fr-icon-warning-fill fr-mr-1v")
Les modifications effectuées ne seront appliquées quune fois que vous aurez publié cette version de lattestation. Les modifications effectuées ne seront appliquées quà la prochaine publication.
%span %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", %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' } } data: { 'disable-with': "Publication en cours…", controller: 'autosave-submit' } }
Publier lattestation Publier les modifications

View file

@ -684,7 +684,9 @@ Rails.application.routes.draw do
get 'add_champ_engagement_juridique' get 'add_champ_engagement_juridique'
end 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] resource :dossier_submitted_message, only: [:edit, :update, :create]
# ADDED TO ACCESS IT FROM THE IFRAME # ADDED TO ACCESS IT FROM THE IFRAME

View file

@ -233,4 +233,25 @@ describe Administrateurs::AttestationTemplateV2sController, type: :controller do
end end
end 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 end

View file

@ -138,7 +138,6 @@ describe 'As an administrateur, I want to manage the procedures attestation',
expect(page).to have_field("Contenu du pied de page", with: "line1\nline2\nline3\nline4") expect(page).to have_field("Contenu du pied de page", with: "line1\nline2\nline3\nline4")
click_on "Publier" click_on "Publier"
expect(page).to have_text("Lattestation a été publiée")
expect(attestation.reload).to be_published expect(attestation.reload).to be_published
end end