amelioration(mail.prioritaire): en plus des mails de device, ajoute la gestion du routage des autres mails critique

This commit is contained in:
Martin 2023-01-23 14:56:05 +01:00 committed by mfo
parent e6b29af2ac
commit 4990c448b1
11 changed files with 118 additions and 7 deletions

View file

@ -21,4 +21,10 @@ class AdministrateurMailer < ApplicationMailer
subject: @subject,
reply_to: CONTACT_EMAIL)
end
private
def forced_delivery_for_action?
action_name == "activate_before_expiration"
end
end

View file

@ -1,6 +1,7 @@
class ApplicationMailer < ActionMailer::Base
include MailerDolistConcern
include MailerMonitoringConcern
include BalancedDeliveryConcern
helper :application # gives access to all helpers defined within `application_helper`.
default from: "#{APPLICATION_NAME} <#{CONTACT_EMAIL}>"

View file

@ -0,0 +1,21 @@
module BalancedDeliveryConcern
extend ActiveSupport::Concern
included do
before_action :add_delivery_method, if: :forced_delivery?
private
def forced_delivery_for_action?
false
end
def forced_delivery?
SafeMailer.forced_delivery_method.present? && forced_delivery_for_action?
end
def add_delivery_method
headers[BalancerDeliveryMethod::FORCE_DELIVERY_METHOD_HEADER] = SafeMailer.forced_delivery_method
end
end
end

View file

@ -5,8 +5,8 @@ class DeviseUserMailer < Devise::Mailer
include Devise::Controllers::UrlHelpers # Optional. eg. `confirmation_url`
include MailerDolistConcern
include MailerMonitoringConcern
include BalancedDeliveryConcern
layout 'mailers/layout'
before_action :add_delivery_method, if: :forced_delivery?
def template_paths
['devise_mailer']
@ -19,11 +19,7 @@ class DeviseUserMailer < Devise::Mailer
super
end
def add_delivery_method
headers[BalancerDeliveryMethod::FORCE_DELIVERY_METHOD_HEADER] = SafeMailer.forced_delivery_method
end
def forced_delivery?
SafeMailer.forced_delivery_method.present?
def forced_delivery_for_action?
true
end
end

View file

@ -44,4 +44,10 @@ class InstructeurMailer < ApplicationMailer
mail(to: instructeur.email, subject: subject)
end
private
def forced_delivery_for_action?
action_name == "send_login_token"
end
end

View file

@ -32,4 +32,8 @@ class InviteMailer < ApplicationMailer
subject: subject,
reply_to: reply_to)
end
def forced_delivery_for_action?
true
end
end

View file

@ -55,4 +55,8 @@ class UserMailer < ApplicationMailer
mail(to: administrateur_or_instructeur.email, subject: subject)
end
def forced_delivery_for_action?
['france_connect_merge_confirmation', "new_account_warning", "ask_for_merge", "invite_instructeur"].include?(action_name)
end
end

View file

@ -6,4 +6,20 @@ RSpec.describe AdministrateurMailer, type: :mailer do
it { expect(subject.to).to eq([admin_email]) }
it { expect(subject.subject).to include("La suppression automatique des dossiers a été activée sur la démarche") }
end
describe '.activate_before_expiration' do
let(:user) { create(:user, reset_password_sent_at: 2.days.ago) }
let(:token) { SecureRandom.hex }
context 'without SafeMailer configured' do
subject { described_class.activate_before_expiration(user, token) }
it { expect(subject[BalancerDeliveryMethod::FORCE_DELIVERY_METHOD_HEADER]&.value).to eq(nil) }
end
context 'with SafeMailer configured' do
let(:forced_delivery_method) { :kikoo }
before { allow(SafeMailer).to receive(:forced_delivery_method).and_return(forced_delivery_method) }
subject { described_class.activate_before_expiration(user, token) }
it { expect(subject[BalancerDeliveryMethod::FORCE_DELIVERY_METHOD_HEADER]&.value).to eq(forced_delivery_method.to_s) }
end
end
end

View file

