diff --git a/app/controllers/organisation_relationships_controller.rb b/app/controllers/organisation_relationships_controller.rb index d622fd17b..369c9b562 100644 --- a/app/controllers/organisation_relationships_controller.rb +++ b/app/controllers/organisation_relationships_controller.rb @@ -66,6 +66,20 @@ class OrganisationRelationshipsController < ApplicationController @resource.save! end + def remove_housing_provider + render "organisation_relationships/remove_housing_provider", layout: "application" + end + + def delete_housing_provider + organisation_relationship_to_remove_id = OrganisationRelationship.find_by(child_organisation_id: @organisation.id, parent_organisation_id: organisation_to_remove_id, relationship_type: OrganisationRelationship::OWNING).id + delete(organisation_relationship_to_remove_id) + redirect_to housing_providers_organisation_path(removed_organisation_id: organisation_to_remove_id) + end + + def delete(organisation_relationship_to_remove_id) + OrganisationRelationship.destroy(organisation_relationship_to_remove_id) + end + private def organisation @@ -76,6 +90,10 @@ private params["organisation"]["related_organisation_id"] end + def organisation_to_remove_id + params["organisation_to_remove_id"] + end + def search_term params["search"] end diff --git a/app/views/organisation_relationships/_housing_provider_list.erb b/app/views/organisation_relationships/_housing_provider_list.erb index e43766c5b..3016387a9 100644 --- a/app/views/organisation_relationships/_housing_provider_list.erb +++ b/app/views/organisation_relationships/_housing_provider_list.erb @@ -12,7 +12,7 @@ scope: "row", class: "govuk-!-text-align-right", }) do %> - <%= govuk_link_to("Remove", "housing-providers/#{housing_provider.id}") %> + <%= govuk_link_to("Remove", housing_providers_remove_organisation_path(organisation_to_remove_id: housing_provider.id)) %> <% end %> <% end %> <% end %> diff --git a/app/views/organisation_relationships/housing_providers.html.erb b/app/views/organisation_relationships/housing_providers.html.erb index 9ff96e68d..8444d9f80 100644 --- a/app/views/organisation_relationships/housing_providers.html.erb +++ b/app/views/organisation_relationships/housing_providers.html.erb @@ -10,6 +10,15 @@ notification_banner.heading(text: "#{Organisation.find(params['related_organisation_id']).name} is now one of your housing providers") end %> <% end %> + <% if params["removed_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['removed_organisation_id']).name} is no longer one of your housing providers") + end %> + <% end %> <% end %> <% if current_user.support? %> <%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %> @@ -24,6 +33,15 @@ notification_banner.heading(text: "#{Organisation.find(params['related_organisation_id']).name} is now one of this organisation's housing providers") end %> <% end %> + <% if params["removed_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['removed_organisation_id']).name} is no longer one of this organisation 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.

diff --git a/app/views/organisation_relationships/remove_housing_provider.html.erb b/app/views/organisation_relationships/remove_housing_provider.html.erb new file mode 100644 index 000000000..d173b7dbf --- /dev/null +++ b/app/views/organisation_relationships/remove_housing_provider.html.erb @@ -0,0 +1,23 @@ +<% @organisation_to_remove_id = params['organisation_to_remove_id'] %> +<%= form_with url: housing_providers_organisation_path(organisation_to_remove_id: @organisation_to_remove_id), method: "delete", 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)) %> +

Remove Housing Provider

+ <% end %> + <% @housing_provider = Organisation.find(@organisation_to_remove_id) %> + <% if current_user.support? %> + <%= govuk_back_link(href: :back) %> + <%= render partial: "organisations/headings", locals: { main: "You are removing '#{@housing_provider.name}' from this organisation's housing providers", sub: nil } %> + <% else %> + <% content_for :before_content do %> + <%= govuk_back_link(href: :back) %> + <% end %> + <%= render partial: "organisations/headings", locals: { main: "You are removing #{@housing_provider.name} from your organisation's housing providers", sub: nil } %> + <% end %> + <%= govuk_warning_text text: "You will no longer be able to submit logs for #{@housing_provider.name}" %> +
+ <%= f.govuk_submit "Confirm" %> + <%= govuk_button_link_to "Cancel", housing_providers_organisation_path(current_user.organisation), html: { method: :get }, secondary: true %> +
+<% end %> diff --git a/config/routes.rb b/config/routes.rb index eae1b159c..3efd89fcc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -81,7 +81,9 @@ Rails.application.routes.draw do get "schemes", to: "organisations#schemes" get "housing-providers", to: "organisation_relationships#housing_providers" get "housing-providers/add", to: "organisation_relationships#add_housing_provider" + get "housing-providers/remove", to: "organisation_relationships#remove_housing_provider" post "housing-providers", to: "organisation_relationships#create_housing_provider" + delete "housing-providers", to: "organisation_relationships#delete_housing_provider" get "managing-agents", to: "organisation_relationships#managing_agents" end end