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)
end
def bypass_unverified_mail_protection!
headers[BalancerDeliveryMethod::BYPASS_UNVERIFIED_MAIL_PROTECTION] = true
end
private
def forced_delivery_provider?

View file

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

View file

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

View file

@ -5,7 +5,10 @@ RSpec.describe DeviseUserMailer, type: :mailer do
subject { described_class.confirmation_instructions(user, token, opts = {}) }
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
context 'with SafeMailer configured' do