diff --git a/app/controllers/organisation_relationships_controller.rb b/app/controllers/organisation_relationships_controller.rb index 1677239d0..9a6609a27 100644 --- a/app/controllers/organisation_relationships_controller.rb +++ b/app/controllers/organisation_relationships_controller.rb @@ -9,6 +9,10 @@ class OrganisationRelationshipsController < ApplicationController @managing_agents = organisation.managing_agents end + def housing_providers + @housing_providers = organisation.housing_providers + end + private def organisation diff --git a/app/controllers/organisations_controller.rb b/app/controllers/organisations_controller.rb index 6baa0405d..75192cd47 100644 --- a/app/controllers/organisations_controller.rb +++ b/app/controllers/organisations_controller.rb @@ -136,13 +136,7 @@ class OrganisationsController < ApplicationController end def housing_providers - housing_providers = - Organisation.joins(:child_organisation_relationships) - .where(organisation_relationships: { - child_organisation_id: @organisation.id, - relationship_type: OrganisationRelationship.relationship_types[:owning], - }) - .order(:name) + housing_providers = @organisation.housing_providers unpaginated_filtered_housing_providers = filtered_collection(housing_providers, search_term) respond_to do |format| format.html do diff --git a/app/helpers/navigation_items_helper.rb b/app/helpers/navigation_items_helper.rb index 52857d65b..fee2ce0f5 100644 --- a/app/helpers/navigation_items_helper.rb +++ b/app/helpers/navigation_items_helper.rb @@ -2,7 +2,7 @@ module NavigationItemsHelper NavigationItem = Struct.new(:text, :href, :current, :classes) def primary_items(path, current_user) - items = if current_user.support? + if current_user.support? [ NavigationItem.new("Organisations", organisations_path, organisations_current?(path)), NavigationItem.new("Users", "/users", users_current?(path)), @@ -24,12 +24,9 @@ module NavigationItemsHelper FeatureToggle.sales_log_enabled? ? NavigationItem.new("Sales logs", sales_logs_path, sales_logs_current?(path)) : nil, NavigationItem.new("Users", users_organisation_path(current_user.organisation), subnav_users_path?(path)), NavigationItem.new("About your organisation", "/organisations/#{current_user.organisation.id}", subnav_details_path?(path)), - NavigationItem.new("Housing providers", housing_providers_organisation_path(current_user.organisation), housing_providers_current?(path)), + NavigationItem.new("Housing providers", housing_providers_organisation_path(current_user.organisation), subnav_housing_providers_path?(path)), ].compact end - - # figure out correct rules - items << managing_agents_item(path) end def secondary_items(path, current_organisation_id) @@ -81,10 +78,6 @@ private path == "/organisations" || path.include?("/organisations/") end - def housing_providers_current?(path) - path == "/housing-providers" - end - def subnav_housing_providers_path?(path) path.include?("/organisations") && path.include?("/housing-providers") end diff --git a/app/models/organisation.rb b/app/models/organisation.rb index e86be1e9f..093655efe 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -15,6 +15,8 @@ class Organisation < ApplicationRecord has_many :managing_agent_relationships, -> { where(relationship_type: OrganisationRelationship::MANAGING) }, foreign_key: :child_organisation_id, class_name: "OrganisationRelationship" has_many :managing_agents, through: :managing_agent_relationships, source: :parent_organisation + has_many :housing_provider_relationships, -> { where(relationship_type: OrganisationRelationship::OWNING) }, foreign_key: :child_organisation_id, class_name: "OrganisationRelationship" + has_many :housing_providers, through: :housing_provider_relationships, source: :parent_organisation scope :search_by_name, ->(name) { where("name ILIKE ?", "%#{name}%") } scope :search_by, ->(param) { search_by_name(param) }