Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/controllers/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ def show
user: current_user,
locked_for_session: pii_locked_for_session?(current_user),
)
if session.delete(:from_select_email_flow)
flash.now[:success] = t(
'account.emails.confirmed_html',
url: account_connected_accounts_url,
)
end
end

def reauthentication
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/users/email_confirmations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def email_address_already_confirmed?

def process_successful_confirmation(email_address)
confirm_and_notify(email_address)
store_from_select_email_flow_in_session
if current_user
flash[:success] = t('devise.confirmations.confirmed')
redirect_to account_url
Expand Down Expand Up @@ -98,5 +99,9 @@ def email_address_already_confirmed_by_current_user?
def confirmation_params
params.permit(:confirmation_token)
end

def store_from_select_email_flow_in_session
session[:from_select_email_flow] = params[:from_select_email_flow].to_s == 'true'
end
end
end
17 changes: 13 additions & 4 deletions app/controllers/users/emails_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ class EmailsController < ApplicationController

def show
analytics.add_email_visit
session[:in_select_email_flow] = params[:in_select_email_flow]
@add_user_email_form = AddUserEmailForm.new
@pending_completions_consent = pending_completions_consent?
end

def add
@add_user_email_form = AddUserEmailForm.new
@add_user_email_form = AddUserEmailForm.new(
session[:in_select_email_flow],
)

result = @add_user_email_form.submit(current_user, permitted_params)
result = @add_user_email_form.submit(
current_user, permitted_params
)
analytics.add_email_request(**result.to_h)

if result.success?
Expand Down Expand Up @@ -71,7 +76,8 @@ def verify
if session_email.blank?
redirect_to add_email_url
else
render :verify, locals: { email: session_email }
render :verify,
locals: { email: session_email, in_select_email_flow: params[:in_select_email_flow] }
end
end

Expand All @@ -97,7 +103,10 @@ def process_successful_creation
resend_confirmation = params[:user][:resend]
session[:email] = @add_user_email_form.email

redirect_to add_email_verify_email_url(resend: resend_confirmation)
redirect_to add_email_verify_email_url(
resend: resend_confirmation,
in_select_email_flow: session.delete(:in_select_email_flow),
)
end

def session_email
Expand Down
8 changes: 6 additions & 2 deletions app/forms/add_user_email_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ class AddUserEmailForm
include FormAddEmailValidator
include ActionView::Helpers::TranslationHelper

attr_reader :email
attr_reader :email, :in_select_email_flow

def self.model_name
ActiveModel::Name.new(self, nil, 'User')
end

def initialize(in_select_email_flow = nil)
@in_select_email_flow = in_select_email_flow
end

def user
@user ||= User.new
end
Expand Down Expand Up @@ -47,7 +51,7 @@ def email_address_record(email)
def process_successful_submission
@success = true
email_address.save!
SendAddEmailConfirmation.new(user).call(email_address)
SendAddEmailConfirmation.new(user).call(email_address, in_select_email_flow)
end

def extra_analytics_attributes
Expand Down
3 changes: 2 additions & 1 deletion app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,14 @@ def verify_by_mail_letter_requested
end
end

def add_email(token)
def add_email(token, from_select_email_flow = nil)
with_user_locale(user) do
presenter = ConfirmationEmailPresenter.new(user, view_context)
@first_sentence = presenter.first_sentence
@confirmation_period = presenter.confirmation_period
@add_email_url = add_email_confirmation_url(
confirmation_token: token,
from_select_email_flow:,
locale: locale_url_param,
)
mail(to: email_address.email, subject: t('user_mailer.add_email.subject'))
Expand Down
6 changes: 4 additions & 2 deletions app/services/send_add_email_confirmation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ def initialize(user)
@user = user
end

def call(email_address)
def call(email_address, in_select_email_flow = nil)
@email_address = email_address
@in_select_email_flow = in_select_email_flow
update_email_address_record
send_email
end
Expand All @@ -23,7 +24,7 @@ def confirmation_sent_at
email_address.confirmation_sent_at
end

attr_reader :email_address
attr_reader :email_address, :in_select_email_flow

