Browse Source

[CLDC-1660] Remove managing agent (#961)

pull/965/head
Jack S 2 years ago committed by GitHub
parent
commit
2642afd036
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 23
      app/controllers/organisation_relationships_controller.rb
  2. 2
      app/views/organisation_relationships/_managing_agent_list.erb
  3. 21
      app/views/organisation_relationships/managing_agents.html.erb
  4. 21
      app/views/organisation_relationships/remove_managing_agent.html.erb
  5. 2
      config/routes.rb
  6. 60
      spec/requests/organisation_relationships_controller_spec.rb

23
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:)

2
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 %>

21
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),
) %>
<h2 class="govuk-visually-hidden">Managing Agents</h2>
<% 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 %>
<p class="govuk-body">A managing agent can submit logs for this organisation.</p>
<% if @total_count == 0 %>
<p class="govuk-body">This organisation does not currently have any managing agents.</p>

21
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)) %>
<h2 class="govuk-visually-hidden">Remove Managing Agent</h2>
<% end %>
<% if current_user.support? %>
<%= govuk_back_link(href: :back) %>
<%= render partial: "organisations/headings", locals: { main: "You are removing ‘#{@target_organisation.name}’ from this organisation's managing agents", sub: nil } %>
<% else %>
<% content_for :before_content do %>
<%= govuk_back_link(href: :back) %>
<% end %>
<%= render partial: "organisations/headings", locals: { main: "You are removing ‘#{@target_organisation.name}’ from your organisation's managing agents", sub: nil } %>
<% end %>
<%= govuk_warning_text text: "#{@target_organisation.name} will no longer be able to submit logs for you" %>
<div class="govuk-button-group">
<%= f.govuk_submit "Confirm" %>
<%= govuk_button_link_to "Cancel", managing_agents_organisation_path(current_user.organisation), html: { method: :get }, secondary: true %>
</div>
<% end %>

2
config/routes.rb

@ -86,7 +86,9 @@ Rails.application.routes.draw do
delete "housing-providers", to: "organisation_relationships#delete_housing_provider"
get "managing-agents", to: "organisation_relationships#managing_agents"
get "managing-agents/add", to: "organisation_relationships#add_managing_agent"
get "managing-agents/remove", to: "organisation_relationships#remove_managing_agent"
post "managing-agents", to: "organisation_relationships#create_managing_agent"
delete "managing-agents", to: "organisation_relationships#delete_managing_agent"
end
end

60
spec/requests/organisation_relationships_controller_spec.rb

@ -212,6 +212,34 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
expect(response).to redirect_to("/organisations/#{organisation.id}/housing-providers")
end
end
describe "organisation_relationships#delete_managing_agent" do
let!(:managing_agent) { FactoryBot.create(:organisation) }
let(:params) do
{
"target_organisation_id": managing_agent.id,
}
end
let(:request) { delete "/organisations/#{organisation.id}/managing-agents", headers:, params: }
before do
FactoryBot.create(
:organisation_relationship,
:managing,
parent_organisation: organisation,
child_organisation: managing_agent,
)
end
it "deletes the new organisation relationship" do
expect { request }.to change(OrganisationRelationship, :count).by(-1)
end
it "redirects to the organisation list" do
request
expect(response).to redirect_to("/organisations/#{organisation.id}/managing-agents")
end
end
end
context "with a data provider user" do
@ -415,6 +443,34 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
end
end
describe "organisation_relationships#delete_managing_agent" do
let!(:managing_agent) { FactoryBot.create(:organisation) }
let(:params) do
{
"target_organisation_id": managing_agent.id,
}
end
let(:request) { delete "/organisations/#{organisation.id}/managing-agents", headers:, params: }
before do
FactoryBot.create(
:organisation_relationship,
:managing,
parent_organisation: organisation,
child_organisation: managing_agent,
)
end
it "deletes the new organisation relationship" do
expect { request }.to change(OrganisationRelationship, :count).by(-1)
end
it "redirects to the organisation list" do
request
expect(response).to redirect_to("/organisations/#{organisation.id}/managing-agents")
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") }
@ -504,6 +560,10 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
expect(page).to have_content("1 total agents")
end
it "shows remove link(s)" do
expect(response.body).to include("Remove")
end
context "when adding a housing provider" do
before do
get "/organisations/#{organisation.id}/managing-agents/add", headers:, params: {}

Loading…
Cancel
Save