Browse Source

Show details for absorbed/absorbing organisations

pull/1996/head
Kat 3 years ago
parent
commit
0a8e5be54c
  1. 16
      app/models/organisation.rb
  2. 32
      app/views/organisations/_merged_organisation_details.html.erb
  3. 1
      app/views/organisations/show.html.erb
  4. 64
      spec/requests/organisations_controller_spec.rb

16
app/models/organisation.rb

@ -33,6 +33,7 @@ class Organisation < ApplicationRecord
scope :search_by_name, ->(name) { where("name ILIKE ?", "%#{name}%") } scope :search_by_name, ->(name) { where("name ILIKE ?", "%#{name}%") }
scope :search_by, ->(param) { search_by_name(param) } scope :search_by, ->(param) { search_by_name(param) }
scope :merged_during_open_collection_period, -> { where("merge_date >= ?", FormHandler.instance.start_date_of_earliest_open_for_editing_collection_period) } scope :merged_during_open_collection_period, -> { where("merge_date >= ?", FormHandler.instance.start_date_of_earliest_open_for_editing_collection_period) }
scope :absorbed_on, ->(date) { where("merge_date = ?", date) }
has_paper_trail has_paper_trail
@ -140,4 +141,19 @@ class Organisation < ApplicationRecord
def duplicate_sales_logs_sets def duplicate_sales_logs_sets
sales_logs.duplicate_sets.map { |array_str| array_str ? array_str.map(&:to_i) : [] } sales_logs.duplicate_sets.map { |array_str| array_str ? array_str.map(&:to_i) : [] }
end end
def recent_merge_date
if merge_date.present?
merge_date
elsif absorbed_organisations.any?
absorbed_organisations.map(&:merge_date).compact.max
end
end
def recently_absorbed_organisations
return unless absorbed_organisations.any?
return absorbed_organisations if recent_merge_date.blank?
absorbed_organisations.absorbed_on(recent_merge_date)
end
end end

32
app/views/organisations/_merged_organisation_details.html.erb

@ -0,0 +1,32 @@
<% if @organisation.absorbed_organisations.any? %>
<%= govuk_details(summary_text: "View all organisations that were merged into #{@organisation.name}") do %>
<p>Merge date: <%= @organisation.recent_merge_date&.to_formatted_s(:govuk_date) %></p>
<%= govuk_table do |table| %>
<%= table.head do |head| %>
<%= head.row do |row| %>
<% row.cell(header: true, text: "Organisation name", html_attributes: { scope: "col" }) %>
<% row.cell(header: true, text: "Organisation ID", html_attributes: { scope: "col" }) %>
<% end %>
<% end %>
<% @organisation.recently_absorbed_organisations&.each do |absorbed_org| %>
<%= table.body do |body| %>
<%= body.row do |row| %>
<% if current_user.support? %>
<% row.cell(text: simple_format(govuk_link_to(absorbed_org.name, organisation_path(absorbed_org)), { class: "govuk-!-font-weight-bold scheme-name-cell" }, wrapper_tag: "div")) %>
<% else %>
<% row.cell(text: absorbed_org.name) %>
<% end %>
<% row.cell(text: "ORG#{absorbed_org.id}") %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
<% if @organisation.absorbing_organisation.present? %>
<% if current_user.support? %>
<p><%= @organisation.name %> was merged into <%= govuk_link_to(@organisation.absorbing_organisation.name, organisation_path(@organisation.absorbing_organisation)) %><%= @organisation.merge_date ? " on #{@organisation.merge_date.to_formatted_s(:govuk_date)}" : "" %>.</p>
<% else %>
<p><%= @organisation.name %> was merged into <%= @organisation.absorbing_organisation.name %><%= @organisation.merge_date ? " on #{@organisation.merge_date.to_formatted_s(:govuk_date)}" : "" %>.</p>
<% end %>
<% end %>

1
app/views/organisations/show.html.erb

