From 4743fb6fba02be331441a2c31854f0224b8528b0 Mon Sep 17 00:00:00 2001 From: Jack S Date: Wed, 19 Oct 2022 12:20:53 +0100 Subject: [PATCH] f --- .../organisation_relationships_controller.rb | 7 ++--- app/helpers/navigation_items_helper.rb | 8 +++--- .../managing_agents.html.erb | 7 ++++- db/seeds.rb | 26 +++++++++++-------- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/app/controllers/organisation_relationships_controller.rb b/app/controllers/organisation_relationships_controller.rb index e784c23e1..1677239d0 100644 --- a/app/controllers/organisation_relationships_controller.rb +++ b/app/controllers/organisation_relationships_controller.rb @@ -4,12 +4,9 @@ class OrganisationRelationshipsController < ApplicationController before_action :authenticate_user! def managing_agents - # kick out if org isn't the current org + # kick out if cannot access org - @managing_agents = OrganisationRelationships.where( - owning_organisation_id: organisation.id, - relationship_type: :managing, - ) + @managing_agents = organisation.managing_agents end private diff --git a/app/helpers/navigation_items_helper.rb b/app/helpers/navigation_items_helper.rb index a5f701743..270a563e4 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) - if current_user.support? + items = if current_user.support? [ NavigationItem.new("Organisations", organisations_path, organisations_current?(path)), NavigationItem.new("Users", "/users", users_current?(path)), @@ -24,9 +24,11 @@ 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)), - managing_agents_item, ].compact end + + # figure out correct rules + items << managing_agents_item(path) end def secondary_items(path, current_organisation_id) @@ -97,7 +99,7 @@ private path.include?("/managing-agents") end - def managing_agents_item + def managing_agents_item(path) return unless FeatureToggle.managing_agents_enabled? return unless current_user.organisation.holds_own_stock? diff --git a/app/views/organisation_relationships/managing_agents.html.erb b/app/views/organisation_relationships/managing_agents.html.erb index a9b698239..a4a8aa6ad 100644 --- a/app/views/organisation_relationships/managing_agents.html.erb +++ b/app/views/organisation_relationships/managing_agents.html.erb @@ -1,3 +1,8 @@ +<% 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.inspect %> + <%= managing_agent.name %> <% end %> diff --git a/db/seeds.rb b/db/seeds.rb index dfc479cb8..e5e4eacaa 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -8,6 +8,17 @@ # rubocop:disable Rails/Output unless Rails.env.test? + managing_agent = Organisation.find_or_create_by!( + name: "Managing Agent", + address_line1: "2 Marsham Street", + address_line2: "London", + postcode: "SW1P 4DF", + holds_own_stock: true, + other_stock_owners: "None", + managing_agents_label: "None", + provider_type: "LA", + ) + org = Organisation.find_or_create_by!( name: "DLUHC", address_line1: "2 Marsham Street", @@ -26,19 +37,12 @@ unless Rails.env.test? end end - Organisation.find_or_create_by!( - name: "DLUHC", - address_line1: "2 Marsham Street", - address_line2: "London", - postcode: "SW1P 4DF", - holds_own_stock: true, - other_stock_owners: "None", - managing_agents_label: "None", - provider_type: "LA", - child_organisations: [org], + OrganisationRelationship.create!( + child_organisation: org, + parent_organisation: managing_agent, + relationship_type: OrganisationRelationship::MANAGING, ) - if Rails.env.development? && User.count.zero? User.create!( name: "Provider",