mailers: fix procedure_after_confirmation in the confirmation email

As mailers are run asynchronously, they don't have access to the
CurrentConfirmation defined in an earlier request.

For the procedure_after_confirmation to be serialized to the Mailer,
we need to pass it at creation time.
This commit is contained in:
Pierre de La Morinerie 2020-02-25 15:12:09 +01:00
parent 9ad56d8e9b
commit 8eb6dd78a1
2 changed files with 15 additions and 1 deletions

View file

@ -15,7 +15,7 @@ class DeviseUserMailer < Devise::Mailer
def confirmation_instructions(record, token, opts = {})
opts[:from] = NO_REPLY_EMAIL
@procedure = CurrentConfirmation.procedure_after_confirmation || nil
@procedure = opts[:procedure_after_confirmation] || nil
super
end
end

View file

@ -25,6 +25,20 @@ class User < ApplicationRecord
before_validation -> { sanitize_email(:email) }
# Override of Devise::Models::Confirmable#send_confirmation_instructions
def send_confirmation_instructions
unless @raw_confirmation_token
generate_confirmation_token!
end
opts = pending_reconfirmation? ? { to: unconfirmed_email } : {}
# Make our procedure_after_confirmation available to the Mailer
opts[:procedure_after_confirmation] = CurrentConfirmation.procedure_after_confirmation
send_devise_notification(:confirmation_instructions, @raw_confirmation_token, opts)
end
# Callback provided by Devise
def after_confirmation
link_invites!