feat(token depreciation): add mail alert
This commit is contained in:
parent
9ae4dbd4af
commit
ca63cc34ab
4 changed files with 49 additions and 0 deletions
|
@ -22,6 +22,15 @@ class AdministrateurMailer < ApplicationMailer
|
||||||
reply_to: CONTACT_EMAIL)
|
reply_to: CONTACT_EMAIL)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def api_token_expiration(user, tokens)
|
||||||
|
@subject = "Renouvellement de jeton d'API nécessaire"
|
||||||
|
@tokens = tokens
|
||||||
|
|
||||||
|
mail(to: user.email,
|
||||||
|
subject: @subject,
|
||||||
|
reply_to: CONTACT_EMAIL)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def forced_delivery_for_action?
|
def forced_delivery_for_action?
|
||||||
|
|
19
app/views/administrateur_mailer/api_token_expiration.haml
Normal file
19
app/views/administrateur_mailer/api_token_expiration.haml
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
- content_for(:title, @subject)
|
||||||
|
|
||||||
|
%p
|
||||||
|
Bonjour,
|
||||||
|
|
||||||
|
%p
|
||||||
|
- if @tokens.one?
|
||||||
|
<b>Votre jeton d'API « #{@tokens.first.prefix} » expirera le 1er juillet 2023</b>.
|
||||||
|
- else
|
||||||
|
<b>Vos jetons d'API « #{@tokens.map(&:prefix).join(', ')} » expireront le 1er juillet 2023</b>.
|
||||||
|
Passée cette date, vos interconnexions utilisant ce jeton ne marcheront plus.
|
||||||
|
|
||||||
|
%p
|
||||||
|
Vous devrez le(s) remplacer par de nouveaux jetons que vous pouvez obtenir en utilisant la page #{link_to(profil_url, profil_url)}.
|
||||||
|
|
||||||
|
%p
|
||||||
|
Nous restons à votre disposition si vous avez besoin d’accompagnement à l'adresse #{link_to CONTACT_EMAIL, "mailto:#{CONTACT_EMAIL}"}.
|
||||||
|
|
||||||
|
= render partial: "layouts/mailers/signature"
|
15
lib/tasks/token_expiration_email.rake
Normal file
15
lib/tasks/token_expiration_email.rake
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
require Rails.root.join("lib", "tasks", "task_helper")
|
||||||
|
|
||||||
|
namespace :token_expiration_email do
|
||||||
|
task send_warning: :environment do
|
||||||
|
admin_tokens = APIToken
|
||||||
|
.includes(:administrateur)
|
||||||
|
.where(version: [1, 2])
|
||||||
|
.to_a
|
||||||
|
.group_by(&:administrateur)
|
||||||
|
|
||||||
|
admin_tokens.each do |admin, tokens|
|
||||||
|
AdministrateurMailer.api_token_expiration(admin.user, tokens).deliver_later
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,4 +10,10 @@ class AdministrateurMailerPreview < ActionMailer::Preview
|
||||||
procedure = Procedure.first
|
procedure = Procedure.first
|
||||||
AdministrateurMailer.notify_procedure_expires_when_termine_forced(email, procedure)
|
AdministrateurMailer.notify_procedure_expires_when_termine_forced(email, procedure)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def api_token_expiration
|
||||||
|
user = User.last
|
||||||
|
tokens = [APIToken.last, APIToken.last]
|
||||||
|
AdministrateurMailer.api_token_expiration(user, tokens)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue