Merge pull request #5077 from tchak/deleted_dossiers_safer_notifications
Mark as sent or destroy right after each notification
This commit is contained in:
commit
76d95e092d
1 changed files with 27 additions and 15 deletions
|
@ -28,29 +28,27 @@ class ExpiredDossiersDeletionService
|
||||||
dossiers,
|
dossiers,
|
||||||
user.email
|
user.email
|
||||||
).deliver_later
|
).deliver_later
|
||||||
|
|
||||||
|
# mark as sent dossiers from current notification
|
||||||
|
Dossier.where(id: dossiers).update_all(brouillon_close_to_expiration_notice_sent_at: Time.zone.now)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# mark as sent dossiers without notification
|
||||||
dossiers_close_to_expiration.update_all(brouillon_close_to_expiration_notice_sent_at: Time.zone.now)
|
dossiers_close_to_expiration.update_all(brouillon_close_to_expiration_notice_sent_at: Time.zone.now)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.send_en_construction_expiration_notices
|
def self.send_en_construction_expiration_notices
|
||||||
dossiers_close_to_expiration = Dossier
|
send_expiration_notices(
|
||||||
.en_construction_close_to_expiration
|
Dossier.en_construction_close_to_expiration.without_en_construction_expiration_notice_sent,
|
||||||
.without_en_construction_expiration_notice_sent
|
:en_construction_close_to_expiration_notice_sent_at
|
||||||
|
)
|
||||||
send_expiration_notices(dossiers_close_to_expiration)
|
|
||||||
|
|
||||||
dossiers_close_to_expiration.update_all(en_construction_close_to_expiration_notice_sent_at: Time.zone.now)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.send_termine_expiration_notices
|
def self.send_termine_expiration_notices
|
||||||
dossiers_close_to_expiration = Dossier
|
send_expiration_notices(
|
||||||
.termine_close_to_expiration
|
Dossier.termine_close_to_expiration.without_termine_expiration_notice_sent,
|
||||||
.without_termine_expiration_notice_sent
|
:termine_close_to_expiration_notice_sent_at
|
||||||
|
)
|
||||||
send_expiration_notices(dossiers_close_to_expiration)
|
|
||||||
|
|
||||||
dossiers_close_to_expiration.update_all(termine_close_to_expiration_notice_sent_at: Time.zone.now)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.delete_expired_brouillons_and_notify
|
def self.delete_expired_brouillons_and_notify
|
||||||
|
@ -65,8 +63,12 @@ class ExpiredDossiersDeletionService
|
||||||
dossiers.map(&:hash_for_deletion_mail),
|
dossiers.map(&:hash_for_deletion_mail),
|
||||||
user.email
|
user.email
|
||||||
).deliver_later
|
).deliver_later
|
||||||
|
|
||||||
|
# destroy dossiers from current notification
|
||||||
|
Dossier.where(id: dossiers).destroy_all
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# destroy dossiers without notification
|
||||||
dossiers_to_remove.destroy_all
|
dossiers_to_remove.destroy_all
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -80,7 +82,7 @@ class ExpiredDossiersDeletionService
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def self.send_expiration_notices(dossiers_close_to_expiration)
|
def self.send_expiration_notices(dossiers_close_to_expiration, close_to_expiration_flag)
|
||||||
dossiers_close_to_expiration
|
dossiers_close_to_expiration
|
||||||
.with_notifiable_procedure
|
.with_notifiable_procedure
|
||||||
.includes(:user)
|
.includes(:user)
|
||||||
|
@ -97,7 +99,13 @@ class ExpiredDossiersDeletionService
|
||||||
dossiers.to_a,
|
dossiers.to_a,
|
||||||
email
|
email
|
||||||
).deliver_later
|
).deliver_later
|
||||||
|
|
||||||
|
# mark as sent dossiers from current notification
|
||||||
|
Dossier.where(id: dossiers.to_a).update_all(close_to_expiration_flag => Time.zone.now)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# mark as sent dossiers without notification
|
||||||
|
dossiers_close_to_expiration.update_all(close_to_expiration_flag => Time.zone.now)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.delete_expired_and_notify(dossiers_to_remove)
|
def self.delete_expired_and_notify(dossiers_to_remove)
|
||||||
|
@ -119,8 +127,12 @@ class ExpiredDossiersDeletionService
|
||||||
DeletedDossier.where(dossier_id: dossiers.map(&:id)),
|
DeletedDossier.where(dossier_id: dossiers.map(&:id)),
|
||||||
email
|
email
|
||||||
).deliver_later
|
).deliver_later
|
||||||
|
|
||||||
|
# destroy dossiers from current notification
|
||||||
|
Dossier.where(id: dossiers.to_a).destroy_all
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# destroy dossiers without notification
|
||||||
dossiers_to_remove.destroy_all
|
dossiers_to_remove.destroy_all
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue