Skip to content

Commit

Permalink
Update applications when user's name changes
Browse files Browse the repository at this point in the history
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.

[1]: f339848
[2]: alphagov/gds-sso@8c0888c
  • Loading branch information
chrisroos committed Nov 16, 2023
1 parent 16299a2 commit 2e87e64
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/controllers/users/names_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/controllers/users/names_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit 2e87e64

Please sign in to comment.