Browse Source

Change user update success banner

pull/2663/head
Kat 2 years ago
parent
commit
2449dabc8d
  1. 9
      app/controllers/users_controller.rb
  2. 5
      config/locales/en.yml
  3. 48
      spec/requests/users_controller_spec.rb

9
app/controllers/users_controller.rb

@ -65,8 +65,9 @@ class UsersController < ApplicationController
if @user == current_user
bypass_sign_in @user
flash[:notice] = I18n.t("devise.passwords.updated") if user_params.key?("password")
if user_params.key?("email") && user_params[:email] != @user.email
flash[:notice] = I18n.t("devise.email.updated", email: @user.unconfirmed_email)
if @user.saved_changes?
flash[:notice] = I18n.t("notification.user_updated.self")
end
if updating_organisation?
@ -83,8 +84,8 @@ class UsersController < ApplicationController
@user.reactivate!
@user.send_confirmation_instructions
flash[:notice] = I18n.t("devise.activation.reactivated", user_name:)
elsif user_params.key?("email") && user_params[:email] != @user.email
flash[:notice] = I18n.t("devise.email.updated", email: @user.unconfirmed_email)
elsif @user.saved_changes?
flash[:notice] = I18n.t("notification.user_updated.other", name: @user.name)
end
if updating_organisation?

5
config/locales/en.yml

@ -215,6 +215,9 @@ en:
scheme_deleted: "%{service_name} has been deleted."
user_deleted: "%{name} has been deleted."
organisation_deleted: "%{name} has been deleted."
user_updated:
self: "Your account details have been updated."
other: "%{name}’s details have been updated."
validations:
organisation:
@ -815,8 +818,6 @@ Make sure these answers are correct."
title: "You told us there are more than 1 persons with 'Partner' relationship to buyer 1."
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"

48
spec/requests/users_controller_spec.rb

@ -1783,18 +1783,18 @@ RSpec.describe UsersController, type: :request do
end
it "shows flash notice" do
patch("/users/#{other_user.id}", headers:, params:)
request
expect(flash[:notice]).to eq("An email has been sent to #{new_email} to confirm this change.")
expect(flash[:notice]).to eq("Your account details have been updated.")
end
it "sends new flow emails" do
expect(notify_client).to receive(:send_email).with(
email_address: other_user.email,
email_address: user.email,
template_id: User::FOR_OLD_EMAIL_CHANGED_BY_OTHER_USER_TEMPLATE_ID,
personalisation: {
new_email:,
old_email: other_user.email,
old_email: user.email,
},
).once
@ -1803,14 +1803,14 @@ RSpec.describe UsersController, type: :request do
template_id: User::FOR_NEW_EMAIL_CHANGED_BY_OTHER_USER_TEMPLATE_ID,
personalisation: {
new_email:,
old_email: other_user.email,
old_email: user.email,
link: include("/account/confirmation?confirmation_token="),
},
).once
expect(notify_client).not_to receive(:send_email)
patch "/users/#{other_user.id}", headers:, params:
request
end
context "when user has never confirmed email address" do
@ -1823,9 +1823,9 @@ RSpec.describe UsersController, type: :request do
end
it "shows flash notice" do
patch("/users/#{other_user.id}", headers:, params:)
request
expect(flash[:notice]).to eq("An email has been sent to #{new_email} to confirm this change.")
expect(flash[:notice]).to eq("Your account details have been updated.")
end
it "sends new flow emails" do
@ -1855,14 +1855,38 @@ RSpec.describe UsersController, type: :request do
end
end
context "and email address hasn't changed" do
let(:params) { { id: user.id, user: { name: new_name, email: other_user.email, is_dpo: "true", is_key_contact: "true" } } }
context "and no fields have changed" do
let(:params) { { id: user.id, user: { name: user.name, email: user.email, is_dpo: user.is_dpo, is_key_contact: user.is_key_contact } } }
before do
user.legacy_users.destroy_all
end
it "shows flash notice" do
it "does not show flash notice" do
request
expect(flash[:notice]).to be_nil
end
end
end
context "when user changes phone number", :aggregate_failures do
let(:params) { { id: user.id, user: { phone: "123123123123" } } }
it "shows flash notice" do
request
expect(flash[:notice]).to eq("Your account details have been updated.")
end
context "and phone numbr hasn't changed" do
let(:params) { { id: user.id, user: { phone: other_user.phone } } }
before do
user.legacy_users.destroy_all
end
it "does not show flash notice" do
patch("/users/#{other_user.id}", headers:, params:)
expect(flash[:notice]).to be_nil
@ -2027,7 +2051,7 @@ RSpec.describe UsersController, type: :request do
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.")
expect(flash[:notice]).to eq("new name’s details have been updated.")
end
it "sends new flow emails" do

Loading…
Cancel
Save