Lors de la restauration d'une démarche supprimée, met sur les dossiers liés hidden_by_administration_at à nil

This commit is contained in:
Kara Diaby 2022-06-10 12:33:47 +02:00
parent 9c5bf1ed1f
commit d58ecb3fcc
3 changed files with 11 additions and 3 deletions

View file

@ -177,7 +177,7 @@ module Administrateurs
def restore def restore
procedure = current_administrateur.procedures.with_discarded.discarded.find(params[:id]) procedure = current_administrateur.procedures.with_discarded.discarded.find(params[:id])
procedure.restore_procedure procedure.restore_procedure(current_administrateur)
flash.notice = t('administrateurs.index.restored', procedure_id: procedure.id) flash.notice = t('administrateurs.index.restored', procedure_id: procedure.id)
redirect_to admin_procedures_path redirect_to admin_procedures_path
end end

View file

@ -707,9 +707,12 @@ class Procedure < ApplicationRecord
end end
end end
def restore_procedure def restore_procedure(author)
if discarded? if discarded?
undiscard undiscard
self.dossiers.hidden_by_administration.each do |dossier|
dossier.restore(author)
end
end end
end end

View file

@ -785,7 +785,11 @@ describe Administrateurs::ProceduresController, type: :controller do
end end
describe 'PUT #restore' do describe 'PUT #restore' do
let(:procedure) { create :procedure, :discarded, administrateur: admin } let(:procedure) { create :procedure_with_dossiers, :with_service, :published, administrateur: admin }
before do
procedure.discard_and_keep_track!(admin)
end
context 'when the admin wants to restore a procedure' do context 'when the admin wants to restore a procedure' do
before do before do
@ -794,6 +798,7 @@ describe Administrateurs::ProceduresController, type: :controller do
end end
it { expect(procedure.discarded?).to be_falsy } it { expect(procedure.discarded?).to be_falsy }
it { expect(procedure.dossiers.first.hidden_by_administration_at).to be_nil }
end end
end end
end end