Browse Source

wip

CLDC-1661-new-page-for-housing-providers
Jack S 2 years ago
parent
commit
7adf58feae
  1. 20
      app/controllers/organisation_relationships_controller.rb
  2. 16
      app/helpers/navigation_items_helper.rb
  3. 6
      app/models/organisation.rb
  4. 6
      app/models/organisation_relationship.rb
  5. 3
      app/views/organisation_relationships/managing_agents.html.erb
  6. 6
      config/initializers/feature_toggle.rb
  7. 1
      config/routes.rb
  8. 4
      db/migrate/20221018143607_rename_organisations_agents_column.rb
  9. 15
      db/seeds.rb
  10. 4
      spec/models/organisation_spec.rb

20
app/controllers/organisation_relationships_controller.rb

@ -0,0 +1,20 @@
class OrganisationRelationshipsController < ApplicationController
include Pagy::Backend
before_action :authenticate_user!
def managing_agents
# kick out if org isn't the current org
@managing_agents = OrganisationRelationships.where(
owning_organisation_id: organisation.id,
relationship_type: :managing,
)
end
private
def organisation
@organisation ||= Organisation.find(params[:id])
end
end

16
app/helpers/navigation_items_helper.rb

@ -24,6 +24,7 @@ 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
end
@ -91,4 +92,19 @@ private
def subnav_details_path?(path)
path.include?("/organisations") && path.include?("/details")
end
def managing_agents_path?(path)
path.include?("/managing-agents")
end
def managing_agents_item
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

6
app/models/organisation.rb

@ -13,6 +13,12 @@ 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_agents,
-> { joins(:parent_organisation_relationships).where({ parent_organisation_relationships: { relationship_type: OrganisationRelationship::MANAGING } }) },
class_name: "Organisation",
through: :parent_organisation_relationships,
source: :child_organisation
scope :search_by_name, ->(name) { where("name ILIKE ?", "%#{name}%") }
scope :search_by, ->(param) { search_by_name(param) }

6
app/models/organisation_relationship.rb

@ -2,9 +2,11 @@ class OrganisationRelationship < ApplicationRecord
belongs_to :child_organisation, class_name: "Organisation"
belongs_to :parent_organisation, class_name: "Organisation"
OWNING = "owning".freeze
MANAGING = "managing".freeze
RELATIONSHIP_TYPE = {
"owning": 0,
"managing": 1,
OWNING => 0,
MANAGING => 1,
}.freeze
enum relationship_type: RELATIONSHIP_TYPE

3
app/views/organisation_relationships/managing_agents.html.erb

@ -0,0 +1,3 @@
<% @managing_agents.each do |managing_agent|%>
<%= managing_agent.inspect %>
<% end %>

6
config/initializers/feature_toggle.rb

@ -8,4 +8,10 @@ class FeatureToggle
false
end
def self.managing_agents_enabled?
return true unless Rails.env.production?
false
end
end

1
config/routes.rb

@ -79,6 +79,7 @@ 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"
end
end

4
db/migrate/20221018143607_rename_organisations_agents_column.rb

@ -0,0 +1,4 @@
class RenameOrganisationsAgentsColumn < ActiveRecord::Migration[7.0]
def change
end
end

15
db/seeds.rb

@ -13,7 +13,7 @@ unless Rails.env.test?
address_line1: "2 Marsham Street",
address_line2: "London",
postcode: "SW1P 4DF",
holds_own_stock: false,
holds_own_stock: true,
other_stock_owners: "None",
managing_agents: "None",
provider_type: "LA",
@ -26,6 +26,19 @@ 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: "None",
provider_type: "LA",
child_organisations: [org]
)
if Rails.env.development? && User.count.zero?
User.create!(
name: "Provider",

4
spec/models/organisation_spec.rb

@ -41,6 +41,10 @@ RSpec.describe Organisation, type: :model do
it "has correct parent" do
expect(child_organisation.parent_organisations.first).to eq(organisation)
end
it "has correct managing agents" do
expect(child_organisation.managing_agents).to eq([organisation])
end
end
context "with owning association" do

Loading…
Cancel
Save