tech: block dubious emails address
This commit is contained in:
parent
f2b3ffed5a
commit
14294af5dc
2 changed files with 84 additions and 0 deletions
27
lib/tasks/deployment/20240530090353_block_dubious_email.rake
Normal file
27
lib/tasks/deployment/20240530090353_block_dubious_email.rake
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
namespace :after_party do
|
||||||
|
desc 'Deployment task: block_dubious_email'
|
||||||
|
task block_dubious_email: :environment do
|
||||||
|
User
|
||||||
|
.where.associated(:instructeur)
|
||||||
|
.where(created_at: ..3.months.ago)
|
||||||
|
.where(last_sign_in_at: nil)
|
||||||
|
.update_all(email_verified_at: nil)
|
||||||
|
|
||||||
|
User
|
||||||
|
.where.associated(:expert)
|
||||||
|
.where(created_at: ..3.months.ago)
|
||||||
|
.where(last_sign_in_at: nil)
|
||||||
|
.update_all(email_verified_at: nil)
|
||||||
|
|
||||||
|
# rubocop:disable DS/Unscoped
|
||||||
|
User
|
||||||
|
.unscoped
|
||||||
|
.where.missing(:instructeur, :expert)
|
||||||
|
.where(confirmed_at: nil)
|
||||||
|
.update_all(email_verified_at: nil)
|
||||||
|
# rubocop:enable DS/Unscoped
|
||||||
|
|
||||||
|
AfterParty::TaskRecord
|
||||||
|
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,57 @@
|
||||||
|
describe '20240530090353_block_dubious_email' do
|
||||||
|
let(:rake_task) { Rake::Task['after_party:block_dubious_email'] }
|
||||||
|
let(:now) { Time.current }
|
||||||
|
let(:confirmed_user) { create(:user, email_verified_at: now, created_at: 1.year.ago) }
|
||||||
|
let(:unconfirmed_user) { create(:user, email_verified_at: now, created_at: 1.year.ago, confirmed_at: nil) }
|
||||||
|
|
||||||
|
let(:never_seen_instructeur) do
|
||||||
|
instructeur = create(:instructeur)
|
||||||
|
instructeur.user.update!(email_verified_at: now, created_at: 1.year.ago)
|
||||||
|
instructeur.user
|
||||||
|
end
|
||||||
|
let(:seen_instructeur) do
|
||||||
|
instructeur = create(:instructeur)
|
||||||
|
instructeur.user.update!(
|
||||||
|
email_verified_at: now,
|
||||||
|
created_at: 1.year.ago,
|
||||||
|
last_sign_in_at: now
|
||||||
|
)
|
||||||
|
instructeur.user
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:young_never_seen_instructeur) do
|
||||||
|
instructeur = create(:instructeur)
|
||||||
|
instructeur.user.update!(
|
||||||
|
email_verified_at: now,
|
||||||
|
created_at: 2.months.ago,
|
||||||
|
confirmed_at: nil
|
||||||
|
)
|
||||||
|
instructeur.user
|
||||||
|
end
|
||||||
|
|
||||||
|
subject(:run_task) { rake_task.invoke }
|
||||||
|
|
||||||
|
after { rake_task.reenable }
|
||||||
|
|
||||||
|
it 'block_dubious_email' do
|
||||||
|
people = [
|
||||||
|
confirmed_user,
|
||||||
|
unconfirmed_user,
|
||||||
|
never_seen_instructeur,
|
||||||
|
young_never_seen_instructeur,
|
||||||
|
seen_instructeur
|
||||||
|
]
|
||||||
|
|
||||||
|
expect(people.map(&:email_verified_at)).to all(be_present)
|
||||||
|
|
||||||
|
run_task
|
||||||
|
people.each(&:reload)
|
||||||
|
|
||||||
|
expect(confirmed_user.email_verified_at).to be_present
|
||||||
|
expect(seen_instructeur.email_verified_at).to be_present
|
||||||
|
expect(young_never_seen_instructeur.email_verified_at).to be_present
|
||||||
|
|
||||||
|
expect(never_seen_instructeur.email_verified_at).to be_nil
|
||||||
|
expect(unconfirmed_user.email_verified_at).to be_nil
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue