Merge pull request #9800 from colinux/fix-publication-revision-errors

ETQ admin je suis prévenu si des erreurs sur la démarche empêchent la publication de révision
This commit is contained in:
mfo 2023-12-08 17:14:14 +00:00 committed by GitHub
commit 28bbfc7b3a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 4 deletions

View file

@ -3,6 +3,12 @@ class Procedure::PublicationWarningComponent < ApplicationComponent
@procedure = procedure @procedure = procedure
end end
def title
return "Des problèmes empêchent la publication des modifications" if @procedure.publiee?
"Des problèmes empêchent la publication de la démarche"
end
private private
def render? def render?
@ -26,7 +32,8 @@ class Procedure::PublicationWarningComponent < ApplicationComponent
when :attestation_template when :attestation_template
edit_admin_procedure_attestation_template_path(@procedure) edit_admin_procedure_attestation_template_path(@procedure)
when :initiated_mail, :received_mail, :closed_mail, :refused_mail, :without_continuation_mail, :re_instructed_mail when :initiated_mail, :received_mail, :closed_mail, :refused_mail, :without_continuation_mail, :re_instructed_mail
admin_procedure_mail_templates_path(@procedure) klass = "Mails::#{attribute.to_s.classify}".constantize
edit_admin_procedure_mail_template_path(@procedure, klass.const_get(:SLUG))
end end
end end
end end

View file

@ -1,4 +1,4 @@
= render Dsfr::AlertComponent.new(state: :warning, title: "Des problèmes empêchent la publication de la démarche") do |c| = render Dsfr::AlertComponent.new(state: :warning, title:) do |c|
- c.body do - c.body do
- error_messages.each do |(messages, path)| - error_messages.each do |(messages, path)|
%p.mt-2 %p.mt-2

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 des modifications')
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