tech(review): quelques améliorations de style
This commit is contained in:
parent
e99f9b5c17
commit
3a9b520a93
2 changed files with 15 additions and 15 deletions
|
@ -3,9 +3,9 @@ class Expired::UsersDeletionService < Expired::MailRateLimiter
|
|||
# we are working on two dataset because we apply two incompatible join on the same query
|
||||
# inner join on users not having dossier.en_instruction [so we do not destroy users with dossiers.en_instruction]
|
||||
# outer join on users not having dossier at all [so we destroy users without dossiers]
|
||||
[expiring_users_without_dossiers, expiring_users_with_dossiers].each do |expiring_segment|
|
||||
delete_expired_users(expiring_segment)
|
||||
send_inactive_close_to_expiration_notice(expiring_segment)
|
||||
[expired_users_without_dossiers, expired_users_with_dossiers].each do |expired_segment|
|
||||
delete_notified_users(expired_segment)
|
||||
send_inactive_close_to_expiration_notice(expired_segment)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -20,8 +20,8 @@ class Expired::UsersDeletionService < Expired::MailRateLimiter
|
|||
end
|
||||
end
|
||||
|
||||
def delete_expired_users(users)
|
||||
to_delete_only(users).find_each do |user|
|
||||
def delete_notified_users(users)
|
||||
only_notified(users).find_each do |user|
|
||||
begin
|
||||
user.delete_and_keep_track_dossiers_also_delete_user(nil)
|
||||
rescue => e
|
||||
|
@ -31,11 +31,11 @@ class Expired::UsersDeletionService < Expired::MailRateLimiter
|
|||
end
|
||||
|
||||
# rubocop:disable DS/Unscoped
|
||||
def expiring_users_with_dossiers
|
||||
def expired_users_with_dossiers
|
||||
users = User.arel_table
|
||||
dossiers = Dossier.arel_table
|
||||
|
||||
expiring_users
|
||||
expired_users
|
||||
.joins(
|
||||
users.join(dossiers, Arel::Nodes::InnerJoin)
|
||||
.on(users[:id].eq(dossiers[:user_id])
|
||||
|
@ -44,11 +44,11 @@ class Expired::UsersDeletionService < Expired::MailRateLimiter
|
|||
)
|
||||
end
|
||||
|
||||
def expiring_users_without_dossiers
|
||||
expiring_users.where.missing(:dossiers)
|
||||
def expired_users_without_dossiers
|
||||
expired_users.where.missing(:dossiers)
|
||||
end
|
||||
|
||||
def expiring_users
|
||||
def expired_users
|
||||
User.unscoped
|
||||
.where.missing(:expert, :instructeur, :administrateur)
|
||||
.where(last_sign_in_at: ..Expired::INACTIVE_USER_RETATION_IN_YEAR.years.ago)
|
||||
|
@ -60,7 +60,7 @@ class Expired::UsersDeletionService < Expired::MailRateLimiter
|
|||
.limit(daily_limit) # ensure to not send too much email
|
||||
end
|
||||
|
||||
def to_delete_only(users)
|
||||
def only_notified(users)
|
||||
users.where.not(inactive_close_to_expiration_notice_sent_at: Expired::REMAINING_WEEKS_BEFORE_EXPIRATION.weeks.ago..)
|
||||
.limit(daily_limit) # event if we do not send email, avoid to destroy 800k user in one batch
|
||||
end
|
||||
|
|
|
@ -114,9 +114,9 @@ describe Expired::UsersDeletionService do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#expiring_users_without_dossiers' do
|
||||
describe '#expired_users_without_dossiers' do
|
||||
let(:dossier) { nil }
|
||||
subject { Expired::UsersDeletionService.new.send(:expiring_users_without_dossiers) }
|
||||
subject { Expired::UsersDeletionService.new.send(:expired_users_without_dossiers) }
|
||||
|
||||
context 'when user last_sign_in_at is 1 year ago and has no dossier' do
|
||||
let(:user) { create(:user, last_sign_in_at: last_signed_in_not_expired) }
|
||||
|
@ -150,10 +150,10 @@ describe Expired::UsersDeletionService do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#expiring_users_with_dossiers' do
|
||||
describe '#expired_users_with_dossiers' do
|
||||
let(:user) { create(:user, last_sign_in_at: last_signed_in_expired) }
|
||||
let(:dossier) { create(:dossier, :brouillon, user:, created_at: last_signed_in_expired) }
|
||||
subject { Expired::UsersDeletionService.new.send(:expiring_users_with_dossiers) }
|
||||
subject { Expired::UsersDeletionService.new.send(:expired_users_with_dossiers) }
|
||||
|
||||
context 'when user is not expired' do
|
||||
let(:user) { create(:user, last_sign_in_at: last_signed_in_not_expired) }
|
||||
|
|
Loading…
Add table
Reference in a new issue