diff --git a/app/views/organisation_relationships/_related_organisation_select_question.html.erb b/app/views/organisation_relationships/_related_organisation_select_question.html.erb
new file mode 100644
index 000000000..cc27c2b8b
--- /dev/null
+++ b/app/views/organisation_relationships/_related_organisation_select_question.html.erb
@@ -0,0 +1,3 @@
+<% answers = question.answer_options.map { |key, value| OpenStruct.new(id: key, name: value) } %>
+<%= f.govuk_collection_select :related_organisation_id, answers, :id, :name, label: { hidden: true }, "data-controller": "accessible-autocomplete" do %>
+<% end %>
diff --git a/app/views/organisation_relationships/add_housing_provider.html.erb b/app/views/organisation_relationships/add_housing_provider.html.erb
new file mode 100644
index 000000000..638d0e00f
--- /dev/null
+++ b/app/views/organisation_relationships/add_housing_provider.html.erb
@@ -0,0 +1,36 @@
+<%= form_with model: @organisation, url: housing_providers_organisation_path, method: "post", local: true do |f| %>
+ <% if current_user.support? %>
+ <%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %>
+ <%= render SubNavigationComponent.new(items: secondary_items(request.path, @organisation.id)) %>
+
Add Housing Provider
+ <% end %>
+ <% if current_user.support? %>
+ <%= govuk_back_link(href: :back) %>
+ <%= render partial: "organisations/headings", locals: { main: "What is the name of this organisation's housing provider?", sub: nil } %>
+
Start typing to search for a housing provider
+ <% else %>
+ <% content_for :before_content do %>
+ <%= govuk_back_link(href: :back) %>
+ <% end %>
+ <%= render partial: "organisations/headings", locals: { main: "What is the name of your housing provider?", sub: nil } %>
+
Start typing to search for your housing provider
+ <% end %>
+ <% answer_options = { "" => "Select an option" } %>
+ <% @organisations.each do |organisation| %>
+ <% answer_options[organisation[0]] = organisation[1] %>
+ <% end %>
+ <%= render partial: "organisation_relationships/related_organisation_select_question", locals: {
+ question: Form::Question.new("", { "answer_options" => answer_options }, nil),
+ f:,
+ } %>
+ <%= f.govuk_submit "Add" %>
+ <%= govuk_details(summary_text: "Can't find the housing provider you're looking for?") do %>
+
+ - Double check the spelling and try again
+ - Type the first few letters to see the suggestions
+ - If you still can't find it,
+ <%= govuk_link_to("contact the DLUHC service desk", "https://digital.dclg.gov.uk/jira/servicedesk/customer/portal/4/group/21", rel: "noreferrer noopener", target: "_blank") %>
+
+
+ <% end %>
+<% end %>
diff --git a/app/views/organisation_relationships/housing_providers.html.erb b/app/views/organisation_relationships/housing_providers.html.erb
index 9f839c58f..9ff96e68d 100644
--- a/app/views/organisation_relationships/housing_providers.html.erb
+++ b/app/views/organisation_relationships/housing_providers.html.erb
@@ -1,21 +1,45 @@
<% item_label = format_label(@pagy.count, "housing providers") %>
-<% title = "Housing Providers" %>
-<% content_for :title, title %>
+
+<% if current_user.data_coordinator? %>
+ <% if params["related_organisation_id"] %>
+ <%= govuk_notification_banner(
+ title_text: "Success",
+ success: true, title_heading_level: 3,
+ title_id: "swanky-notifications"
+ ) do |notification_banner|
+ notification_banner.heading(text: "#{Organisation.find(params['related_organisation_id']).name} is now one of your housing providers")
+ end %>
+ <% end %>
+<% end %>
<% if current_user.support? %>
<%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %>
<%= render SubNavigationComponent.new(items: secondary_items(request.path, @organisation.id)) %>
Housing Providers
+ <% if params["related_organisation_id"] %>
+ <%= govuk_notification_banner(
+ title_text: "Success",
+ success: true, title_heading_level: 3,
+ title_id: "swanky-notifications"
+ ) do |notification_banner|
+ notification_banner.heading(text: "#{Organisation.find(params['related_organisation_id']).name} is now one of this organisation's housing providers")
+ end %>
+ <% end %>
This organisation can submit logs for its housing providers.
+ <% if @total_count == 0 %>
+
This organisation does not currently have any housing providers.
+ <% end %>
<% else %>
- <%= render partial: "organisations/headings", locals: { main: "Your housing providers", sub: nil } %>
+ <%= render partial: "organisations/headings", locals: { main: "Your housing providers", sub: current_user.organisation.name } %>
Your organisation can submit logs for its housing providers.
+ <% if @total_count == 0 %>
+
You do not currently have any housing providers.
+ <% end %>
<% end %>
-<% if @total_count == 0 %>
-
This organisation does not currently have any housing providers.
-<% end %>
-<% if current_user.data_coordinator? || current_user.support? %>
- <%= govuk_button_link_to "Add a housing provider", housing_providers_organisation_path(organisation_id: @organisation.id), html: { method: :get } %>
+<% if current_user.support? %>
+ <%= govuk_button_link_to "Add a housing provider", housing_providers_add_organisation_path(organisation_id: @organisation.id), html: { method: :get } %>
+ <% elsif current_user.data_coordinator? %>
+ <%= govuk_button_link_to "Add a housing provider", housing_providers_add_organisation_path, html: { method: :get } %>
<% end %>
<% if @total_count != 0 %>
<%= render SearchComponent.new(current_user:, search_label: "Search for a housing provider", value: @searched) %>
diff --git a/config/routes.rb b/config/routes.rb
index 9474c5e3f..eae1b159c 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -80,6 +80,8 @@ Rails.application.routes.draw do
get "logs/csv-confirmation", to: "lettings_logs#csv_confirmation"
get "schemes", to: "organisations#schemes"
get "housing-providers", to: "organisation_relationships#housing_providers"
+ get "housing-providers/add", to: "organisation_relationships#add_housing_provider"
+ post "housing-providers", to: "organisation_relationships#create_housing_provider"
get "managing-agents", to: "organisation_relationships#managing_agents"
end
end
diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb
index 4268785c9..2557d6cb2 100644
--- a/spec/requests/organisations_controller_spec.rb
+++ b/spec/requests/organisations_controller_spec.rb
@@ -254,7 +254,7 @@ RSpec.describe OrganisationsController, type: :request do
expect(response.body).to include(user.email)
end
- it "shows hidden accesibility fields only for active users in the current user's organisation" do
+ it "shows hidden accessibility fields only for active users in the current user's organisation" do
expected_case_row_log = "
User #{user.email}"
unauthorized_case_row_log = "
User #{other_org_user.email}"
expect(CGI.unescape_html(response.body)).to include(expected_case_row_log)
@@ -288,7 +288,7 @@ RSpec.describe OrganisationsController, type: :request 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!(:other_organisation) { FactoryBot.create(:organisation, name: "Foobar LTD 2") }
before do
FactoryBot.create(:organisation_relationship, child_organisation: organisation, parent_organisation: housing_provider, relationship_type: OrganisationRelationship.relationship_types[:owning])
@@ -319,6 +319,20 @@ RSpec.describe OrganisationsController, type: :request do
it "shows the pagination count" do
expect(page).to have_content("1 total housing providers")
end
+
+ context "when adding a housing provider" do
+ before do
+ get "/organisations/#{organisation.id}/housing-providers/add", headers:, params: {}
+ end
+
+ it "has the correct header" do
+ expect(response.body).to include("What is the name of your housing provider?")
+ end
+
+ it "shows an add button" do
+ expect(page).to have_button("Add")
+ end
+ end
end
context "with an organisation that are not in scope for the user, i.e. that they do not belong to" do
@@ -520,6 +534,34 @@ RSpec.describe OrganisationsController, type: :request do
expect { request }.not_to change(Organisation, :count)
end
end
+
+ describe "organisation_relationships#create_housing_provider" do
+ let!(:housing_provider) { FactoryBot.create(:organisation) }
+
+ let(:params) do
+ {
+ "organisation": {
+ "related_organisation_id": housing_provider.id,
+ },
+ }
+ end
+
+ let(:request) { post "/organisations/#{organisation.id}/housing-providers", headers:, params: }
+
+ it "creates a new organisation relationship" do
+ expect { request }.to change(OrganisationRelationship, :count).by(1)
+ end
+
+ it "sets the organisation relationship attributes correctly" do
+ request
+ expect(OrganisationRelationship).to exist(child_organisation_id: organisation.id, parent_organisation_id: housing_provider.id, relationship_type: OrganisationRelationship::OWNING)
+ end
+
+ it "redirects to the organisation list" do
+ request
+ expect(response).to redirect_to("/organisations/#{organisation.id}/housing-providers?related_organisation_id=#{housing_provider.id}")
+ end
+ end
end
context "with a data provider user" do
@@ -1152,6 +1194,56 @@ RSpec.describe OrganisationsController, type: :request do
end
end
+ context "when viewing a specific organisation's housing providers" 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 2") }
+
+ before do
+ FactoryBot.create(:organisation_relationship, child_organisation: organisation, parent_organisation: housing_provider, relationship_type: OrganisationRelationship.relationship_types[:owning])
+ FactoryBot.create(:organisation_relationship, child_organisation: other_organisation, parent_organisation: other_org_housing_provider, relationship_type: OrganisationRelationship.relationship_types[:owning])
+ get "/organisations/#{organisation.id}/housing-providers", headers:, params: {}
+ end
+
+ it "displays the name of the organisation" do
+ expect(page).to have_content(organisation.name)
+ end
+
+ it "has a sub-navigation with correct tabs" do
+ expect(page).to have_css(".app-sub-navigation")
+ expect(page).to have_content("Users")
+ end
+
+ it "shows a table of housing providers" do
+ expected_html = "