Browse Source

Add page content

pull/2655/head
Kat 2 years ago committed by kosiakkatrina
parent
commit
9bc8845421
  1. 16
      app/controllers/organisations_controller.rb
  2. 4
      app/policies/organisation_policy.rb
  3. 114
      app/views/organisations/duplicate_schemes.html.erb
  4. 71
      spec/requests/organisations_controller_spec.rb

16
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

4
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

114
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 %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<h1 class="govuk-heading-xl"><%= title %></h1>
<p class="govuk-body">Since your organisation recently merged, we’ve reviewed your schemes for possible duplicates.</p>
<p class="govuk-body">These sets of schemes and locations might be duplicates because they have the same answers for certain fields.</p>
<h2 class="govuk-heading-m">What you need to do</h2>
<ul class="govuk-list govuk-list--bullet">
<li>Review each set of schemes or locations and decide if they are duplicates.</li>
<li>If they are, choose one to keep and deactivate the others on the date your organisation merged.</li>
<li>When you have resolved all duplicates, confirm below.</li>
</ul>
<p class="govuk-body">If you need help with this, <%= govuk_link_to "contact the helpdesk (opens in a new tab)", GlobalConstants::HELPDESK_URL, target: "#" %>.</p>
<% if @duplicate_schemes.any? %>
<h2 class="govuk-heading-m"><%= @duplicate_schemes.count == 1 ? "This set" : "These #{@duplicate_schemes.count} sets" %> of schemes might have duplicates</h2>
<%= govuk_details(summary_text: "Why are these schemes identified as duplicates?") do %>
<p class="govuk-body">
These schemes have the same answers for the following fields:
</p>
<ul class="govuk-list govuk-list--bullet">
<li>Type of scheme</li>
<li>Registered under Care Standards Act 2000</li>
<li>Housing stock owned by</li>
<li>Support services provided by</li>
<li>Primary client group</li>
<li>Has another client group</li>
<li>Secondary client group</li>
<li>Level of support given</li>
<li>Intended length of stay</li>
</ul>
<% 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 %>
<ol class="govuk-list govuk-list--number">
<% duplicate_set.each do |scheme| %>
<li>
<%= govuk_link_to scheme.service_name, scheme %>
</li>
<% end %>
</ol>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
<% if @duplicate_locations.any? %>
<h2 class="govuk-heading-m"><%= @duplicate_locations.count == 1 ? "This set" : "These #{@duplicate_locations.count} sets" %> of locations might have duplicates</h2>
<%= govuk_details(summary_text: "Why are these locations identified as duplicates?") do %>
<p class="govuk-body">
These locations belong to the same scheme and have the same answers for the following fields:
</p>
<ul class="govuk-list govuk-list--bullet">
<li>Postcode</li>
<li>Mobility standards</li>
</ul>
<% 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 %>
<ol class="govuk-list govuk-list--number">
<% duplicate_set[:locations].each do |location| %>
<li>
<%= govuk_link_to location.name, scheme_location_path(location) %>
</li>
<% end %>
</ol>
<% end %>
<% row.with_cell do %>
<%= govuk_link_to duplicate_set[:scheme].service_name, duplicate_set[:scheme] %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
</div>
</div>

71
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) {}

Loading…
Cancel
Save