amelioration(User.mailer.notify_inactive_close_to_deletion): ajoute le mail pour prevenir de la suppression de compte

This commit is contained in:
Martin 2023-11-03 10:39:41 +01:00 committed by mfo
parent ea9c571a30
commit 2f28012324
5 changed files with 52 additions and 3 deletions

View file

@ -67,7 +67,19 @@ class UserMailer < ApplicationMailer
mail(to: administrateur_or_instructeur.email, subject: subject)
end
def notify_inactive_close_to_deletion(user)
@user = user
@subject = "Votre compte sera supprimé dans #{ExpiredUsersDeletionService::RETENTION_AFTER_NOTICE_IN_WEEK} semaines"
mail(to: user.email, subject: @subject)
end
def self.critical_email?(action_name)
['france_connect_merge_confirmation', "new_account_warning", "ask_for_merge", "invite_instructeur"].include?(action_name)
[
'france_connect_merge_confirmation',
"new_account_warning",
"ask_for_merge",
"invite_instructeur"
].include?(action_name)
end
end

View file

@ -1,5 +1,5 @@
class ExpiredUsersDeletionService
RETENTION_AFTER_NOTICE = 2.weeks
RETENTION_AFTER_NOTICE_IN_WEEK = 2
def self.process_expired
delete_expired_users
@ -35,6 +35,6 @@ class ExpiredUsersDeletionService
end
def self.expiring_user_notified
expiring_users.where.not(inactive_close_to_expiration_notice_sent_at: RETENTION_AFTER_NOTICE.ago..)
expiring_users.where.not(inactive_close_to_expiration_notice_sent_at: RETENTION_AFTER_NOTICE_IN_WEEK.weeks.ago..)
end
end

View file

@ -0,0 +1,18 @@
- content_for(:title, @subject)
%p
Bonjour,
%p
Cela fait plus de deux ans que vous ne vous êtes pas connecté à #{APPLICATION_NAME}.
%br
Dans le respect du RGPD, nous allons
%strong supprimer votre compte d'ici #{distance_of_time_in_words(ExpiredUsersDeletionService::RETENTION_AFTER_NOTICE_IN_WEEK.weeks)}.
%p
%strong Ne vous en faites pas,
vos dossiers restent conservé par l'administration. À tout moment vous pourrez re-créer une compte sur notre plateforme.
%br
Mais dans l'attente, nous tenons a respecter le RGPD et protéger ainsi votre vie privée.
= render partial: "layouts/mailers/signature"

View file

@ -29,6 +29,10 @@ class UserMailerPreview < ActionMailer::Preview
UserMailer.invite_gestionnaire(user, 'aedfa0d0', groupe_gestionnaire)
end
def notify_inactive_close_to_deletion
UserMailer.notify_inactive_close_to_deletion(user)
end
private
def user

View file

@ -112,4 +112,19 @@ RSpec.describe UserMailer, type: :mailer do
end
end
end
describe '.notify_inactive_close_to_deletion' do
subject { described_class.notify_inactive_close_to_deletion(user) }
it { expect(subject.to).to eq([user.email]) }
it { expect(subject.body).to include("Cela fait plus de deux ans que vous ne vous êtes pas connecté à #{APPLICATION_NAME}.") }
context 'when perform_later is called' do
let(:custom_queue) { 'low_priority' }
before { ENV['BULK_EMAIL_QUEUE'] = custom_queue }
it 'enqueues email is custom queue for low priority delivery' do
expect { subject.deliver_later }.to have_enqueued_job.on_queue(custom_queue)
end
end
end
end