Merge pull request #11120 from colinux/fix-restore-brouillon-expired-by-automatic
ETQ usager je peux restorer un brouillon supprimé automatiquement car pas modifié automatiquement
This commit is contained in:
commit
f3bb274657
3 changed files with 18 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue