From 07b54c3ba573aed185d221d9cb05a580a375506d Mon Sep 17 00:00:00 2001 From: Ynda Jas Date: Wed, 29 May 2024 15:14:24 +0100 Subject: [PATCH 1/2] Fix current role on edit own role page On the page where a user can edit their role, the select element always had "Normal" preselected, regardless of the user's actual current role. This was because of a mistake in the preselection logic, which is fixed here --- app/views/account/roles/edit.html.erb | 2 +- test/integration/account_roles_test.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/account/roles/edit.html.erb b/app/views/account/roles/edit.html.erb index fe0e620bf..bce135e28 100644 --- a/app/views/account/roles/edit.html.erb +++ b/app/views/account/roles/edit.html.erb @@ -24,7 +24,7 @@ id: "user_role", name: "user[role]", label: "Role", - options: current_user.manageable_roles.map { |role| { text: role.display_name, value: role.name, selected: current_user.role == role.name } } + options: current_user.manageable_roles.map { |role| { text: role.display_name, value: role.name, selected: current_user.role_name == role.name } } } %> <%= render "govuk_publishing_components/components/button", { text: "Change role" diff --git a/test/integration/account_roles_test.rb b/test/integration/account_roles_test.rb index 72d94dc40..13c84bfdc 100644 --- a/test/integration/account_roles_test.rb +++ b/test/integration/account_roles_test.rb @@ -21,6 +21,7 @@ class AccountRolesTest < ActionDispatch::IntegrationTest visit edit_account_role_path + assert has_select? "Role", selected: "Superadmin" select "Normal", from: "Role" click_button "Change role" From 1c739dffacc11743e4e5ca968d1a791cbe36e556 Mon Sep 17 00:00:00 2001 From: Ynda Jas Date: Wed, 29 May 2024 15:38:05 +0100 Subject: [PATCH 2/2] Fix current role on edit another user's role page On the page where a user can edit another user's role, the select element always had "Normal" preselected, regardless of the user's actual current role. This was because of a mistake in the preselection logic, which is fixed here --- app/views/users/roles/edit.html.erb | 2 +- test/integration/change_user_role_test.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/users/roles/edit.html.erb b/app/views/users/roles/edit.html.erb index d966aa072..916fb0efd 100644 --- a/app/views/users/roles/edit.html.erb +++ b/app/views/users/roles/edit.html.erb @@ -48,7 +48,7 @@ name: "user[role]", label: "Role", hint: user_role_select_hint, - options: current_user.manageable_roles.map { |role| { text: role.display_name, value: role.name, selected: @user.role == role.name } }, + options: current_user.manageable_roles.map { |role| { text: role.display_name, value: role.name, selected: @user.role_name == role.name } }, error_message: @user.errors[:role].any? ? @user.errors.full_messages_for(:role).to_sentence : nil } %>
diff --git a/test/integration/change_user_role_test.rb b/test/integration/change_user_role_test.rb index a9138cdbb..f3c94b18b 100644 --- a/test/integration/change_user_role_test.rb +++ b/test/integration/change_user_role_test.rb @@ -14,10 +14,11 @@ def sign_in_as_and_edit_user(sign_in_as, user_to_edit) context "when logged in as a super admin" do should "be able to change the role of a user who is not exempt from 2SV" do - user = create(:user) + user = create(:two_step_enabled_organisation_admin) sign_in_as_and_edit_user(@super_admin, user) click_link "Change Role" + assert has_select? "Role", selected: "Organisation admin" select "Admin", from: "Role" click_button "Change role"