Merge pull request #7713 from betagouv/more_fix_on_preview

fix(preview): empeche d'accéder a la page aperçu si la revision est invalide
This commit is contained in:
LeSim 2022-09-05 10:48:06 +02:00 committed by GitHub
commit 661c98b4e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 33 additions and 3 deletions

View file

@ -2,6 +2,7 @@ module Administrateurs
class ProceduresController < AdministrateurController
before_action :retrieve_procedure, only: [:champs, :annotations, :modifications, :edit, :monavis, :update_monavis, :jeton, :update_jeton, :publication, :publish, :transfert, :close, :allow_expert_review, :experts_require_administrateur_invitation, :reset_draft]
before_action :procedure_revisable?, only: [:champs, :annotations, :modifications, :reset_draft]
before_action :draft_valid?, only: [:apercu]
ITEMS_PER_PAGE = 25
@ -309,6 +310,13 @@ module Administrateurs
private
def draft_valid?
if procedure_without_control.draft_revision.invalid?
flash.alert = t('preview_unavailable', scope: 'administrateurs.procedures')
redirect_back(fallback_location: champs_admin_procedure_path(procedure_without_control))
end
end
def apercu_tab
params[:tab] || 'dossier'
end

View file

@ -1,4 +1,4 @@
.sub-header
#breadcrumbs.sub-header
.container.flex.justify-between.align-baseline.column
%ul.breadcrumbs.mt-1.mb-3
- steps.each do |step|

View file

@ -1,7 +1,7 @@
= render partial: 'administrateurs/breadcrumbs',
locals: { steps: [link_to('Démarches', admin_procedures_path),
link_to(@procedure.libelle.truncate_words(10), admin_procedure_path(@procedure)),
'Configuration des champs'], preview: true }
'Configuration des champs'], preview: @procedure.draft_revision.valid? }
.container
%h1 Configuration des champs

View file

@ -1,3 +1,9 @@
= turbo_stream.replace 'breadcrumbs' , render(partial: 'administrateurs/breadcrumbs',
locals: { steps: [link_to('Démarches', admin_procedures_path),
link_to(@procedure.libelle.truncate_words(10), admin_procedure_path(@procedure)),
'Configuration des champs'],
preview: @procedure.draft_revision.valid? })
= turbo_stream.replace 'errors-summary', render(TypesDeChampEditor::ErrorsSummary.new(revision: @procedure.draft_revision))
- if @destroyed.present?

View file

@ -5,3 +5,4 @@ en:
replacement_procedure_title: Is this procedure replaced by an existing one? If yes, please indicate the number of the new procedure
actions:
close_procedure: Close the procedure
preview_unavailable: Preview is unavailable due to procedure misconfiguration

View file

@ -5,3 +5,4 @@ fr:
replacement_procedure_title: Cette démarche est-elle remplacée par une existante ? Si oui, veuillez indiquer le n° de la nouvelle démarche
actions:
close_procedure: Clore la démarche
preview_unavailable: Aperçu non disponible car la démarche est mal configurée

View file

@ -18,16 +18,30 @@ describe Administrateurs::ProceduresController, type: :controller do
let(:procedure) { create(:procedure, :with_all_champs) }
subject { get :apercu, params: { id: procedure.id } }
before do
sign_in(admin.user)
get :apercu, params: { id: procedure.id }
end
it do
subject
expect(response).to have_http_status(:ok)
expect(procedure.dossiers.visible_by_user).to be_empty
expect(procedure.dossiers.for_procedure_preview).not_to be_empty
end
context 'when the draft is invalid' do
before do
allow_any_instance_of(ProcedureRevision).to receive(:invalid?).and_return(true)
end
it do
subject
expect(response).to redirect_to(champs_admin_procedure_path(procedure))
expect(flash[:alert]).to be_present
end
end
end
let(:procedure_params) {