@ -9,6 +9,23 @@ RSpec.describe InstructeurMailer, type: :mailer do
it { expect(subject.body).to include('Bonjour') }
end
describe '#send_login_token' do
let(:user) { create(:instructeur) }
let(:token) { SecureRandom.hex }
context 'without SafeMailer configured' do
subject { described_class.send_login_token(user, token) }
it { expect(subject[BalancerDeliveryMethod::FORCE_DELIVERY_METHOD_HEADER]&.value).to eq(nil) }
end
context 'with SafeMailer configured' do
let(:forced_delivery_method) { :kikoo }
before { allow(SafeMailer).to receive(:forced_delivery_method).and_return(forced_delivery_method) }
subject { described_class.send_login_token(user, token) }
it { expect(subject[BalancerDeliveryMethod::FORCE_DELIVERY_METHOD_HEADER]&.value).to eq(forced_delivery_method.to_s) }
end
end
describe '#last_week_overview' do
let(:instructeur) { create(:instructeur) }
let(:procedure) { create(:procedure, :published, instructeurs: [instructeur]) }

View file

@ -29,6 +29,16 @@ RSpec.describe InviteMailer, type: :mailer do
expect(TargetedUserLink.where(target_model: invite, user: invite.user).count).to eq(1)
end
end
context 'without SafeMailer configured' do
it { expect(mailer[BalancerDeliveryMethod::FORCE_DELIVERY_METHOD_HEADER]&.value).to eq(nil) }
end
context 'with SafeMailer configured' do
let(:forced_delivery_method) { :kikoo }
before { allow(SafeMailer).to receive(:forced_delivery_method).and_return(forced_delivery_method) }
it { expect(mailer[BalancerDeliveryMethod::FORCE_DELIVERY_METHOD_HEADER]&.value).to eq(forced_delivery_method.to_s) }
end
end
describe '.invite_guest' do

View file

@ -15,6 +15,16 @@ RSpec.describe UserMailer, type: :mailer do
it { expect(subject.body).to have_link("Commencer la démarche « #{procedure.libelle} »", href: commencer_sign_in_url(path: procedure.path)) }
end
context 'without SafeMailer configured' do
it { expect(subject[BalancerDeliveryMethod::FORCE_DELIVERY_METHOD_HEADER]&.value).to eq(nil) }
end
context 'with SafeMailer configured' do
let(:forced_delivery_method) { :kikoo }
before { allow(SafeMailer).to receive(:forced_delivery_method).and_return(forced_delivery_method) }
it { expect(subject[BalancerDeliveryMethod::FORCE_DELIVERY_METHOD_HEADER]&.value).to eq(forced_delivery_method.to_s) }
end
end
describe '.ask_for_merge' do
@ -24,6 +34,16 @@ RSpec.describe UserMailer, type: :mailer do
it { expect(subject.to).to eq([requested_email]) }
it { expect(subject.body).to include(requested_email) }
context 'without SafeMailer configured' do
it { expect(subject[BalancerDeliveryMethod::FORCE_DELIVERY_METHOD_HEADER]&.value).to eq(nil) }
end
context 'with SafeMailer configured' do
let(:forced_delivery_method) { :kikoo }
before { allow(SafeMailer).to receive(:forced_delivery_method).and_return(forced_delivery_method) }
it { expect(subject[BalancerDeliveryMethod::FORCE_DELIVERY_METHOD_HEADER]&.value).to eq(forced_delivery_method.to_s) }
end
end
describe '.france_connect_merge_confirmation' do
@ -34,6 +54,16 @@ RSpec.describe UserMailer, type: :mailer do
it { expect(subject.to).to eq([email]) }
it { expect(subject.body).to include(france_connect_particulier_mail_merge_with_existing_account_url(merge_token: code)) }
context 'without SafeMailer configured' do
it { expect(subject[BalancerDeliveryMethod::FORCE_DELIVERY_METHOD_HEADER]&.value).to eq(nil) }
end
context 'with SafeMailer configured' do
let(:forced_delivery_method) { :kikoo }
before { allow(SafeMailer).to receive(:forced_delivery_method).and_return(forced_delivery_method) }
it { expect(subject[BalancerDeliveryMethod::FORCE_DELIVERY_METHOD_HEADER]&.value).to eq(forced_delivery_method.to_s) }
end
end
describe '.send_archive' do