fix multiple errors from creation of dedicated method to restore and extend

This commit is contained in:
Lisa Durand 2024-07-25 14:40:22 +02:00
parent 4b1e743ecf
commit 4f7b0c93d0
No known key found for this signature in database
GPG key ID: 0DF91F2CA1E8B816
5 changed files with 10 additions and 6 deletions

View file

@ -25,6 +25,8 @@ module Instructeurs
def extend_conservation_and_restore def extend_conservation_and_restore
dossier.extend_conservation_and_restore(1.month, current_instructeur) dossier.extend_conservation_and_restore(1.month, current_instructeur)
flash[:notice] = t('views.instructeurs.dossiers.archived_dossier')
redirect_back(fallback_location: instructeur_dossier_path(@dossier.procedure, @dossier))
end end
def geo_data def geo_data
@ -380,7 +382,7 @@ module Instructeurs
Dossier Dossier
.where(id: current_instructeur.dossiers.visible_by_administration) .where(id: current_instructeur.dossiers.visible_by_administration)
.or(Dossier.where(id: current_user.dossiers.for_procedure_preview)) .or(Dossier.where(id: current_user.dossiers.for_procedure_preview))
elsif action_name == 'extend_conservation' elsif action_name == 'extend_conservation_and_restore'
Dossier Dossier
.where(id: current_instructeur.dossiers.visible_by_administration) .where(id: current_instructeur.dossiers.visible_by_administration)
.or(Dossier.where(id: current_instructeur.dossiers.hidden_by_expired)) .or(Dossier.where(id: current_instructeur.dossiers.hidden_by_expired))

View file

@ -260,7 +260,9 @@ module Users
end end
def extend_conservation_and_restore def extend_conservation_and_restore
dossier.extend_conservation_and_restore(conservation_extension, author) dossier.extend_conservation_and_restore(dossier.procedure.duree_conservation_dossiers_dans_ds.months, current_user)
flash[:notice] = t('views.users.dossiers.archived_dossier', duree_conservation_dossiers_dans_ds: dossier.procedure.duree_conservation_dossiers_dans_ds)
redirect_back(fallback_location: dossier_path(@dossier))
end end
def modifier def modifier
@ -534,7 +536,7 @@ module Users
Dossier.visible_by_user.or(Dossier.for_procedure_preview).or(Dossier.for_editing_fork) Dossier.visible_by_user.or(Dossier.for_procedure_preview).or(Dossier.for_editing_fork)
elsif action_name == 'restore' elsif action_name == 'restore'
Dossier.hidden_by_user Dossier.hidden_by_user
elsif action_name == 'extend_conservation' elsif action_name == 'extend_conservation_and_restore'
Dossier.visible_by_user.or(Dossier.hidden_by_expired) Dossier.visible_by_user.or(Dossier.hidden_by_expired)
else else
Dossier.visible_by_user Dossier.visible_by_user

View file

@ -691,7 +691,7 @@ class Dossier < ApplicationRecord
def extend_conservation_and_restore(conservation_extension, author) def extend_conservation_and_restore(conservation_extension, author)
extend_conservation(conservation_extension) extend_conservation(conservation_extension)
update(hidden_by_expired_at: nil, hidden_by_reason: nil) update(hidden_by_expired_at: nil, hidden_by_reason: nil)
restore(current_user) restore(author)
end end
def show_procedure_state_warning? def show_procedure_state_warning?

View file

@ -108,7 +108,7 @@
- else - else
- if dossier.expiration_can_be_extended? - if dossier.expiration_can_be_extended?
= button_to users_dossier_extend_conservation_and_restore_path(dossier), class: 'fr-btn fr-btn--sm' do = button_to users_dossier_repousser_expiration_and_restore_path(dossier), class: 'fr-btn fr-btn--sm' do
Restaurer et étendre la conservation Restaurer et étendre la conservation

View file

@ -1308,7 +1308,7 @@ describe Instructeurs::DossiersController, type: :controller do
end end
describe '#extend_conservation and restore' do describe '#extend_conservation and restore' do
subject { post :extend_conservation, params: { procedure_id: procedure.id, dossier_id: dossier.id } } subject { post :extend_conservation_and_restore, params: { procedure_id: procedure.id, dossier_id: dossier.id } }
before do before do
dossier.update(hidden_by_expired_at: 1.hour.ago, hidden_by_reason: 'expired') dossier.update(hidden_by_expired_at: 1.hour.ago, hidden_by_reason: 'expired')