From 9bc88454216d32953839460979b48f8c8f873190 Mon Sep 17 00:00:00 2001 From: Kat Date: Fri, 20 Sep 2024 15:45:29 +0100 Subject: [PATCH] Add page content --- app/controllers/organisations_controller.rb | 16 +++ app/policies/organisation_policy.rb | 4 + .../organisations/duplicate_schemes.html.erb | 114 ++++++++++++++++++ .../requests/organisations_controller_spec.rb | 71 +++++++++++ 4 files changed, 205 insertions(+) diff --git a/app/controllers/organisations_controller.rb b/app/controllers/organisations_controller.rb index 044bab74d..c6bc5888e 100644 --- a/app/controllers/organisations_controller.rb +++ b/app/controllers/organisations_controller.rb @@ -44,6 +44,22 @@ class OrganisationsController < ApplicationController redirect_to schemes_csv_confirmation_organisation_path end + def duplicate_schemes + authorize @organisation + + duplicate_scheme_sets = @organisation.owned_schemes.duplicate_sets + @duplicate_schemes = duplicate_scheme_sets.map { |set| set.map { |id| @organisation.owned_schemes.find(id) } } + @duplicate_locations = [] + @organisation.owned_schemes.each do |scheme| + duplicate_location_sets = scheme.locations.duplicate_sets + next unless duplicate_location_sets.any? + + duplicate_location_sets.each do |duplicate_set| + @duplicate_locations << { scheme: scheme, locations: duplicate_set.map { |id| scheme.locations.find(id) } } + end + end + end + def show redirect_to details_organisation_path(@organisation) end diff --git a/app/policies/organisation_policy.rb b/app/policies/organisation_policy.rb index 9c27d6e91..97fd4582e 100644 --- a/app/policies/organisation_policy.rb +++ b/app/policies/organisation_policy.rb @@ -34,4 +34,8 @@ class OrganisationPolicy editable_sales_logs = organisation.sales_logs.visible.after_date(editable_from_date) organisation.sales_logs.visible.where(saledate: nil).any? || editable_sales_logs.any? end + + def duplicate_schemes? + user.support? || (user.data_coordinator? && user.organisation == organisation) + end end diff --git a/app/views/organisations/duplicate_schemes.html.erb b/app/views/organisations/duplicate_schemes.html.erb index e69de29bb..d002f2989 100644 --- a/app/views/organisations/duplicate_schemes.html.erb +++ b/app/views/organisations/duplicate_schemes.html.erb @@ -0,0 +1,114 @@ +<% content_for :before_content do %> + <%= govuk_back_link href: schemes_organisation_path(@organisation) %> +<% end %> + +<% title = "Review these sets of schemes and locations" %> +<% content_for :title, title %> + +<% if current_user.support? %> + <%= render SubNavigationComponent.new( + items: secondary_items(request.path, @organisation.id), + ) %> +<% end %> + +
+
+

<%= title %>

+ +

Since your organisation recently merged, we’ve reviewed your schemes for possible duplicates.

+

These sets of schemes and locations might be duplicates because they have the same answers for certain fields.

+

What you need to do

+
    +
  • Review each set of schemes or locations and decide if they are duplicates.
  • +
  • If they are, choose one to keep and deactivate the others on the date your organisation merged.
  • +
  • When you have resolved all duplicates, confirm below.
  • +
+

If you need help with this, <%= govuk_link_to "contact the helpdesk (opens in a new tab)", GlobalConstants::HELPDESK_URL, target: "#" %>.

+ + <% if @duplicate_schemes.any? %> +

<%= @duplicate_schemes.count == 1 ? "This set" : "These #{@duplicate_schemes.count} sets" %> of schemes might have duplicates

+ + <%= govuk_details(summary_text: "Why are these schemes identified as duplicates?") do %> +

+ These schemes have the same answers for the following fields: +

+
    +
  • Type of scheme
  • +
  • Registered under Care Standards Act 2000
  • +
  • Housing stock owned by
  • +
  • Support services provided by
  • +
  • Primary client group
  • +
  • Has another client group
  • +
  • Secondary client group
  • +
  • Level of support given
  • +
  • Intended length of stay
  • +
