diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 5f619ad36..da0291e7d 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -56,13 +56,14 @@ class UsersController < ApplicationController redirect_to account_path else user_name = @user.name&.possessive || @user.email.possessive - case user_params[:active] - when "false" + if user_params[:active] == "false" @user.update!(confirmed_at: nil, sign_in_count: 0, initial_confirmation_sent: false) flash[:notice] = I18n.t("devise.activation.deactivated", user_name:) - when "true" + elsif user_params[:active] == "true" @user.send_confirmation_instructions flash[:notice] = I18n.t("devise.activation.reactivated", user_name:) + elsif user_params.key?("email") && FeatureToggle.new_email_journey? + flash[:notice] = I18n.t("devise.email.updated", email: @user.unconfirmed_email) end redirect_to user_path(@user) end diff --git a/config/locales/en.yml b/config/locales/en.yml index fb29431e1..5b7654c12 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -684,6 +684,8 @@ Make sure these answers are correct." hint_text: "This is more than 5 times the income, which is higher than we would expect." devise: + email: + updated: An email has been sent to %{email} to confirm this change. two_factor_authentication: success: "Two-factor authentication successful" attempt_failed: "Attempt failed" diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb index 2b2f5a98d..381402c7f 100644 --- a/spec/requests/users_controller_spec.rb +++ b/spec/requests/users_controller_spec.rb @@ -1730,6 +1730,12 @@ RSpec.describe UsersController, type: :request do allow(FeatureToggle).to receive(:new_email_journey?).and_return(true) end + it "shows flash notice" do + patch("/users/#{other_user.id}", headers:, params:) + + expect(flash[:notice]).to eq("An email has been sent to #{new_email} to confirm this change.") + end + it "sends a new flow emails" do expect(notify_client).to receive(:send_email).with( email_address: other_user.email,