From 2642afd03637b71f6eb5a2b22d8b2c04ef7f5c49 Mon Sep 17 00:00:00 2001 From: Jack S <113976590+bibblobcode@users.noreply.github.com> Date: Wed, 2 Nov 2022 12:47:18 +0000 Subject: [PATCH] [CLDC-1660] Remove managing agent (#961) --- .../organisation_relationships_controller.rb | 23 ++++++- .../_managing_agent_list.erb | 2 +- .../managing_agents.html.erb | 21 ------- .../remove_managing_agent.html.erb | 21 +++++++ config/routes.rb | 2 + ...anisation_relationships_controller_spec.rb | 60 +++++++++++++++++++ 6 files changed, 105 insertions(+), 24 deletions(-) create mode 100644 app/views/organisation_relationships/remove_managing_agent.html.erb diff --git a/app/controllers/organisation_relationships_controller.rb b/app/controllers/organisation_relationships_controller.rb index 590e41a79..f50349d20 100644 --- a/app/controllers/organisation_relationships_controller.rb +++ b/app/controllers/organisation_relationships_controller.rb @@ -86,12 +86,31 @@ class OrganisationRelationshipsController < ApplicationController end def delete_housing_provider - organisation_relationship_to_remove = OrganisationRelationship.find_by!(child_organisation: @organisation, parent_organisation: target_organisation, relationship_type: OrganisationRelationship::OWNING) - organisation_relationship_to_remove.destroy! + relationship = OrganisationRelationship.find_by!( + child_organisation: @organisation, + parent_organisation: target_organisation, + relationship_type: OrganisationRelationship::OWNING, + ) + relationship.destroy! flash[:notice] = "#{target_organisation.name} is no longer one of #{current_user.data_coordinator? ? 'your' : "this organisation's"} housing providers" redirect_to housing_providers_organisation_path end + def remove_managing_agent + @target_organisation_id = target_organisation.id + end + + def delete_managing_agent + relationship = OrganisationRelationship.find_by!( + parent_organisation: @organisation, + child_organisation: target_organisation, + relationship_type: OrganisationRelationship::MANAGING, + ) + relationship.destroy! + flash[:notice] = "#{target_organisation.name} is no longer one of #{current_user.data_coordinator? ? 'your' : "this organisation's"} managing agents" + redirect_to managing_agents_organisation_path + end + private def create!(child_organisation:, parent_organisation:, relationship_type:) diff --git a/app/views/organisation_relationships/_managing_agent_list.erb b/app/views/organisation_relationships/_managing_agent_list.erb index 3c69bbf71..65195033c 100644 --- a/app/views/organisation_relationships/_managing_agent_list.erb +++ b/app/views/organisation_relationships/_managing_agent_list.erb @@ -12,7 +12,7 @@ scope: "row", class: "govuk-!-text-align-right", }) do %> - <%= govuk_link_to("Remove", "managing-agents/#{managing_agent.id}") %> + <%= govuk_link_to("Remove", managing_agents_remove_organisation_path(target_organisation_id: managing_agent.id)) %> <% end %> <% end %> <% end %> diff --git a/app/views/organisation_relationships/managing_agents.html.erb b/app/views/organisation_relationships/managing_agents.html.erb index db423366c..2f17f0a7e 100644 --- a/app/views/organisation_relationships/managing_agents.html.erb +++ b/app/views/organisation_relationships/managing_agents.html.erb @@ -1,32 +1,11 @@ <% item_label = format_label(@pagy.count, "managing agents") %> -<% 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 this organisation's managing agents") - 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), ) %>
A managing agent can submit logs for this organisation.
<% if @total_count == 0 %>This organisation does not currently have any managing agents.
diff --git a/app/views/organisation_relationships/remove_managing_agent.html.erb b/app/views/organisation_relationships/remove_managing_agent.html.erb new file mode 100644 index 000000000..2862acf64 --- /dev/null +++ b/app/views/organisation_relationships/remove_managing_agent.html.erb @@ -0,0 +1,21 @@ +<%= form_with url: managing_agents_organisation_path(target_organisation_id: @target_organisation.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)) %> +