diff --git a/app/controllers/instructeurs/dossiers_controller.rb b/app/controllers/instructeurs/dossiers_controller.rb index 3dc179258..d7ebd7078 100644 --- a/app/controllers/instructeurs/dossiers_controller.rb +++ b/app/controllers/instructeurs/dossiers_controller.rb @@ -18,11 +18,15 @@ module Instructeurs 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 68d284040..79e244ecc 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -254,11 +254,15 @@ module Users 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 5c9503ec4..f6abad9b1 100644 --- a/app/models/batch_operation.rb +++ b/app/models/batch_operation.rb @@ -92,7 +92,7 @@ class BatchOperation < ApplicationRecord 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 6c46d3b2b..6e13231b5 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -681,16 +681,17 @@ class Dossier < ApplicationRecord 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 59bb4de63..e55c99d00 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 62f8d38d8..a7f93a637 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 77991c3d6..3a8e72fba 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -268,6 +268,7 @@ Rails.application.routes.draw do 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 @@ Rails.application.routes.draw do 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 0627c5f08..16476828c 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -107,8 +107,8 @@ describe Dossier, type: :model do 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 @@ describe Dossier, type: :model do 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 @@ describe Dossier, type: :model do 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