Merge pull request #10472 from demarches-simplifiees/block_dubious_email_adresse

Tech: block l'envoi de mails à des adresses douteuses
This commit is contained in:
LeSim 2024-05-31 08:32:43 +00:00 committed by GitHub
commit abd2dae7a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 84 additions and 0 deletions

View 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

View file

@ -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