diff --git a/app/controllers/instructeurs/dossiers_controller.rb b/app/controllers/instructeurs/dossiers_controller.rb index 3dc179258c5..d7ebd707868 100644 --- a/app/controllers/instructeurs/dossiers_controller.rb +++ b/app/controllers/instructeurs/dossiers_controller.rb @@ -18,11 +18,15 @@ class DossiersController < ProceduresController after_action :mark_annotations_privees_as_read, only: [:annotations_privees, :update_annotations] def extend_conservation - dossier.extend_conservation(1.month, current_instructeur) + dossier.extend_conservation(1.month) flash[:notice] = t('views.instructeurs.dossiers.archived_dossier') redirect_back(fallback_location: instructeur_dossier_path(@dossier.procedure, @dossier)) end + def extend_conservation_and_restore + dossier.extend_conservation_and_restore(1.month, current_instructeur) + end + def geo_data send_data dossier.to_feature_collection.to_json, type: 'application/json', diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 73ade9250d0..100d0f01260 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -254,11 +254,15 @@ def submit_brouillon end def extend_conservation - dossier.extend_conservation(dossier.procedure.duree_conservation_dossiers_dans_ds.months, current_user) + dossier.extend_conservation(dossier.procedure.duree_conservation_dossiers_dans_ds.months) 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 + def extend_conservation_and_restore + dossier.extend_conservation_and_restore(conservation_extension, author) + end + def modifier @dossier = dossier_with_champs end diff --git a/app/models/batch_operation.rb b/app/models/batch_operation.rb index 5c9503ec44f..f6abad9b169 100644 --- a/app/models/batch_operation.rb +++ b/app/models/batch_operation.rb @@ -92,7 +92,7 @@ def process_one(dossier) when BatchOperation.operations.fetch(:follow) instructeur.follow(dossier) when BatchOperation.operations.fetch(:repousser_expiration) - dossier.extend_conservation(1.month, instructeur) + dossier.extend_conservation(1.month) when BatchOperation.operations.fetch(:repasser_en_construction) dossier.repasser_en_construction!(instructeur: instructeur) when BatchOperation.operations.fetch(:unfollow) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index cae1a019237..98a8be7f99e 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -686,16 +686,17 @@ def expiration_can_be_extended? brouillon? || en_construction? end - def extend_conservation(conservation_extension, author) + def extend_conservation(conservation_extension) update(conservation_extension: self.conservation_extension + conservation_extension, brouillon_close_to_expiration_notice_sent_at: nil, en_construction_close_to_expiration_notice_sent_at: nil, termine_close_to_expiration_notice_sent_at: nil) + end - if hidden_by_expired? - update(hidden_by_expired_at: nil, hidden_by_reason: nil) - restore(author) - end + def extend_conservation_and_restore(conservation_extension, author) + extend_conservation(conservation_extension) + update(hidden_by_expired_at: nil, hidden_by_reason: nil) + restore(current_user) end def show_procedure_state_warning? diff --git a/app/views/instructeurs/procedures/_dossier_actions.html.haml b/app/views/instructeurs/procedures/_dossier_actions.html.haml index 59bb4de631d..e55c99d002b 100644 --- a/app/views/instructeurs/procedures/_dossier_actions.html.haml +++ b/app/views/instructeurs/procedures/_dossier_actions.html.haml @@ -1,6 +1,6 @@ - if hidden_by_administration && hidden_by_expired %li - = button_to repousser_expiration_instructeur_dossier_path(procedure_id, dossier_id), method: :patch, class: "fr-btn fr-icon-refresh-line" do + = button_to repousser_expiration_and_restore_instructeur_dossier_path(procedure_id, dossier_id), method: :patch, class: "fr-btn fr-icon-refresh-line" do = t('views.instructeurs.dossiers.restore_and_extend') - elsif hidden_by_administration diff --git a/app/views/users/dossiers/_dossiers_list.html.haml b/app/views/users/dossiers/_dossiers_list.html.haml index 62f8d38d8f2..a7f93a63735 100644 --- a/app/views/users/dossiers/_dossiers_list.html.haml +++ b/app/views/users/dossiers/_dossiers_list.html.haml @@ -108,7 +108,7 @@ - else - if dossier.expiration_can_be_extended? - = button_to users_dossier_repousser_expiration_path(dossier), class: 'fr-btn fr-btn--sm' do + = button_to users_dossier_extend_conservation_and_restore_path(dossier), class: 'fr-btn fr-btn--sm' do Restaurer et étendre la conservation diff --git a/config/routes.rb b/config/routes.rb index 77991c3d678..3a8e72fba5b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -268,6 +268,7 @@ get '/carte' => 'carte#show' post '/carte' => 'carte#save' post '/repousser-expiration' => 'dossiers#extend_conservation' + post '/repousser-expiration-and-restore' => 'dossiers#extend_conservation_and_restore' end # Redirection of legacy "/users/dossiers" route to "/dossiers" @@ -489,6 +490,7 @@ member do resources :commentaires, only: [:destroy] post 'repousser-expiration' => 'dossiers#extend_conservation' + post 'repousser-expiration-and-restore' => 'dossiers#extend_conservation_and_restore' get 'geo_data' get 'apercu_attestation' get 'bilans_bdf' diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 0304cb69d16..6a716acf960 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -107,8 +107,8 @@ context 'does not include an expiring dossier that has been postponed' do before do - expiring_dossier.extend_conservation(1.month, user) - expiring_dossier_with_notification.extend_conservation(1.month, user) + expiring_dossier.extend_conservation(1.month) + expiring_dossier_with_notification.extend_conservation(1.month) expiring_dossier.reload expiring_dossier_with_notification.reload end @@ -158,8 +158,8 @@ context 'does not include an expiring dossier that has been postponed' do before do - expiring_dossier.extend_conservation(1.month, user) - expiring_dossier_with_notification.extend_conservation(1.month, user) + expiring_dossier.extend_conservation(1.month) + expiring_dossier_with_notification.extend_conservation(1.month) expiring_dossier.reload expiring_dossier_with_notification.reload end @@ -218,8 +218,8 @@ context 'does not include an expiring dossier that has been postponed' do before do - expiring_dossier.extend_conservation(1.month, user) - expiring_dossier_with_notification.extend_conservation(1.month, user) + expiring_dossier.extend_conservation(1.month) + expiring_dossier_with_notification.extend_conservation(1.month) expiring_dossier.reload expiring_dossier_with_notification.reload end