[Fix #1799] Send automatic emails to improve administrateur activation
This commit is contained in:
parent
2f8206edd5
commit
f6d53be873
5 changed files with 114 additions and 0 deletions
|
@ -0,0 +1,9 @@
|
|||
class Administrateurs::ActivateBeforeExpirationJob < ApplicationJob
|
||||
queue_as :cron
|
||||
|
||||
def perform(*args)
|
||||
Administrateur.inactive.where(created_at: 2.days.ago.all_day).each do |a|
|
||||
AdministrateurMailer.activate_before_expiration(a).deliver_later
|
||||
end
|
||||
end
|
||||
end
|
11
app/mailers/administrateur_mailer.rb
Normal file
11
app/mailers/administrateur_mailer.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
class AdministrateurMailer < ApplicationMailer
|
||||
layout 'mailers/layout'
|
||||
|
||||
def activate_before_expiration(administrateur)
|
||||
@administrateur = administrateur
|
||||
@expiration_date = administrateur.reset_password_sent_at + Devise.reset_password_within
|
||||
mail(to: administrateur.email,
|
||||
subject: "demarches-simplifiees.fr - N'oubliez pas d'activer votre compte administrateur",
|
||||
reply_to: "contact@demarches-simplifiees.fr")
|
||||
end
|
||||
end
|
|
@ -0,0 +1,17 @@
|
|||
- content_for(:title, "N'oubliez pas d'activer votre compte")
|
||||
|
||||
Bonjour,
|
||||
%br
|
||||
%br
|
||||
Vous avez fait la demande d’un compte administrateur sur demarches-simplifiees.fr.
|
||||
Votre compte a été créé mais reste inactif, il arrivera à expiration le #{@expiration_date.strftime("%d/%m/%Y")}
|
||||
%br
|
||||
%br
|
||||
Afin d’activer votre compte, veuillez cliquer sur le lien ci-dessous :
|
||||
= link_to(admin_activate_url(token: @administrateur.reset_password_token), admin_activate_url(token: @administrateur.reset_password_token))
|
||||
%br
|
||||
%br
|
||||
Nous restons à votre disposition si vous avez besoin d’accompagnement.
|
||||
%br
|
||||
%br
|
||||
= render partial: "layouts/mailers/bizdev_signature"
|
|
@ -0,0 +1,72 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Administrateurs::ActivateBeforeExpirationJob, type: :job do
|
||||
describe 'perform' do
|
||||
let(:administrateur) { create(:administrateur, active: active) }
|
||||
let(:mailer_double) { double('mailer', deliver_later: true) }
|
||||
|
||||
subject { Administrateurs::ActivateBeforeExpirationJob.perform_now }
|
||||
|
||||
before do
|
||||
Timecop.freeze(DateTime.new(2018, 03, 20))
|
||||
administrateur.reload
|
||||
allow(AdministrateurMailer).to receive(:activate_before_expiration).and_return(mailer_double)
|
||||
end
|
||||
|
||||
after { Timecop.return }
|
||||
|
||||
context "with an inactive administrateur" do
|
||||
let(:active) { false }
|
||||
|
||||
context "created now" do
|
||||
before { subject }
|
||||
it { expect(AdministrateurMailer).not_to have_received(:activate_before_expiration) }
|
||||
end
|
||||
|
||||
context "created a long time ago" do
|
||||
before do
|
||||
administrateur.update_columns(created_at: DateTime.new(2018, 03, 10))
|
||||
subject
|
||||
end
|
||||
|
||||
it { expect(AdministrateurMailer).not_to have_received(:activate_before_expiration) }
|
||||
end
|
||||
|
||||
context "created 2 days ago" do
|
||||
before do
|
||||
administrateur.update_columns(created_at: DateTime.new(2018, 03, 18, 20, 00))
|
||||
subject
|
||||
end
|
||||
|
||||
it { expect(AdministrateurMailer).to have_received(:activate_before_expiration).with(administrateur) }
|
||||
end
|
||||
end
|
||||
|
||||
context "with an active administrateur" do
|
||||
let(:active) { true }
|
||||
|
||||
context "created now" do
|
||||
before { subject }
|
||||
it { expect(AdministrateurMailer).not_to have_received(:activate_before_expiration) }
|
||||
end
|
||||
|
||||
context "created a long time ago" do
|
||||
before do
|
||||
administrateur.update_columns(created_at: DateTime.new(2018, 03, 10))
|
||||
subject
|
||||
end
|
||||
|
||||
it { expect(AdministrateurMailer).not_to have_received(:activate_before_expiration) }
|
||||
end
|
||||
|
||||
context "created 2 days ago" do
|
||||
before do
|
||||
administrateur.update_columns(created_at: DateTime.new(2018, 03, 18, 20, 00))
|
||||
subject
|
||||
end
|
||||
|
||||
it { expect(AdministrateurMailer).not_to have_received(:activate_before_expiration) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
5
spec/mailers/previews/administrateur_mailer_preview.rb
Normal file
5
spec/mailers/previews/administrateur_mailer_preview.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class AdministrateurMailerPreview < ActionMailer::Preview
|
||||
def activate_before_expiration
|
||||
AdministrateurMailer.activate_before_expiration(Administrateur.inactive.where.not(reset_password_token: nil).last)
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue