From 025bf571d363602fb85ed0d3b6fbecf52817fd61 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Thu, 20 Oct 2022 10:46:31 +0100 Subject: [PATCH] feat: remove managing agent related code so can be merged directly --- .../organisation_relationships_controller.rb | 6 ------ app/helpers/navigation_items_helper.rb | 20 +------------------ app/models/organisation.rb | 2 -- .../managing_agents.html.erb | 8 -------- config/initializers/feature_toggle.rb | 6 ------ config/routes.rb | 1 - ...3607_rename_organisations_agents_column.rb | 4 ---- db/seeds.rb | 10 +++++----- spec/models/organisation_spec.rb | 14 ++++++------- 9 files changed, 13 insertions(+), 58 deletions(-) delete mode 100644 app/views/organisation_relationships/managing_agents.html.erb delete mode 100644 db/migrate/20221018143607_rename_organisations_agents_column.rb diff --git a/app/controllers/organisation_relationships_controller.rb b/app/controllers/organisation_relationships_controller.rb index d15d904e6..1f83a3edc 100644 --- a/app/controllers/organisation_relationships_controller.rb +++ b/app/controllers/organisation_relationships_controller.rb @@ -5,12 +5,6 @@ class OrganisationRelationshipsController < ApplicationController before_action :authenticate_user! - def managing_agents - # kick out if cannot access org - - @managing_agents = organisation.managing_agents - end - def housing_providers housing_providers = organisation.housing_providers unpaginated_filtered_housing_providers = filtered_collection(housing_providers, search_term) diff --git a/app/helpers/navigation_items_helper.rb b/app/helpers/navigation_items_helper.rb index 0e97540c2..811db5cc9 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)), @@ -28,9 +28,6 @@ module NavigationItemsHelper NavigationItem.new("Housing providers", housing_providers_organisation_path(current_user.organisation), housing_providers_path?(path)), ].compact end - - # figure out correct rules - items << managing_agents_item(path) end def secondary_items(path, current_organisation_id) @@ -106,19 +103,4 @@ private def housing_providers_path?(path) path.include?("/housing-providers") end - - def managing_agents_path?(path) - path.include?("/managing-agents") - end - - def managing_agents_item(path) - return unless FeatureToggle.managing_agents_enabled? - return unless current_user.organisation.holds_own_stock? - - NavigationItem.new( - "Managing agents", - "/organisations/#{current_user.organisation.id}/managing-agents", - managing_agents_path?(path), - ) - end end diff --git a/app/models/organisation.rb b/app/models/organisation.rb index db81cc807..27230ead0 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -13,8 +13,6 @@ class Organisation < ApplicationRecord has_many :child_organisation_relationships, foreign_key: :parent_organisation_id, class_name: "OrganisationRelationship" has_many :child_organisations, through: :child_organisation_relationships - 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 diff --git a/app/views/organisation_relationships/managing_agents.html.erb b/app/views/organisation_relationships/managing_agents.html.erb deleted file mode 100644 index a4a8aa6ad..000000000 --- a/app/views/organisation_relationships/managing_agents.html.erb +++ /dev/null @@ -1,8 +0,0 @@ -<% title = format_title(nil, current_user.support? ? "About this organisation" : "Your managing agents", current_user, nil, nil, @organisation.name) %> -<% content_for :title, title %> - -<%= render partial: "organisations/headings", locals: { main: "Your managing agents", sub: nil } %> - -<% @managing_agents.each do |managing_agent|%> - <%= managing_agent.name %> -<% end %> diff --git a/config/initializers/feature_toggle.rb b/config/initializers/feature_toggle.rb index 64b75e6b7..0e01531ca 100644 --- a/config/initializers/feature_toggle.rb +++ b/config/initializers/feature_toggle.rb @@ -8,10 +8,4 @@ class FeatureToggle false end - - def self.managing_agents_enabled? - return true unless Rails.env.production? - - false - end end diff --git a/config/routes.rb b/config/routes.rb index bae96c98c..e703b853d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -79,7 +79,6 @@ Rails.application.routes.draw do post "logs/email-csv", to: "organisations#email_csv" get "logs/csv-confirmation", to: "lettings_logs#csv_confirmation" get "schemes", to: "organisations#schemes" - get "managing-agents", to: "organisation_relationships#managing_agents" get "housing-providers", to: "organisation_relationships#housing_providers" end end diff --git a/db/migrate/20221018143607_rename_organisations_agents_column.rb b/db/migrate/20221018143607_rename_organisations_agents_column.rb deleted file mode 100644 index 0397f4afd..000000000 --- a/db/migrate/20221018143607_rename_organisations_agents_column.rb +++ /dev/null @@ -1,4 +0,0 @@ -class RenameOrganisationsAgentsColumn < ActiveRecord::Migration[7.0] - def change - end -end diff --git a/db/seeds.rb b/db/seeds.rb index e5e4eacaa..2ad174195 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -8,8 +8,8 @@ # rubocop:disable Rails/Output unless Rails.env.test? - managing_agent = Organisation.find_or_create_by!( - name: "Managing Agent", + housing_provider = Organisation.find_or_create_by!( + name: "Housing Provider", address_line1: "2 Marsham Street", address_line2: "London", postcode: "SW1P 4DF", @@ -24,7 +24,7 @@ unless Rails.env.test? address_line1: "2 Marsham Street", address_line2: "London", postcode: "SW1P 4DF", - holds_own_stock: true, + holds_own_stock: false, other_stock_owners: "None", managing_agents_label: "None", provider_type: "LA", @@ -39,8 +39,8 @@ unless Rails.env.test? OrganisationRelationship.create!( child_organisation: org, - parent_organisation: managing_agent, - relationship_type: OrganisationRelationship::MANAGING, + parent_organisation: housing_provider, + relationship_type: OrganisationRelationship::OWNING, ) if Rails.env.development? && User.count.zero? diff --git a/spec/models/organisation_spec.rb b/spec/models/organisation_spec.rb index 1d9e557ec..ec83e7469 100644 --- a/spec/models/organisation_spec.rb +++ b/spec/models/organisation_spec.rb @@ -34,14 +34,14 @@ RSpec.describe Organisation, type: :model do before do FactoryBot.create( :organisation_relationship, - :managing, + :owning, child_organisation:, parent_organisation: organisation, ) FactoryBot.create( :organisation_relationship, - :managing, + :owning, child_organisation: grandchild_organisation, parent_organisation: child_organisation, ) @@ -58,7 +58,7 @@ RSpec.describe Organisation, type: :model do end end - context "with managing association", :aggregate_failures do + context "with owning association", :aggregate_failures do let!(:child_organisation) { FactoryBot.create(:organisation, name: "DLUHC Child") } let!(:grandchild_organisation) { FactoryBot.create(:organisation, name: "DLUHC Grandchild") } @@ -79,15 +79,15 @@ RSpec.describe Organisation, type: :model do FactoryBot.create( :organisation_relationship, - :managing, + :owning, child_organisation: grandchild_organisation, parent_organisation: child_organisation, ) end - it "has correct managing_agents" do - expect(child_organisation.managing_agents).to eq([organisation]) - expect(grandchild_organisation.managing_agents).to eq([child_organisation]) + it "has correct housing_providers" do + expect(child_organisation.housing_providers).to eq([organisation]) + expect(grandchild_organisation.housing_providers).to eq([child_organisation]) end end