improuve discarded_expired scopes

This commit is contained in:
Paul Chavard 2022-01-11 15:20:23 +01:00 committed by Kara Diaby
parent 68b45ae31d
commit 7e0d471a08

View file

@ -347,23 +347,26 @@ class Dossier < ApplicationRecord
scope :without_en_construction_expiration_notice_sent, -> { where(en_construction_close_to_expiration_notice_sent_at: nil) } scope :without_en_construction_expiration_notice_sent, -> { where(en_construction_close_to_expiration_notice_sent_at: nil) }
scope :without_termine_expiration_notice_sent, -> { where(termine_close_to_expiration_notice_sent_at: nil) } scope :without_termine_expiration_notice_sent, -> { where(termine_close_to_expiration_notice_sent_at: nil) }
scope :discarded_expired, -> { discarded.where('dossiers.hidden_at < ?', 1.week.ago) }
scope :discarded_by_user_expired, -> { discarded.where('dossiers.hidden_by_user_at < ?', 1.week.ago) }
scope :discarded_by_administration_expired, -> { discarded.where('dossiers.hidden_by_administration_at < ?', 1.week.ago) }
scope :discarded_brouillon_expired, -> do scope :discarded_brouillon_expired, -> do
with_discarded with_discarded
.discarded
.state_brouillon .state_brouillon
.where('hidden_at < ?', 1.week.ago) .discarded_expired
.or(state_brouillon.discarded_by_user_expired)
end end
scope :discarded_en_construction_expired, -> do scope :discarded_en_construction_expired, -> do
with_discarded with_discarded
.discarded
.state_en_construction .state_en_construction
.where('dossiers.hidden_at < ?', 1.week.ago) .discarded_expired
.or(state_en_construction.discarded_by_user_expired)
end end
scope :discarded_termine_expired, -> do scope :discarded_termine_expired, -> do
with_discarded with_discarded
.discarded
.state_termine .state_termine
.where('dossiers.hidden_at < ?', 1.week.ago) .discarded_expired
.or(state_termine.discarded_by_user_expired.discarded_by_administration_expired)
end end
scope :brouillon_near_procedure_closing_date, -> do scope :brouillon_near_procedure_closing_date, -> do
@ -774,14 +777,14 @@ class Dossier < ApplicationRecord
end end
if can_be_hidden_by_user? && author_is_user(author) if can_be_hidden_by_user? && author_is_user(author)
update(hidden_by_user_at: Time.zone.now) update(hidden_by_user_at: Time.zone.now, dossier_transfer_id: nil)
end end
user_email = user_deleted? ? nil : user_email_for(:notification) user_email = user_deleted? ? nil : user_email_for(:notification)
deleted_dossier = nil deleted_dossier = nil
transaction do transaction do
if deleted_by_instructeur_and_user? || en_construction? && author_is_administration(author) || brouillon? if deleted_by_instructeur_and_user? || en_construction? || brouillon?
if keep_track_on_deletion? if keep_track_on_deletion?
log_dossier_operation(author, :supprimer, self) log_dossier_operation(author, :supprimer, self)
deleted_dossier = DeletedDossier.create_from_dossier(self, reason) deleted_dossier = DeletedDossier.create_from_dossier(self, reason)