diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 2e82070d9..b07169338 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -505,7 +505,7 @@ module Users if action_name == 'update' || action_name == 'champ' Dossier.visible_by_user.or(Dossier.for_procedure_preview).or(Dossier.for_editing_fork) elsif action_name == 'restore' - Dossier.hidden_by_user + Dossier.hidden_by_user.or(Dossier.hidden_by_not_modified_for_a_long_time) elsif action_name == 'extend_conservation_and_restore' || (action_name == 'show' && request.format.pdf?) Dossier.visible_by_user.or(Dossier.hidden_by_expired) else diff --git a/app/models/dossier.rb b/app/models/dossier.rb index ae9d12e57..2cc8a28e3 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -219,6 +219,7 @@ class Dossier < ApplicationRecord scope :hidden_by_user, -> { where.not(hidden_by_user_at: nil) } scope :hidden_by_administration, -> { where.not(hidden_by_administration_at: nil) } scope :hidden_by_expired, -> { where.not(hidden_by_expired_at: nil) } + scope :hidden_by_not_modified_for_a_long_time, -> { hidden_by_expired.where(hidden_by_reason: :not_modified_for_a_long_time) } scope :visible_by_user, -> { where(for_procedure_preview: false, hidden_by_user_at: nil, editing_fork_origin_id: nil, hidden_by_expired_at: nil) } scope :visible_by_administration, -> { state_not_brouillon @@ -852,7 +853,9 @@ class Dossier < ApplicationRecord update(hidden_by_user_at: nil) end - if !hidden_by_user? && !hidden_by_administration? + if is_user?(author) && hidden_by_reason&.to_sym == :not_modified_for_a_long_time + update(hidden_by_expired_at: nil) + elsif !hidden_by_user? && !hidden_by_administration? update(hidden_by_reason: nil) elsif hidden_by_user? update(hidden_by_reason: :user_request) diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index 2b855d3a6..317c11365 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -1407,6 +1407,19 @@ describe Users::DossiersController, type: :controller do expect(dossier.reload.hidden_by_user_at).to be_nil end end + + context 'when brouillon has been automatically expired' do + let(:dossier) { create(:dossier, :brouillon, user:) } + + before { + dossier.hide_and_keep_track!(:automatic, :not_modified_for_a_long_time) + } + + it 'must restore hidden attributes' do + expect { subject }.to change { dossier.reload.hidden_by_expired_at }.from(anything).to(nil) + expect(dossier.hidden_by_reason).to eq("not_modified_for_a_long_time") + end + end end describe '#new' do