fallback to using default product name

when a pseudonym is not found for an email we don't have the account to
load the product name, this is set to 'Canvas' for most accounts. This
will allow the email to still send instead of error, but might not be
accurate

test plan
 - in console make a user that is unregistered
 - make a unconfirmed communication_channel for the user
 - it should send an email to it

fixes KNO-474
flag=none

Change-Id: I1855993a07a4edd4ba8d523df7efb29d128eef4d
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/237933
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Drake Harper <drake.harper@instructure.com>
QA-Review: Drake Harper <drake.harper@instructure.com>
Product-Review: Drake Harper <drake.harper@instructure.com>
This commit is contained in:
Rob Orton 2020-05-19 15:29:28 -06:00
parent 82e495f426
commit e676f78d34
3 changed files with 19 additions and 11 deletions

View File

@ -1,6 +1,6 @@
<% p = asset.is_a?(Pseudonym) ? asset : (asset.pseudonym || asset.user.pseudonym) %>
<% a = p.account %>
<% product_name = a.product_name %>
<% a = p&.account %>
<% product_name = a&.product_name || I18n.t('Canvas') %>
<% cc = asset.is_a?(CommunicationChannel) ? asset : (p.communication_channel || p.user.communication_channel) %>
<% define_content :link do %>
<%= registration_confirmation_url(cc.confirmation_code) %>
@ -14,7 +14,7 @@
"Thank you for registering with %{product_name}! This email is confirmation that the user %{user} is registering for a new account at %{website}.",
:product_name => product_name,
:user => asset.user.short_name,
:website => (HostUrl.context_host((p.account rescue nil)) || HostUrl.default_host) %>
:website => (HostUrl.context_host(p&.account) || HostUrl.default_host) %>
<%= t :details, "To finish the registration process, please visit the following url:" %>
<%= content :link %>

View File

@ -1,6 +1,6 @@
<% p = asset.is_a?(Pseudonym) ? asset : (asset.pseudonym || asset.user.pseudonym) %>
<% a = p.account %>
<% product_name = a.product_name || "Canvas" %>
<% a = p&.account %>
<% product_name = a&.product_name || I18n.t('Canvas') %>
<% cc = asset.is_a?(CommunicationChannel) ? asset : (p.communication_channel || p.user.communication_channel) %>
<% define_content :link do %>
@ -19,4 +19,4 @@
"Thank you for registering with %{product_name}! This email is confirmation that the user %{user} is registering for a new account at %{website}.",
:product_name => product_name,
:user => asset.user.short_name,
:website => (HostUrl.context_host((p.account rescue nil)) || HostUrl.default_host) %></p>
:website => (HostUrl.context_host(p&.account) || HostUrl.default_host) %></p>

View File

@ -22,16 +22,24 @@ require File.expand_path(File.dirname(__FILE__) + '/messages_helper')
describe 'confirm_registration' do
before :once do
user_factory
@pseudonym = @user.pseudonyms.create!(unique_id: 'unique@example.com',
password: 'password',
password_confirmation: 'password')
@object = @user.communication_channels.create!(path_type: 'email',
path: 'bob@example.com',
user: @user)
end
let(:asset) { @object }
let(:notification_name) { :confirm_registration }
include_examples "a message"
context 'with_pseudonym' do
before :once do
@pseudonym = @user.pseudonyms.create!(unique_id: 'unique@example.com',
password: 'password',
password_confirmation: 'password')
end
include_examples "a message"
end
context 'without_pseudonym' do
include_examples "a message"
end
end