Skip to content

Commit 0410882

Browse files
authored
Update email auth to use a common OnRuby sender (#1079)
This way, we don't need to add each RUG's email address to the Sendgrid list of authorized senders
1 parent bbd7870 commit 0410882

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

app/controllers/concerns/with_email_auth.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ def email_login
1010
email = normalize_email(params[:email])
1111
if email.present? && valid_looking_email?(email)
1212
token = EmailAuthToken.generate(email)
13-
from = Whitelabel[:email]
1413
label_name = t("label.#{Whitelabel[:label_id]}.name")
1514
label_link = Whitelabel[:canonical_url]
16-
UserMailer.login_link(email, token, from, I18n.locale,
15+
UserMailer.login_link(email, token, I18n.locale,
1716
label_name, label_link).deliver_later
1817

1918
redirect_to root_path, notice: t('email_auth.email_sent', email:)

app/mailers/user_mailer.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
# Original author: https://github.com/phoet
55

66
class UserMailer < ApplicationMailer
7-
def login_link(email, token, from, locale, label_name, label_link) # rubocop:disable Metrics/ParameterLists
7+
COMMON_SENDER = '[email protected]'
8+
9+
def login_link(email, token, locale, label_name, label_link)
810
@token = token
9-
@from = from
1011
@label_name = label_name
1112
@label_link = label_link
1213

1314
I18n.with_locale(locale) do
14-
mail from: @from, to: email, subject: t('email_auth.subject', label: label_name)
15+
mail from: COMMON_SENDER, to: email,
16+
subject: t('email_auth.subject', label: label_name)
1517
end
1618
end
1719
end

spec/mailers/user_mailer_spec.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,19 @@
33
describe UserMailer do
44
describe '#login_link' do
55
subject(:mail) do
6-
described_class.login_link(email, token, from, locale, label_name, label_link).deliver_now
6+
described_class.login_link(email, token, locale, label_name, label_link).deliver_now
77
end
88

99
let(:email) { '[email protected]' }
1010
let(:token) { '12345678' }
11-
let(:from) { '[email protected]' }
1211
let(:locale) { :en }
1312
let(:label_name) { 'My RUG' }
1413
let(:label_link) { 'http://rug.org' }
1514

1615
it 'renders the headers' do
1716
expect(mail.subject).to eq('Login to My RUG')
1817
expect(mail.to).to eq([email])
19-
expect(mail.from).to eq([from])
18+
expect(mail.from).to eq([UserMailer::COMMON_SENDER])
2019
end
2120

2221
it 'renders the body' do

0 commit comments

Comments
 (0)