Skip to content

Commit

Permalink
Fix admin user switching issue
Browse files Browse the repository at this point in the history
This fixes an issue where if an admin user switches their organisation,
the user list view shows the switched organisation rather than each user's
actual organisation. We include a test to reflect that this behaviour is
now correct.
  • Loading branch information
benshimmin committed Jan 17, 2025
1 parent 4c1ae14 commit 734c759
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

[Full changelog][unreleased]

- Fixed: users list view shows correct organisation after admin user has
switched organisation

## Release 161 - 2025-01-14

[Full changelog][161]
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/users/_active_table.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
%tr.govuk-table__row
%td.govuk-table__cell= user.name
%td.govuk-table__cell= user.email
%td.govuk-table__cell.organisation= user.organisation.name
%td.govuk-table__cell.organisation= user.primary_organisation.name
%td.govuk-table__cell
= a11y_action_link(t("default.link.show"), user_path(user), user.name)
= a11y_action_link(t("default.link.edit"), edit_user_path(user), user.name, ["govuk-!-margin-left-3"])
2 changes: 1 addition & 1 deletion app/views/shared/users/_deactivated_table.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
%tr.govuk-table__row
%td.govuk-table__cell= user.name
%td.govuk-table__cell= user.email
%td.govuk-table__cell.organisation= user.organisation.name
%td.govuk-table__cell.organisation= user.primary_organisation.name
%td.govuk-table__cell= time_ago_in_words(user.deactivated_at)
%td.govuk-table__cell
= a11y_action_link(t("default.link.show"), user_path(user), user.name)
Expand Down
42 changes: 42 additions & 0 deletions spec/features/users_can_switch_organisation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,48 @@
end
end

context "when a BEIS user has switched organisation" do
let(:user_with_additional_organisations) do
user = create(:beis_user)
user.additional_organisations << [
create(:partner_organisation),
create(:partner_organisation),
create(:beis_organisation)
]
user
end

before do
authenticate!(user: user_with_additional_organisations)
end
after { logout }

scenario "the other users' organisations in the users list do not change to the switched organisation" do
org1 = create(:partner_organisation)
org2 = create(:partner_organisation)
create(:partner_organisation_user, organisation: org1)
create(:partner_organisation_user, organisation: org2)

additional_org = user_with_additional_organisations.additional_organisations.first
beis_org = user_with_additional_organisations.additional_organisations.last

visit(root_path)

# Switch to any other organisation...
select(additional_org.name, from: "current_user_organisation")
click_on t("organisation_switcher.submit")

# Switch to BEIS/DSIT organisation so that users_path can be viewed
select(beis_org.name, from: "current_user_organisation")
click_on t("organisation_switcher.submit")

visit(users_path)

expect(page).to have_content org1.name
expect(page).to have_content org2.name
end
end

context "when the user has no additional organisations" do
let(:user) { create(:partner_organisation_user) }

Expand Down

0 comments on commit 734c759

Please sign in to comment.