diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 90d78f33bf3..e6068396f1c 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -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 diff --git a/app/controllers/users/email_confirmations_controller.rb b/app/controllers/users/email_confirmations_controller.rb index fdd01844ad0..7e7e87e9f8b 100644 --- a/app/controllers/users/email_confirmations_controller.rb +++ b/app/controllers/users/email_confirmations_controller.rb @@ -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 @@ -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 diff --git a/app/controllers/users/emails_controller.rb b/app/controllers/users/emails_controller.rb index e213740f38c..b52c7625d8c 100644 --- a/app/controllers/users/emails_controller.rb +++ b/app/controllers/users/emails_controller.rb @@ -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? @@ -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 @@ -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 diff --git a/app/forms/add_user_email_form.rb b/app/forms/add_user_email_form.rb index 99530bb5bb2..cc91ff62fa2 100644 --- a/app/forms/add_user_email_form.rb +++ b/app/forms/add_user_email_form.rb @@ -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 @@ -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 diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index afb50fab1ae..804c61ea82c 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -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')) diff --git a/app/services/send_add_email_confirmation.rb b/app/services/send_add_email_confirmation.rb index cc9eb7dc7d8..fbeb8d900a8 100644 --- a/app/services/send_add_email_confirmation.rb +++ b/app/services/send_add_email_confirmation.rb @@ -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 @@ -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!( @@ -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 diff --git a/app/views/accounts/connected_accounts/selected_email/edit.html.erb b/app/views/accounts/connected_accounts/selected_email/edit.html.erb index f513ad8ddd7..f2a57f126e5 100644 --- a/app/views/accounts/connected_accounts/selected_email/edit.html.erb +++ b/app/views/accounts/connected_accounts/selected_email/edit.html.erb @@ -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, diff --git a/app/views/sign_up/completions/show.html.erb b/app/views/sign_up/completions/show.html.erb index e019e17a33d..b40f9ce2a3c 100644 --- a/app/views/sign_up/completions/show.html.erb +++ b/app/views/sign_up/completions/show.html.erb @@ -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 %>
diff --git a/app/views/sign_up/select_email/show.html.erb b/app/views/sign_up/select_email/show.html.erb index 0403c5d2653..53b0c04e5de 100644 --- a/app/views/sign_up/select_email/show.html.erb +++ b/app/views/sign_up/select_email/show.html.erb @@ -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, diff --git a/app/views/users/emails/verify.html.erb b/app/views/users/emails/verify.html.erb index 471f93d0a34..211b59fc6ee 100644 --- a/app/views/users/emails/verify.html.erb +++ b/app/views/users/emails/verify.html.erb @@ -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') } %> -<%= t('notices.use_diff_email.text_html', link_html: link_to(t('notices.use_diff_email.link'), add_email_path)) %>
+<%= 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))) %>
<%= t('devise.registrations.close_window') %>
<% if FeatureManagement.enable_load_testing_mode? && EmailAddress.find_with_email(email) %> diff --git a/config/locales/en.yml b/config/locales/en.yml index dfa8e89d2ab..892e172f502 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 your connected accounts 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 diff --git a/config/locales/es.yml b/config/locales/es.yml index 87dbd353b81..e4404aecfcb 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -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 Sus cuentas conectadas 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 diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 7ed5a60b33b..e5c09c19612 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -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 vos comptes connectés 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é diff --git a/config/locales/zh.yml b/config/locales/zh.yml index ce88a940dca..d4c6d20f307 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -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: 你已确认了你的电邮地址。请到你已连接的账户来更新你与已连接机构所分享的电邮。 account.forget_all_browsers.longer_description: 你选择“忘掉所有浏览器”后,我们将需要额外信息来知道的确是你在登录你自己的账户。每次你要访问自己的账户时,我们都会向你要一个多因素身份证实方法(比如短信/SMS 代码或安全密钥) account.index.auth_app_add: 添加应用程序 account.index.auth_app_disabled: 未启用 diff --git a/spec/controllers/accounts_controller_spec.rb b/spec/controllers/accounts_controller_spec.rb index 52818437548..0bae12eabd0 100644 --- a/spec/controllers/accounts_controller_spec.rb +++ b/spec/controllers/accounts_controller_spec.rb @@ -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( diff --git a/spec/controllers/users/email_confirmations_controller_spec.rb b/spec/controllers/users/email_confirmations_controller_spec.rb index 8c984d65584..c6a7613e381 100644 --- a/spec/controllers/users/email_confirmations_controller_spec.rb +++ b/spec/controllers/users/email_confirmations_controller_spec.rb @@ -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 diff --git a/spec/mailers/user_mailer_spec.rb b/spec/mailers/user_mailer_spec.rb index 7f4b80dd228..71f615af5fe 100644 --- a/spec/mailers/user_mailer_spec.rb +++ b/spec/mailers/user_mailer_spec.rb @@ -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 diff --git a/spec/views/users/emails/verify.html.erb_spec.rb b/spec/views/users/emails/verify.html.erb_spec.rb index 5c74dd8b7ed..f90ae443004 100644 --- a/spec/views/users/emails/verify.html.erb_spec.rb +++ b/spec/views/users/emails/verify.html.erb_spec.rb @@ -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