From 60abc6ea6ec51dda8f811d6920646400b8b2d34d Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Tue, 5 Dec 2023 18:31:20 +0100 Subject: [PATCH] fix(admin): warn when errors block revision publication --- .../administrateurs/procedures_controller.rb | 2 ++ .../administrateurs/procedures/show.html.haml | 6 ++++-- .../administrateurs/procedure_publish_spec.rb | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/app/controllers/administrateurs/procedures_controller.rb b/app/controllers/administrateurs/procedures_controller.rb index 5b4ed4a01..6cd846529 100644 --- a/app/controllers/administrateurs/procedures_controller.rb +++ b/app/controllers/administrateurs/procedures_controller.rb @@ -316,6 +316,8 @@ module Administrateurs flash.notice = "Nouvelle version de la démarche publiée" redirect_to admin_procedure_path(@procedure) + rescue ActiveRecord::RecordInvalid + redirect_to admin_procedure_publication_path(@procedure) end def transfert diff --git a/app/views/administrateurs/procedures/show.html.haml b/app/views/administrateurs/procedures/show.html.haml index 3abf908b2..2078a364c 100644 --- a/app/views/administrateurs/procedures/show.html.haml +++ b/app/views/administrateurs/procedures/show.html.haml @@ -35,12 +35,14 @@ - c.body do = render Procedure::RevisionChangesComponent.new changes: @procedure.revision_changes, previous_revision: @procedure.published_revision + = render Procedure::PublicationWarningComponent.new(procedure: @procedure) + - c.bottom do %ul.fr-mt-2w.fr-btns-group.fr-btns-group--inline - if @procedure.publiee? - %li= button_to 'Publier les modifications', admin_procedure_publish_revision_path(@procedure), class: 'fr-btn', id: 'publish-procedure-link', data: { disable_with: "Publication...", confirm: 'Êtes-vous sûr de vouloir publier les modifications ?' }, disabled: !@procedure.draft_revision.valid?, method: :put + %li= button_to 'Publier les modifications', admin_procedure_publish_revision_path(@procedure), class: 'fr-btn', id: 'publish-procedure-link', data: { disable_with: "Publication...", confirm: 'Êtes-vous sûr de vouloir publier les modifications ?' }, disabled: !@procedure.draft_revision.valid? || @procedure.errors.present?, method: :put - else - %li= button_to 'Publier les modifications', admin_procedure_publication_path(@procedure), class: 'fr-btn', id: 'publish-procedure-link', data: { disable_with: "Publication..." }, disabled: !@procedure.draft_revision.valid?, method: :get + %li= button_to 'Publier les modifications', admin_procedure_publication_path(@procedure), class: 'fr-btn', id: 'publish-procedure-link', data: { disable_with: "Publication..." }, disabled: !@procedure.draft_revision.valid? || @procedure.errors.present?, method: :get %li= button_to "Réinitialiser les modifications", admin_procedure_reset_draft_path(@procedure), class: 'fr-btn fr-btn--secondary fr-mr-2w', data: { confirm: 'Êtes-vous sûr de vouloir réinitialiser les modifications ?' }, method: :put - if !@procedure.procedure_expires_when_termine_enabled? diff --git a/spec/system/administrateurs/procedure_publish_spec.rb b/spec/system/administrateurs/procedure_publish_spec.rb index 70f088dea..1c08b91b8 100644 --- a/spec/system/administrateurs/procedure_publish_spec.rb +++ b/spec/system/administrateurs/procedure_publish_spec.rb @@ -154,4 +154,23 @@ describe 'Publishing a procedure', js: true do expect(page).to have_selector(".dubious-champs", count: dubious_champs.size) end end + + context 'when the procedure has other validation error' do + let(:procedure) { create(:procedure, :published, :with_service, :with_type_de_champ, administrateur:) } + let(:initiated_mail) { create(:initiated_mail, procedure:, body: "Hey!") } + + before do + initiated_mail.body += "\n--invalid balise--" + initiated_mail.save!(validate: false) + + procedure.draft_revision.add_type_de_champ(type_champ: :text, libelle: "Nouveau champ") + end + + scenario 'an error message prevents the publication' do + visit admin_procedure_path(procedure) + expect(page).to have_content('Des problèmes empêchent la publication de la démarche') + expect(page).to have_link('corriger', href: edit_admin_procedure_mail_template_path(procedure, Mails::InitiatedMail::SLUG)) + expect(page).to have_button('Publier les modifications', disabled: true) + end + end end