@ -39,6 +39,7 @@
<% if FeatureToggle.merge_organisations_enabled? %> <% if FeatureToggle.merge_organisations_enabled? %>
<p>To report a merge or update your organisation details, <%= govuk_link_to "contact the helpdesk", "https://dluhcdigital.atlassian.net/servicedesk/customer/portal/6/group/11" %>.</p> <p>To report a merge or update your organisation details, <%= govuk_link_to "contact the helpdesk", "https://dluhcdigital.atlassian.net/servicedesk/customer/portal/6/group/11" %>.</p>
<% end %> <% end %>
<%= render partial: "organisations/merged_organisation_details" %>
</div> </div>
<div class="govuk-grid-column-one-third-from-desktop"> <div class="govuk-grid-column-one-third-from-desktop">

64
spec/requests/organisations_controller_spec.rb

@ -279,6 +279,70 @@ RSpec.describe OrganisationsController, type: :request do
expect(page).to have_content("To report a merge or update your organisation details, ") expect(page).to have_content("To report a merge or update your organisation details, ")
expect(page).to have_link("contact the helpdesk", href: "https://dluhcdigital.atlassian.net/servicedesk/customer/portal/6/group/11") expect(page).to have_link("contact the helpdesk", href: "https://dluhcdigital.atlassian.net/servicedesk/customer/portal/6/group/11")
end end
it "does not display merge history if there is none" do
expect(page).not_to have_content("View all organisations that were merged into #{organisation.name}")
end
context "when the organisation has absorbed other organisations" do
let!(:absorbed_organisation) { create(:organisation, name: "First Absorbed Organisation") }
let!(:other_absorbed_organisation) { create(:organisation, name: "Other Absorbed Organisation") }
let!(:old_absorbed_organisation) { create(:organisation, name: "Old Absorbed Organisation") }
before do
absorbed_organisation.update!(merge_date: Time.zone.local(2023, 4, 3), absorbing_organisation: organisation)
other_absorbed_organisation.update!(merge_date: Time.zone.local(2023, 4, 3), absorbing_organisation: organisation)
old_absorbed_organisation.update!(merge_date: Time.zone.local(2023, 4, 2), absorbing_organisation: organisation)
get "/organisations/#{organisation.id}/details", headers:, params: {}
end
it "displays a list of absorbed organisations" do
expect(page).to have_content("View all organisations that were merged into #{organisation.name}")
expect(page).to have_content("Merge date: 3 April 2023")
expect(page).to have_content("First Absorbed Organisation")
expect(page).to have_content("Other Absorbed Organisation")
expect(page).not_to have_content("Old Absorbed Organisation")
expect(page).to have_content("ORG#{absorbed_organisation.id}")
expect(page).to have_content("ORG#{other_absorbed_organisation.id}")
expect(page).not_to have_content("ORG#{old_absorbed_organisation.id}")
end
end
context "when the organisation has absorbed other organisations without merge dates" do
let!(:absorbed_organisation) { create(:organisation, name: "First Absorbed Organisation") }
let!(:other_absorbed_organisation) { create(:organisation, name: "Other Absorbed Organisation") }
before do
absorbed_organisation.update!(merge_date: Time.zone.local(2023, 4, 3), absorbing_organisation: organisation)
other_absorbed_organisation.update!(merge_date: Time.zone.local(2023, 4, 3), absorbing_organisation: organisation)
get "/organisations/#{organisation.id}/details", headers:, params: {}
end
it "displays a list of absorbed organisations" do
expect(page).to have_content("View all organisations that were merged into #{organisation.name}")
expect(page).to have_content("Merge date:")
expect(page).to have_content("First Absorbed Organisation")
expect(page).to have_content("Other Absorbed Organisation")
expect(page).to have_content("ORG#{absorbed_organisation.id}")
expect(page).to have_content("ORG#{other_absorbed_organisation.id}")
end
end
context "when viewing absorbed organisation" do
let(:absorbing_organisation) { create(:organisation, name: "First Absorbing Organisation") }
context "and your organisation was absorbed" do
before do
organisation.update!(merge_date: Time.zone.local(2023, 4, 3), absorbing_organisation:)
get "/organisations/#{organisation.id}/details", headers:, params: {}
end
it "displays the organisation merge details" do
expect(response).not_to have_http_status(:not_found)
expect(page).to have_content("#{organisation.name} was merged into First Absorbing Organisation on 3 April 2023.")
end
end
end
end end
context "with organisation that are not in scope for the user, i.e. that they do not belong to" do context "with organisation that are not in scope for the user, i.e. that they do not belong to" do

Loading…
Cancel
Save