def update_email_address_record
email_address.update!(
Expand Down Expand Up @@ -59,6 +60,7 @@ def send_email_associated_with_another_account_email
def send_confirmation_email
UserMailer.with(user: user, email_address: email_address).add_email(
confirmation_token,
in_select_email_flow,
).deliver_now_or_later
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<% end %>

<%= render ButtonComponent.new(
url: add_email_path,
url: add_email_path(in_select_email_flow: true),
outline: true,
big: true,
wide: true,
Expand Down
2 changes: 1 addition & 1 deletion app/views/sign_up/completions/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<% if @presenter.multiple_emails? %>
<%= link_to t('help_text.requested_attributes.change_email_link'), sign_up_select_email_path %>
<% else %>
<%= link_to t('account.index.email_add'), add_email_path %>
<%= link_to t('account.index.email_add'), add_email_path(in_select_email_flow: true) %>
<% end %>
</p>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/sign_up/select_email/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<% end %>

<%= render ButtonComponent.new(
url: add_email_path,
url: add_email_path(in_select_email_flow: true),
outline: true,
big: true,
wide: true,
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/emails/verify.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<%= t('notices.signed_up_and_confirmed.no_email_sent_explanation_start') %>
<%= button_to(add_email_resend_path, method: :post, class: 'usa-button usa-button--unstyled', form_class: 'display-inline-block padding-left-1') { t('links.resend') } %>

<p><%= t('notices.use_diff_email.text_html', link_html: link_to(t('notices.use_diff_email.link'), add_email_path)) %></p>
<p><%= t('notices.use_diff_email.text_html', link_html: link_to(t('notices.use_diff_email.link'), add_email_path(in_select_email_flow: in_select_email_flow))) %></p>
<p><%= t('devise.registrations.close_window') %></p>

<% if FeatureManagement.enable_load_testing_mode? && EmailAddress.find_with_email(email) %>
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ account.email_language.name.es: Español
account.email_language.name.fr: Français
account.email_language.name.zh: 中文 (简体)
account.email_language.updated: Your email language preference has been updated.
account.emails.confirmed_html: You have confirmed your email address. Go to <a href="%{url}">your connected accounts</a> to update the email you share with connected agencies.
account.forget_all_browsers.longer_description: Once you choose to ‘forget all browsers,’ we’ll need additional information to know that it’s actually you signing in to your account. We’ll ask for a multi-factor authentication method (such as text/SMS code or a security key) each time you want to access your account.
account.index.auth_app_add: Add app
account.index.auth_app_disabled: not enabled
Expand Down
1 change: 1 addition & 0 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ account.email_language.name.es: Español
account.email_language.name.fr: Français
account.email_language.name.zh: 中文 (简体)
account.email_language.updated: Se actualizó su preferencia de idioma del correo electrónico.
account.emails.confirmed_html: Usted confirmó su dirección de correo electrónico. Vaya a <a href="%{url}">Sus cuentas conectadas</a> para actualizar el correo electrónico que proporcionó a las agencias conectadas.
account.forget_all_browsers.longer_description: Una vez que elija “Olvidar todos los navegadores”, necesitaremos más información para saber que realmente es usted quien está iniciando sesión en su cuenta. Le pediremos un método de autenticación multifactor (como código de texto o de SMS, o una clave de seguridad) cada vez que desee acceder a su cuenta.
account.index.auth_app_add: Agregar aplicación
account.index.auth_app_disabled: no habilitada
Expand Down
1 change: 1 addition & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ account.email_language.name.es: Español
account.email_language.name.fr: Français
account.email_language.name.zh: 中文 (简体)
account.email_language.updated: Votre langue de préférence pour les e-mails a été mise à jour.
account.emails.confirmed_html: Vous avez confirmé votre adresse e-mail. Rendez-vous sur <a href="%{url}">vos comptes connectés</a> pour actualiser l’adresse e-mail que vous communiquez aux organismes connectés.
account.forget_all_browsers.longer_description: Une fois que vous aurez choisi d’« oublier tous les navigateurs », nous aurons besoin d’informations supplémentaires pour savoir que c’est bien vous qui vous connectez à votre compte. Nous vous demanderons une méthode d’authentification multi-facteurs (comme un code SMS/texto ou une clé de sécurité) chaque fois que vous souhaiterez accéder à votre compte.
account.index.auth_app_add: Ajouter une appli
account.index.auth_app_disabled: non activé
Expand Down
1 change: 1 addition & 0 deletions config/locales/zh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ account.email_language.name.es: Español
account.email_language.name.fr: Français
account.email_language.name.zh: 中文 (简体)
account.email_language.updated: 你的电邮语言选择已更新。
account.emails.confirmed_html: 你已确认了你的电邮地址。请到<a href="%{url}">你已连接的账户</a>来更新你与已连接机构所分享的电邮。
account.forget_all_browsers.longer_description: 你选择“忘掉所有浏览器”后,我们将需要额外信息来知道的确是你在登录你自己的账户。每次你要访问自己的账户时,我们都会向你要一个多因素身份证实方法(比如短信/SMS 代码或安全密钥)
account.index.auth_app_add: 添加应用程序
account.index.auth_app_disabled: 未启用
Expand Down
36 changes: 36 additions & 0 deletions spec/controllers/accounts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,42 @@
end
end

context 'when user just added new email through select email flow' do
context 'when user is in select email form flow' do
before do
session[:from_select_email_flow] = true
end
it 'renders the proper flash message' do
flash_message = t(
'account.emails.confirmed_html',
url: account_connected_accounts_url,
)
user = create(:user, :fully_registered)
sign_in user

get :show

expect(response).to_not be_redirect
expect(flash[:success]).to eq(flash_message)
expect(session[:from_select_email_flow]).to be_nil
end
end

context 'when user is not in email form flow' do
before do
session[:from_select_email_flow] = false
end
it 'renders proper flash message' do
t('devise.confirmations.confirmed')
user = create(:user, :fully_registered)
sign_in user

get :show
expect(flash[:success]).to be_nil
end
end
end

context 'when a profile has been deactivated by password reset' do
it 'renders the profile and shows a deactivation banner' do
user = create(
Expand Down
20 changes: 20 additions & 0 deletions spec/controllers/users/email_confirmations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@
get :create, params: { confirmation_token: email_record.reload.confirmation_token }
end

context 'when select email feature is disabled' do
before do
allow(IdentityConfig.store).to receive(:feature_select_email_to_share_enabled).
and_return(false)
end
it 'should render proper flash member' do
flash_message = t('devise.confirmations.confirmed')
user = create(:user)
sign_in user
new_email = Faker::Internet.email

add_email_form = AddUserEmailForm.new
add_email_form.submit(user, email: new_email)
email_record = add_email_form.email_address_record(new_email)

get :create, params: { confirmation_token: email_record.reload.confirmation_token }
expect(flash[:success]).to eq(flash_message)
end
end

it 'rejects an otherwise valid token for unconfirmed users' do
user = create(:user, :unconfirmed, email_addresses: [])
new_email = Faker::Internet.email
Expand Down
16 changes: 16 additions & 0 deletions spec/mailers/user_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@
expect(mail.html_part.body).to have_content(add_email_url)
expect(mail.html_part.body).to_not have_content(sign_up_create_email_confirmation_url)
end

context 'when user adds email from select email flow' do
let(:token) { SecureRandom.hex }
let(:mail) do
UserMailer.with(user: user, email_address: email_address).add_email(token, true)
end

it 'renders the add_email_confirmation_url' do
add_email_url = add_email_confirmation_url(
confirmation_token: token,
from_select_email_flow: true,
)

expect(mail.html_part.body).to have_content(add_email_url)
end
end
end

describe '#email_deleted' do
Expand Down
1 change: 1 addition & 0 deletions spec/views/users/emails/verify.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
let(:email) { 'foo@bar.com' }
before do
allow(view).to receive(:email).and_return(email)
allow(view).to receive(:in_select_email_flow).and_return(nil)
@resend_email_confirmation_form = ResendEmailConfirmationForm.new
end

Expand Down