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:
commit
28bbfc7b3a
5 changed files with 34 additions and 4 deletions
|
@ -3,6 +3,12 @@ class Procedure::PublicationWarningComponent < ApplicationComponent
|
|||
@procedure = procedure
|
||||
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
|
||||
|
||||
def render?
|
||||
|
@ -26,7 +32,8 @@ class Procedure::PublicationWarningComponent < ApplicationComponent
|
|||
when :attestation_template
|
||||
edit_admin_procedure_attestation_template_path(@procedure)
|
||||
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
|
||||
|
|
|
@ -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
|
||||
- error_messages.each do |(messages, path)|
|
||||
%p.mt-2
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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 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
|
||||
|
|
Loading…
Reference in a new issue