-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
amelioration(users.expiration): notifie deux semaine a l'avance avant…
… de supprimer un compte
- Loading branch information
Martin
committed
Nov 3, 2023
1 parent
636d767
commit ff02e33
Showing
2 changed files
with
62 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,38 @@ | ||
class ExpiredUsersDeletionService | ||
RETENTION_AFTER_NOTICE = 2.weeks | ||
|
||
def self.process_expired | ||
users = find_expired_user | ||
users.find_each do |user| | ||
delete_expired_users | ||
send_inactive_close_to_expiration_notice | ||
end | ||
|
||
def self.send_inactive_close_to_expiration_notice | ||
expiring_users_to_notify.in_batches do |batch| | ||
batch.each do |user| | ||
UserMailer.notify_inactive_close_to_deletion(user).perform_later | ||
end | ||
batch.update_all(inactive_close_to_expiration_notice_sent_at: Time.zone.now.utc) | ||
end | ||
end | ||
|
||
def self.delete_expired_users | ||
expiring_user_notified.find_each do |user| | ||
user.delete_and_keep_track_dossiers_also_delete_user(nil) | ||
end | ||
end | ||
|
||
def self.find_expired_user | ||
def self.expiring_users | ||
User.unscoped # avoid default_scope eager_loading :export, :instructeur, :administrateur | ||
.joins(:dossiers) | ||
.having('MAX(dossiers.created_at) < ?', 2.years.ago) | ||
.group('users.id') | ||
end | ||
|
||
def self.expiring_users_to_notify | ||
expiring_users.where(inactive_close_to_expiration_notice_sent_at: nil) | ||
end | ||
|
||
def self.expiring_user_notified | ||
expiring_users.where.not(inactive_close_to_expiration_notice_sent_at: RETENTION_AFTER_NOTICE.ago..) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters