From 384364986e3853187d9b2b1ee0be824589cab7fb Mon Sep 17 00:00:00 2001 From: Chris Roos Date: Thu, 16 Nov 2023 12:05:21 +0000 Subject: [PATCH] Update applications when user's name changes Trello: https://trello.com/c/2t9zx0Aq Prior to #2497 changing a user's name in Signon would queue a job to push that update out to the applications the user has access to. This commit reinstates the previous behaviour by using `UserUpdate` in `Users::NamesController#update`, which in turn uses `PermissionUpdater` to push updates to the user's apps. I can't find any documentation that describes the changes that result in push updates to a user's applications, but as far as I can see, changing a user's name has resulted in a push update since the relevant functionality was added to Signon[1] and gds-sso[2] in 2012 so it seems reasonable that we retain this behaviour. Note that `UserUpdate#record_update`[3] records an `EventLog` event so I've removed this from `Users::NamesController#update`. [1]: https://github.com/alphagov/signon/pull/6/commits/f339848ac0c98188b0fc746935324f59215d26f2 [2]: https://github.com/alphagov/gds-sso/commit/8c0888cda78b2d0323da26ff4c8da362074168d7 [3]: https://github.com/alphagov/signon/blob/16299a28ed46d12a8b0cb61c1cf755166317057c/app/services/user_update.rb#L72 --- app/controllers/users/names_controller.rb | 4 ++-- test/controllers/users/names_controller_test.rb | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/controllers/users/names_controller.rb b/app/controllers/users/names_controller.rb index dc78aad97..0caa802bb 100644 --- a/app/controllers/users/names_controller.rb +++ b/app/controllers/users/names_controller.rb @@ -9,8 +9,8 @@ class Users::NamesController < ApplicationController def edit; end def update - if @user.update(user_params) - EventLog.record_event(@user, EventLog::ACCOUNT_UPDATED, initiator: current_user, ip_address: user_ip_address) + updater = UserUpdate.new(@user, user_params, current_user, user_ip_address) + if updater.call redirect_to edit_user_path(@user), notice: "Updated user #{@user.email} successfully" else render :edit diff --git a/test/controllers/users/names_controller_test.rb b/test/controllers/users/names_controller_test.rb index 7c10bdea8..c42c840d3 100644 --- a/test/controllers/users/names_controller_test.rb +++ b/test/controllers/users/names_controller_test.rb @@ -103,6 +103,13 @@ class Users::NamesControllerTest < ActionController::TestCase put :update, params: { user_id: user, user: { name: "new-user-name" } } end + should "push changes out to apps" do + user = create(:user) + PermissionUpdater.expects(:perform_on).with(user).once + + put :update, params: { user_id: user, user: { name: "new-user-name" } } + end + should "redirect to user page and display success notice" do user = create(:user, email: "user@gov.uk")