+ <% end %> + + <%= govuk_table do |table| %> + <%= table.with_head do |head| %> + <% head.with_row do |row| %> + <% row.with_cell(header: true, text: "Schemes") %> + <% end %> + + <%= table.with_body do |body| %> + <% @duplicate_schemes.each do |duplicate_set| %> + <% body.with_row do |row| %> + <% row.with_cell do %> +
    + <% duplicate_set.each do |scheme| %> +
  1. + <%= govuk_link_to scheme.service_name, scheme %> +
  2. + <% end %> +
+ <% end %> + <% end %> + <% end %> + <% end %> + <% end %> + <% end %> + <% end %> + + <% if @duplicate_locations.any? %> +

<%= @duplicate_locations.count == 1 ? "This set" : "These #{@duplicate_locations.count} sets" %> of locations might have duplicates

+ <%= govuk_details(summary_text: "Why are these locations identified as duplicates?") do %> +

+ These locations belong to the same scheme and have the same answers for the following fields: +

+
    +
  • Postcode
  • +
  • Mobility standards
  • +
+ <% end %> + + <%= govuk_table do |table| %> + <%= table.with_head do |head| %> + <% head.with_row do |row| %> + <% row.with_cell(header: true, text: "Locations") %> + <% row.with_cell(header: true, text: "Scheme") %> + <% end %> + + <%= table.with_body do |body| %> + <% @duplicate_locations.each do |duplicate_set| %> + <% body.with_row do |row| %> + <% row.with_cell do %> +
    + <% duplicate_set[:locations].each do |location| %> +
  1. + <%= govuk_link_to location.name, scheme_location_path(location) %> +
  2. + <% end %> +
+ <% end %> + <% row.with_cell do %> + <%= govuk_link_to duplicate_set[:scheme].service_name, duplicate_set[:scheme] %> + <% end %> + <% end %> + <% end %> + <% end %> + <% end %> + <% end %> + <% end %> +
+
diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index 50ec7fab5..8f62e72a8 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/spec/requests/organisations_controller_spec.rb @@ -366,6 +366,77 @@ RSpec.describe OrganisationsController, type: :request do end end + describe "#duplicate_schemes" do + context "with support user" do + let(:user) { create(:user, :support) } + + before do + allow(user).to receive(:need_two_factor_authentication?).and_return(false) + sign_in user + get "/organisations/#{organisation.id}/schemes/duplicates", headers: + end + + it "has page heading" do + expect(page).to have_content("Review these sets of schemes and locations") + end + + context "with duplicate schemes and locations" do + let(:schemes) { create_list(:scheme, 5, :duplicate, owning_organisation: organisation) } + + before do + create_list(:location, 2, scheme: schemes.first, postcode: "M1 1AA", mobility_type: "M") + create_list(:location, 2, scheme: schemes.first, postcode: "M1 1AA", mobility_type: "A") + get "/organisations/#{organisation.id}/schemes/duplicates", headers: + end + + it "displays the duplicate schemes" do + expect(page).to have_content("This set of schemes might have duplicates") + end + + it "displays the duplicate locations" do + expect(page).to have_content("These 2 sets of locations might have duplicates") + end + end + + context "without duplicate schemes and locations" do + it "does not display the schemes" do + expect(page).not_to have_content("schemes might have duplicates") + end + + it "does not display the locations" do + expect(page).not_to have_content("locations might have duplicates") + end + end + end + + context "with data coordinator user" do + let(:user) { create(:user, :data_coordinator) } + let!(:schemes) { create_list(:scheme, 5, :duplicate) } + + before do + sign_in user + get "/organisations/#{organisation.id}/schemes/duplicates", headers: + end + + it "has page heading" do + expect(page).to have_content("Review these sets of schemes and locations") + end + end + + context "with data coordinator user" do + let(:user) { create(:user, :data_provider) } + + before do + sign_in user + get "/organisations/#{organisation.id}/schemes/duplicates", headers: + end + + it "be unauthorised" do + expect(response).to have_http_status(:unauthorized) + end + end + end + describe "#show" do context "with an organisation that the user belongs to" do let(:set_time) {}