Merge pull request #4830 from betagouv/dev

2020-02-25-02
This commit is contained in:
Pierre de La Morinerie 2020-02-25 15:46:31 +01:00 committed by GitHub
commit 32442ae00c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 25 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

@ -295,6 +295,7 @@ class Procedure < ApplicationRecord
procedure.cloned_from_library = from_library
procedure.parent_procedure = self
procedure.canonical_procedure = nil
if from_library
procedure.service = nil

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!

View file

@ -538,6 +538,15 @@ describe Procedure do
expect(subject.deliberation.attached?).to be true
end
end
context 'with canonical procedure' do
let(:canonical_procedure) { create(:procedure) }
let(:procedure) { create(:procedure, canonical_procedure: canonical_procedure, received_mail: received_mail, service: service) }
it 'do not clone canonical procedure' do
expect(subject.canonical_procedure).to be_nil
end
end
end
describe '#publish!' do