diff --git a/app/controllers/organisation_relationships_controller.rb b/app/controllers/organisation_relationships_controller.rb index 1f83a3edc..1bba91f19 100644 --- a/app/controllers/organisation_relationships_controller.rb +++ b/app/controllers/organisation_relationships_controller.rb @@ -4,6 +4,7 @@ class OrganisationRelationshipsController < ApplicationController before_action :authenticate_user! + before_action :authenticate_scope! def housing_providers housing_providers = organisation.housing_providers @@ -27,4 +28,10 @@ private def search_term params["search"] end + + def authenticate_scope! + if current_user.organisation != organisation + render_not_found + end + end end diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index 6bc335921..efbd42afe 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/spec/requests/organisations_controller_spec.rb @@ -284,6 +284,54 @@ RSpec.describe OrganisationsController, type: :request do end end + context "when accessing the housing providers tab" do + context "with an organisation that the user belongs to" do + let!(:housing_provider) { FactoryBot.create(:organisation) } + let!(:other_org_housing_provider) { FactoryBot.create(:organisation, name: "Foobar LTD") } + let!(:other_organisation) { FactoryBot.create(:organisation, name: "Foobar LTD") } + let!(:organisation_relationship) { FactoryBot.create(:organisation_relationship, child_organisation: organisation, parent_organisation: housing_provider, relationship_type: OrganisationRelationship.relationship_types[:owning]) } + let!(:other_organisation_relationship) { FactoryBot.create(:organisation_relationship, child_organisation: other_organisation, parent_organisation: other_org_housing_provider, relationship_type: OrganisationRelationship.relationship_types[:owning]) } + + before do + get "/organisations/#{organisation.id}/housing-providers", headers:, params: {} + end + + it "shows the tab navigation" do + expected_html = "