From ba56c793255e146dac3c41beafba7924b3f873ce Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Tue, 3 Oct 2023 11:11:17 +0200 Subject: [PATCH] admin can't reactivate procedure if auto archive on past --- .../administrateurs/procedures_controller.rb | 11 +++++--- .../procedures_controller_spec.rb | 26 +++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/app/controllers/administrateurs/procedures_controller.rb b/app/controllers/administrateurs/procedures_controller.rb index f42e63808..1ddb2754e 100644 --- a/app/controllers/administrateurs/procedures_controller.rb +++ b/app/controllers/administrateurs/procedures_controller.rb @@ -264,9 +264,14 @@ module Administrateurs draft_revision: :types_de_champ ).find(params[:procedure_id]) - @procedure.path = @procedure.suggested_path(current_administrateur) - @current_administrateur = current_administrateur - @closed_procedures = current_administrateur.procedures.with_discarded.closes.map { |p| ["#{p.libelle} (#{p.id})", p.id] }.to_h + if @procedure.auto_archive_on && !@procedure.auto_archive_on.future? + flash.alert = "La date limite de dépôt des dossiers doit être postérieure à la date du jour pour réactiver la procédure. #{view_context.link_to('Veuillez la modifier', edit_admin_procedure_path(@procedure))}" + redirect_to admin_procedure_path(@procedure) + else + @procedure.path = @procedure.suggested_path(current_administrateur) + @current_administrateur = current_administrateur + @closed_procedures = current_administrateur.procedures.with_discarded.closes.map { |p| ["#{p.libelle} (#{p.id})", p.id] }.to_h + end end def publish diff --git a/spec/controllers/administrateurs/procedures_controller_spec.rb b/spec/controllers/administrateurs/procedures_controller_spec.rb index c53f11b93..338f94d0e 100644 --- a/spec/controllers/administrateurs/procedures_controller_spec.rb +++ b/spec/controllers/administrateurs/procedures_controller_spec.rb @@ -902,6 +902,32 @@ describe Administrateurs::ProceduresController, type: :controller do end end + describe 'GET #publication' do + subject(:perform_request) { get :publication, params: { procedure_id: procedure.id } } + + context 'when procedure is closed' do + let(:procedure) { create(:procedure, :closed, administrateur: admin) } + + it 'assigns procedure' do + perform_request + expect(response).to have_http_status(:ok) + end + + context 'with auto_archive on past' do + before do + procedure.auto_archive_on = Date.today - 1.week + procedure.save(validate: false) + end + + it 'suggest to update autoarchive' do + perform_request + expect(response).to redirect_to(admin_procedure_path(procedure.id)) + expect(flash.alert).to include('La date limite de dépôt des dossiers doit être postérieure à la date du jour pour réactiver la procédure.') + end + end + end + end + describe 'PUT #publish' do let(:procedure) { create(:procedure, administrateur: admin, lien_site_web: lien_site_web) } let(:procedure2) { create(:procedure, :published, administrateur: admin, lien_site_web: lien_site_web) }