diff --git a/app/controllers/instructeurs/dossiers_controller.rb b/app/controllers/instructeurs/dossiers_controller.rb index 1605c4de1..11ff38c6d 100644 --- a/app/controllers/instructeurs/dossiers_controller.rb +++ b/app/controllers/instructeurs/dossiers_controller.rb @@ -376,6 +376,10 @@ module Instructeurs Dossier .where(id: current_instructeur.dossiers.visible_by_administration) .or(Dossier.where(id: current_user.dossiers.for_procedure_preview)) + elsif action_name == 'extend_conservation' + Dossier + .where(id: current_instructeur.dossiers.visible_by_administration) + .or(Dossier.where(id: current_instructeur.dossiers.hidden_by_automatic)) else current_instructeur.dossiers.visible_by_administration end diff --git a/app/models/dossier.rb b/app/models/dossier.rb index c78ca8208..4b17b1933 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -689,6 +689,10 @@ class Dossier < ApplicationRecord 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) + + if hidden_at.present? + update(hidden_at: nil, hidden_by_reason: nil) + end end def show_procedure_state_warning? diff --git a/app/services/dossier_projection_service.rb b/app/services/dossier_projection_service.rb index 85521f70f..4eb691c8a 100644 --- a/app/services/dossier_projection_service.rb +++ b/app/services/dossier_projection_service.rb @@ -1,5 +1,5 @@ class DossierProjectionService - class DossierProjection < Struct.new(:dossier_id, :state, :archived, :hidden_by_user_at, :hidden_by_administration_at, :for_tiers, :prenom, :nom, :batch_operation_id, :sva_svr_decision_on, :corrections, :columns) do + class DossierProjection < Struct.new(:dossier_id, :state, :archived, :hidden_by_user_at, :hidden_by_administration_at, :hidden_at, :for_tiers, :prenom, :nom, :batch_operation_id, :sva_svr_decision_on, :corrections, :columns) do def pending_correction? return false if corrections.blank? @@ -44,13 +44,14 @@ class DossierProjectionService batch_operation_field = { TABLE => 'self', COLUMN => 'batch_operation_id' } hidden_by_user_at_field = { TABLE => 'self', COLUMN => 'hidden_by_user_at' } hidden_by_administration_at_field = { TABLE => 'self', COLUMN => 'hidden_by_administration_at' } + hidden_at_field = { TABLE => 'self', COLUMN => 'hidden_at' } for_tiers_field = { TABLE => 'self', COLUMN => 'for_tiers' } individual_first_name = { TABLE => 'individual', COLUMN => 'prenom' } individual_last_name = { TABLE => 'individual', COLUMN => 'nom' } sva_svr_decision_on_field = { TABLE => 'self', COLUMN => 'sva_svr_decision_on' } dossier_corrections = { TABLE => 'dossier_corrections', COLUMN => 'resolved_at' } champ_value = champ_value_formatter(dossiers_ids, fields) - ([state_field, archived_field, sva_svr_decision_on_field, hidden_by_user_at_field, hidden_by_administration_at_field, for_tiers_field, individual_first_name, individual_last_name, batch_operation_field, dossier_corrections] + fields) # the view needs state and archived dossier attributes + ([state_field, archived_field, sva_svr_decision_on_field, hidden_by_user_at_field, hidden_by_administration_at_field, hidden_at_field, for_tiers_field, individual_first_name, individual_last_name, batch_operation_field, dossier_corrections] + fields) .each { |f| f[:id_value_h] = {} } .group_by { |f| f[TABLE] } # one query per table .each do |table, fields| @@ -73,7 +74,7 @@ class DossierProjectionService .pluck(:id, *fields.map { |f| f[COLUMN].to_sym }) .each do |id, *columns| fields.zip(columns).each do |field, value| - if [state_field, archived_field, hidden_by_user_at_field, hidden_by_administration_at_field, for_tiers_field, batch_operation_field, sva_svr_decision_on_field].include?(field) + if [state_field, archived_field, hidden_by_user_at_field, hidden_by_administration_at_field, hidden_at_field, for_tiers_field, batch_operation_field, sva_svr_decision_on_field].include?(field) field[:id_value_h][id] = value else field[:id_value_h][id] = value&.strftime('%d/%m/%Y') # other fields are datetime @@ -150,6 +151,7 @@ class DossierProjectionService archived_field[:id_value_h][dossier_id], hidden_by_user_at_field[:id_value_h][dossier_id], hidden_by_administration_at_field[:id_value_h][dossier_id], + hidden_at_field[:id_value_h][dossier_id], for_tiers_field[:id_value_h][dossier_id], individual_first_name[:id_value_h][dossier_id], individual_last_name[:id_value_h][dossier_id], diff --git a/app/views/instructeurs/dossiers/_header_actions.html.haml b/app/views/instructeurs/dossiers/_header_actions.html.haml index f13702df7..b58a1f496 100644 --- a/app/views/instructeurs/dossiers/_header_actions.html.haml +++ b/app/views/instructeurs/dossiers/_header_actions.html.haml @@ -8,6 +8,7 @@ dossier_is_followed: current_instructeur&.follow?(dossier), close_to_expiration: dossier.close_to_expiration?, hidden_by_administration: dossier.hidden_by_administration?, + hidden_at: dossier.hidden_at.present?, has_pending_correction: dossier.pending_correction?, has_blocking_pending_correction: dossier.procedure.feature_enabled?(:blocking_pending_correction) && dossier.pending_correction?, turbo: true, diff --git a/app/views/instructeurs/procedures/_dossier_actions.html.haml b/app/views/instructeurs/procedures/_dossier_actions.html.haml index fb0b1435d..0db82e409 100644 --- a/app/views/instructeurs/procedures/_dossier_actions.html.haml +++ b/app/views/instructeurs/procedures/_dossier_actions.html.haml @@ -1,7 +1,13 @@ -- if hidden_by_administration +- if hidden_by_administration && hidden_at + %li + = button_to repousser_expiration_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 %li = button_to restore_instructeur_dossier_path(procedure_id, dossier_id), method: :patch, class: "fr-btn fr-icon-refresh-line" do = t('views.instructeurs.dossiers.restore') + - elsif close_to_expiration || Dossier::TERMINE.include?(state) %li - if close_to_expiration diff --git a/app/views/instructeurs/procedures/show.html.haml b/app/views/instructeurs/procedures/show.html.haml index a5bd8de97..bc9188a5b 100644 --- a/app/views/instructeurs/procedures/show.html.haml +++ b/app/views/instructeurs/procedures/show.html.haml @@ -172,6 +172,7 @@ dossier_is_followed: @followed_dossiers_id.include?(p.dossier_id), close_to_expiration: @statut == 'expirant', hidden_by_administration: @statut == 'supprimes_recemment', + hidden_at: p.hidden_at.present?, sva_svr: @procedure.sva_svr_enabled?, has_blocking_pending_correction: @procedure.feature_enabled?(:blocking_pending_correction) && p.pending_correction?, turbo: false, diff --git a/app/views/recherche/index.html.haml b/app/views/recherche/index.html.haml index 7fb4bce78..d4360f8c9 100644 --- a/app/views/recherche/index.html.haml +++ b/app/views/recherche/index.html.haml @@ -102,6 +102,7 @@ dossier_is_followed: @followed_dossiers_id.include?(p.dossier_id), close_to_expiration: nil, hidden_by_administration: nil, + hidden_at: nil, sva_svr: p.sva_svr_decision_on.present?, has_blocking_pending_correction: p.pending_correction? && Flipper.enabled?(:blocking_pending_correction, ProcedureFlipperActor.new(procedure_id)), turbo: false, diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 5c72b1f50..763bf35c2 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -409,6 +409,7 @@ fr: acts_on_behalf: "agit pour" deleted_by_administration: "Dossier supprimé par l’administration" restore: "Restaurer" + restore_and_extend: "Restaurer et étendre la conservation" filters: title: Sélectionner un filtre select_all: Tout selectionner diff --git a/spec/controllers/instructeurs/dossiers_controller_spec.rb b/spec/controllers/instructeurs/dossiers_controller_spec.rb index 9445a00db..1a4af55d2 100644 --- a/spec/controllers/instructeurs/dossiers_controller_spec.rb +++ b/spec/controllers/instructeurs/dossiers_controller_spec.rb @@ -1307,6 +1307,19 @@ describe Instructeurs::DossiersController, type: :controller do end end + describe '#extend_conservation and restore' do + before do + dossier.update(hidden_at: 1.hour.ago, hidden_by_reason: 'expired') + end + subject { post :extend_conservation, params: { procedure_id: procedure.id, dossier_id: dossier.id } } + + it "puts hidden_at to nil and extends conservation_extension by 1 month" do + subject + expect(dossier.reload.hidden_at).to eq(nil) + expect(dossier.reload.conservation_extension).to eq(1.month) + end + end + describe '#reaffectation' do let!(:gi_2) { GroupeInstructeur.create(label: 'deuxième groupe', procedure: procedure) } let!(:gi_3) { GroupeInstructeur.create(label: 'troisième groupe', procedure: procedure) }