feat(user): always allow devise mail

This commit is contained in:
simon lehericey 2024-05-29 09:52:54 +02:00
parent 607fbf5287
commit 8104157da6
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5
4 changed files with 17 additions and 5 deletions

View file

@ -8,6 +8,10 @@ module BalancedDeliveryConcern
self.class.critical_email?(action_name) self.class.critical_email?(action_name)
end end
def bypass_unverified_mail_protection!
headers[BalancerDeliveryMethod::BYPASS_UNVERIFIED_MAIL_PROTECTION] = true
end
private private
def forced_delivery_provider? def forced_delivery_provider?

View file

@ -34,6 +34,8 @@ class DeviseUserMailer < Devise::Mailer
@procedure = opts[:procedure_after_confirmation] || nil @procedure = opts[:procedure_after_confirmation] || nil
@prefill_token = opts[:prefill_token] @prefill_token = opts[:prefill_token]
bypass_unverified_mail_protection!
I18n.with_locale(record.locale) do I18n.with_locale(record.locale) do
super super
end end

View file

@ -1,20 +1,23 @@
RSpec.describe BalancerDeliveryMethod do RSpec.describe BalancerDeliveryMethod do
class ExampleMailer < ApplicationMailer class ExampleMailer < ApplicationMailer
include BalancedDeliveryConcern
def greet(name, bypass_unverified_mail_protection: true) def greet(name, bypass_unverified_mail_protection: true)
mail(to: name, from: "smtp_from", body: "Hello #{name}") mail(to: name, from: "smtp_from", body: "Hello #{name}")
if bypass_unverified_mail_protection bypass_unverified_mail_protection! if bypass_unverified_mail_protection
headers['BYPASS_UNVERIFIED_MAIL_PROTECTION'] = true
end
end end
end end
class ImportantEmail < ApplicationMailer class ImportantEmail < ApplicationMailer
include BalancedDeliveryConcern
before_action :set_x_deliver_with before_action :set_x_deliver_with
def greet(name) def greet(name)
mail(to: name, from: "smtp_from", body: "Hello #{name}") mail(to: name, from: "smtp_from", body: "Hello #{name}")
headers['BYPASS_UNVERIFIED_MAIL_PROTECTION'] = true
bypass_unverified_mail_protection!
end end
private private

View file

@ -5,7 +5,10 @@ RSpec.describe DeviseUserMailer, type: :mailer do
subject { described_class.confirmation_instructions(user, token, opts = {}) } subject { described_class.confirmation_instructions(user, token, opts = {}) }
context 'without SafeMailer configured' do context 'without SafeMailer configured' do
it { expect(subject[BalancerDeliveryMethod::FORCE_DELIVERY_METHOD_HEADER]&.value).to eq(nil) } it do
expect(subject[BalancerDeliveryMethod::FORCE_DELIVERY_METHOD_HEADER]&.value).to eq(nil)
expect(subject[BalancerDeliveryMethod::BYPASS_UNVERIFIED_MAIL_PROTECTION]).to be_present
end
end end
context 'with SafeMailer configured' do context 'with SafeMailer configured' do