Browse Source

CLDC-2081 Display merge history (#1996)

* Show details for absorbed/absorbing organisations

* Only display recent merges for absorbing org

* Display historic merges
pull/2009/head v0.3.71
kosiakkatrina 1 year ago committed by GitHub
parent
commit
873d69a933
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      app/models/organisation.rb
  2. 34
      app/views/organisations/_merged_organisation_details.html.erb
  3. 1
      app/views/organisations/show.html.erb
  4. 83
      spec/requests/organisations_controller_spec.rb

6
app/models/organisation.rb

@ -140,4 +140,10 @@ 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 recently_absorbed_organisations_grouped_by_merge_date
return unless absorbed_organisations.present? && absorbed_organisations.merged_during_open_collection_period.present?
absorbed_organisations.merged_during_open_collection_period.group_by(&:merge_date)
end
end end

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

@ -0,0 +1,34 @@
<% if @organisation.recently_absorbed_organisations_grouped_by_merge_date.present? %>
<%= govuk_details(summary_text: "View all organisations that were merged into #{@organisation.name}") do %>
<% @organisation.recently_absorbed_organisations_grouped_by_merge_date.each do |merge_date, organisations| %>
<p><strong>Merge date:</strong> <%= 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", class: "govuk-!-width-one-half" }) %>
<% row.cell(header: true, text: "Organisation ID", html_attributes: { scope: "col", class: "govuk-!-width-one-half" }) %>
<% end %>
<% end %>
<% 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 %>
<% 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">

83
spec/requests/organisations_controller_spec.rb

@ -279,6 +279,89 @@ 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!(:previously_absorbed_organisation) { create(:organisation, name: "Previously 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)
previously_absorbed_organisation.update!(merge_date: Time.zone.local(2023, 4, 2), absorbing_organisation: organisation)
get "/organisations/#{organisation.id}/details", headers:, params: {}
end
it "displays separate lists 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).to have_content("Previously Absorbed Organisation")
expect(page).to have_content("ORG#{absorbed_organisation.id}")
expect(page).to have_content("ORG#{other_absorbed_organisation.id}")
expect(page).to have_content("Merge date: 2 April 2023")
expect(page).to have_content("ORG#{previously_absorbed_organisation.id}")
end
end
context "when the organisation has absorbed other organisations during a closed collection period" 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(2021, 4, 3), absorbing_organisation: organisation)
other_absorbed_organisation.update!(merge_date: Time.zone.local(2021, 4, 3), absorbing_organisation: organisation)
get "/organisations/#{organisation.id}/details", headers:, params: {}
end
it "does not display absorbed organisations" do
expect(page).not_to have_content("View all organisations that were merged into #{organisation.name}")
expect(page).not_to have_content("Merge date: 3 April 2021")
expect(page).not_to have_content("First Absorbed Organisation")
expect(page).not_to have_content("Other Absorbed Organisation")
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