fix(admin): warn when errors block revision publication

This commit is contained in:
Colin Darie 2023-12-05 18:31:20 +01:00
parent 70ddced7e8
commit 60abc6ea6e
3 changed files with 25 additions and 2 deletions

View file

@ -316,6 +316,8 @@ module Administrateurs
flash.notice = "Nouvelle version de la démarche publiée" flash.notice = "Nouvelle version de la démarche publiée"
redirect_to admin_procedure_path(@procedure) redirect_to admin_procedure_path(@procedure)
rescue ActiveRecord::RecordInvalid
redirect_to admin_procedure_publication_path(@procedure)
end end
def transfert def transfert

View file

@ -35,12 +35,14 @@
- c.body do - c.body do
= render Procedure::RevisionChangesComponent.new changes: @procedure.revision_changes, previous_revision: @procedure.published_revision = render Procedure::RevisionChangesComponent.new changes: @procedure.revision_changes, previous_revision: @procedure.published_revision
= render Procedure::PublicationWarningComponent.new(procedure: @procedure)
- c.bottom do - c.bottom do
%ul.fr-mt-2w.fr-btns-group.fr-btns-group--inline %ul.fr-mt-2w.fr-btns-group.fr-btns-group--inline
- if @procedure.publiee? - 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 - 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 %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? - if !@procedure.procedure_expires_when_termine_enabled?

View file

@ -154,4 +154,23 @@ describe 'Publishing a procedure', js: true do
expect(page).to have_selector(".dubious-champs", count: dubious_champs.size) expect(page).to have_selector(".dubious-champs", count: dubious_champs.size)
end end
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 end