diff --git a/app/helpers/tab_nav_helper.rb b/app/helpers/tab_nav_helper.rb index 24408be28..27542094d 100644 --- a/app/helpers/tab_nav_helper.rb +++ b/app/helpers/tab_nav_helper.rb @@ -19,7 +19,8 @@ module TabNavHelper end def org_cell(user) + org_name = current_user.support? ? govuk_link_to(user.organisation.name, lettings_logs_organisation_path(user.organisation)) : user.organisation.name role = "#{user.role.to_s.humanize}" - [user.organisation.name, role].join("\n") + [org_name, role].join("\n") end end diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index c62fccf2c..acb53d51d 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -67,7 +67,7 @@ <%= summary_list.with_row do |row| row.with_key { "Organisation" } - row.with_value { @user.organisation.name } + row.with_value { current_user.support? ? govuk_link_to(@user.organisation.name, lettings_logs_organisation_path(@user.organisation)) : @user.organisation.name } row.with_action end %> diff --git a/spec/helpers/tab_nav_helper_spec.rb b/spec/helpers/tab_nav_helper_spec.rb index 7b4efc5eb..9dbf92e7a 100644 --- a/spec/helpers/tab_nav_helper_spec.rb +++ b/spec/helpers/tab_nav_helper_spec.rb @@ -2,21 +2,21 @@ require "rails_helper" RSpec.describe TabNavHelper do let(:organisation) { FactoryBot.create(:organisation) } - let(:user) { FactoryBot.build(:user, organisation:) } + let(:current_user) { FactoryBot.build(:user, organisation:) } let(:scheme) { FactoryBot.create(:scheme, service_name: "Some name") } let(:location) { FactoryBot.create(:location, scheme:) } describe "#user_cell" do it "returns user link and email separated by a newline character" do - expected_html = "#{user.name}\nUser #{user.email}" - expect(user_cell(user)).to match(expected_html) + expected_html = "#{current_user.name}\nUser #{current_user.email}" + expect(user_cell(current_user)).to match(expected_html) end end describe "#org_cell" do it "returns the users org name and role separated by a newline character" do expected_html = "DLUHC\nData provider" - expect(org_cell(user)).to match(expected_html) + expect(org_cell(current_user)).to match(expected_html) end end diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb index 9784aa0dc..bb0a1cca3 100644 --- a/spec/requests/users_controller_spec.rb +++ b/spec/requests/users_controller_spec.rb @@ -1188,7 +1188,7 @@ RSpec.describe UsersController, type: :request do describe "#index" do let!(:other_user) { create(:user, organisation: user.organisation, name: "User 2", email: "other@example.com") } let!(:inactive_user) { create(:user, organisation: user.organisation, active: false, name: "User 3", email: "inactive@example.com", last_sign_in_at: Time.zone.local(2022, 10, 10)) } - let!(:other_org_user) { create(:user, name: "User 4", email: "otherorg@otherexample.com", organisation: create(:organisation, :without_dpc)) } + let!(:other_org_user) { create(:user, name: "User 4", email: "otherorg@otherexample.com", organisation: create(:organisation, :without_dpc, name: "Other name")) } before do get "/users", headers:, params: {} @@ -1201,6 +1201,11 @@ RSpec.describe UsersController, type: :request do expect(page).to have_content(other_org_user.name) end + it "links to user organisations" do + expect(page).to have_link(user.organisation.name, href: "/organisations/#{user.organisation.id}/lettings-logs", count: 3) + expect(page).to have_link(other_org_user.organisation.name, href: "/organisations/#{other_org_user.organisation.id}/lettings-logs", count: 1) + end + it "shows last logged in date for all users" do expect(page).to have_content("10 October 2022") end @@ -1432,6 +1437,10 @@ RSpec.describe UsersController, type: :request do expect(page).to have_link("Change", text: "if a key contact") end + it "links to user organisation" do + expect(page).to have_link(other_user.organisation.name, href: "/organisations/#{other_user.organisation.id}/lettings-logs") + end + it "does not show option to resend confirmation email" do expect(page).not_to have_button("Resend invite link") end