[15 Minute Fix]: Update email footer copy to account for email authentication (#12877)

* Update email footer copy to account for email authentication

Fixes https://github.com/forem/forem/issues/12546.
This commit is contained in:
Vaidehi Joshi 2021-03-03 08:36:40 -08:00 committed by GitHub
parent 3f3d7e8707
commit 7e583be9ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 27 deletions

View file

@ -23,6 +23,16 @@ module AuthenticationHelper
Authentication::Providers.enabled_for_user(user)
end
def signed_up_with(user = current_user)
providers = Authentication::Providers.enabled_for_user(user)
# If the user did not authenticate with any provider, they signed up with an email.
auth_method = providers.any? ? providers.map(&:official_name).to_sentence : "Email & Password"
verb = providers.size > 1 ? "any of those" : "that"
"Reminder: you used #{auth_method} to authenticate your account, so please use #{verb} to sign in if prompted."
end
def available_providers_array
Authentication::Providers.available.map(&:to_s)
end

View file

@ -1,30 +1,29 @@
<html>
<body style='font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, sans-serif;'>
<table style="width:100%;max-width:700px;margin:auto;font-size:18px">
<tr>
<td style="padding:4%;">
<%= yield %>
</td>
</tr>
<% if @user %>
<tr>
<td style="padding:3% 12% 2% 4%;font-size:18px;line-height:22px;color:#7d7d7d">
<% providers = authentication_enabled_providers_for_user(@user).map(&:official_name) %>
Reminder: You used <b><%= providers.to_sentence %></b> to authenticate your account, so use <%= providers.size == 1 ? "that" : "any of those" %> to sign in if prompted.
<body style='font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, sans-serif;'>
<table style="width:100%;max-width:700px;margin:auto;font-size:18px">
<tr>
<td style="padding:4%;">
<%= yield %>
</td>
</tr>
<% if @user %>
<tr>
<td style="padding:3% 12% 2% 4%;font-size:18px;line-height:22px;color:#7d7d7d">
<%= signed_up_with(@user) %>
<br /><br />
<div style="font-size:0.78em">
<% if @unsubscribe %>
<%= link_to "Unsubscribe", email_subscriptions_unsubscribe_url(ut: @unsubscribe), style: "color:#7d7d7d" %> |
<a href="<%= app_url(user_settings_path(:notifications)) %>" style="color:#7d7d7d">Adjust your email settings</a>
<% else %>
Don't want to get emails like this? Adjust your email settings at
<a href="<%= app_url(user_settings_path(:notifications)) %>"><%= app_url(user_settings_path(:notifications)) %></a>
<% end %>
</div>
</td>
</tr>
<% end %>
</table>
</body>
<br /><br />
<div style="font-size:0.78em">
<% if @unsubscribe %>
<%= link_to "Unsubscribe", email_subscriptions_unsubscribe_url(ut: @unsubscribe), style: "color:#7d7d7d" %> |
<a href="<%= app_url(user_settings_path(:notifications)) %>" style="color:#7d7d7d">Adjust your email settings</a>
<% else %>
Don't want to get emails like this? Adjust your email settings at
<a href="<%= app_url(user_settings_path(:notifications)) %>"><%= app_url(user_settings_path(:notifications)) %></a>
<% end %>
</div>
</td>
</tr>
<% end %>
</table>
</body>
</html>

View file

@ -28,6 +28,24 @@ RSpec.describe AuthenticationHelper, type: :helper do
end
end
describe "#signed_up_with" do
it "returns an authentication reminder when a user auths with a provider" do
providers = Authentication::Providers.available.last(2)
allow(Authentication::Providers).to receive(:enabled).and_return(providers)
allow(user).to receive(:identities).and_return(user.identities.where(provider: providers))
expect(helper.signed_up_with(user)).to match(/GitHub and Twitter/)
expect(helper.signed_up_with(user)).to match(/use any of those/)
end
it "returns an authentication reminder when a user signs up with email" do
allow(Authentication::Providers).to receive(:enabled).and_return([])
expect(helper.signed_up_with(user)).to match(/Email & Password/)
expect(helper.signed_up_with(user)).to match(/use that/)
end
end
describe "#available_providers_array" do
it "returns array of available providers in lowercase" do
provider = Authentication::Providers.available.first