Browse Source
* CLDC-2093 Merge organisations page - view all merge requests (#2561) * CLDC-3585 Update absorbing organisation question (#2564) * Update user permissions and absorbing org question order * Update absorbing organisation question and routing * CLDC 2094: View a merge request (#2565) * CLDC-3584 Update merging orgs question (#2567) * Update merging organisations question * Update rebase tests * Update routing between CYA and questions * CLDC-3586 Update merge date merge request question (#2571) * Remove unused paths and update merge date * lint * Create delete merge request functionality (#2568) * CLDC-3588: Add helpdesk ticket question (#2572) * Merge request fixes (#2578) * Add cancel button to merging orgs and update merging orgs selection * Update submit button text * Update back buttons * CLDC-2101 Add begin merge (#2575) * Calculate merge request status * Add start merge and merge request job * Update merge request when it gets processed * Refactor and display a banner for failed requests * update test * Update change links * Update copy for error message (#2583) * Do not display cancel button if there's no submit (#2584) * Update hint date (#2588) * CLDC-2100++ Add success notification after delete (#2589) * Update helpdesk_ticket.html.erb * CLDC-2094++ Merge details page adjustments (#2593) * Change page name and hide buttons during processing status * Update test * Make merge request status dynamic (#2592) * Make merge request status dynamic * Update tests * Keep check answers referrer when validation is hit (#2594) * Keep check answers referrer when validation is hit * Remove absorbing org from merging organisations list * Update text to handle singular merge requests * Add merge start confirmation page (#2601) * Set merge request as non processing if it fails (#2598) * Set merge request to no longer processing if it fails * clear last_failed_attempt as soon as we start processing the merge * CLDC-3603 View merged users outcomes (#2602) * Update user outcomes view link * Add user outcomes page * Set user outcomes before merge and on merge fail * Update hardcoded total user count * Account for singular user numbers * CLDC-3603 View scheme outcomes (#2604) * Update scheme outcomes view link * Add scheme outcomes page * Update scheme outcome before merge and on merge fail * Update back links in merge outcomes pages (#2611) * CLDC-3605 View relationships page (#2606) * CLDC-3609 Add existing absorbing organisation merge request question (#2600) * Add existing absorbing organisation page and field * Update status calculation and add new question to check answers * Call correct merge service flow * Update test * Update test * Return correct status when existing_absorbing_organisation is false (#2617) * Change styling of relationship outcomes page (#2619) * CLDC-3604 View logs outcomes (#2618) * Update view logs outcomes link * Add logs outcomes page * Set logs outcome before merge and on merge fail * Update logs outcomes text * Update line break * Fix incorrect filtering of relationships and count * Fix test * Fix test * Fix test * Make example date depend on collection year (#2620) --------- Co-authored-by: Manny Dinssa <44172848+Dinssa@users.noreply.github.com>pull/2626/head^2
kosiakkatrina
5 months ago
committed by
GitHub
58 changed files with 2573 additions and 721 deletions
@ -0,0 +1,35 @@ |
|||||||
|
document.addEventListener('DOMContentLoaded', function () { |
||||||
|
const urlParams = new URLSearchParams(window.location.search) |
||||||
|
let tab = urlParams.get('tab') |
||||||
|
|
||||||
|
if (!tab && window.location.hash) { |
||||||
|
tab = window.location.hash.substring(1) |
||||||
|
urlParams.set('tab', tab) |
||||||
|
window.history.replaceState(null, null, `${window.location.pathname}?${urlParams.toString()}`) |
||||||
|
} |
||||||
|
function activateTab (tabId) { |
||||||
|
const tabElement = document.getElementById(tabId) |
||||||
|
if (tabElement) { |
||||||
|
tabElement.click() |
||||||
|
} |
||||||
|
window.history.replaceState(null, null, `${window.location.pathname}?${urlParams.toString()}`) |
||||||
|
} |
||||||
|
|
||||||
|
function handleTabClick (event) { |
||||||
|
event.preventDefault() |
||||||
|
const targetId = this.getAttribute('href').substring(1) |
||||||
|
activateTab(targetId) |
||||||
|
urlParams.set('tab', targetId) |
||||||
|
window.history.replaceState(null, null, `${window.location.pathname}?${urlParams.toString()}`) |
||||||
|
} |
||||||
|
|
||||||
|
if (tab) { |
||||||
|
activateTab(`tab_${tab}`) |
||||||
|
} |
||||||
|
|
||||||
|
window.scrollTo(0, 0) |
||||||
|
|
||||||
|
document.querySelectorAll('.govuk-tabs__tab').forEach(tabElement => { |
||||||
|
tabElement.addEventListener('click', handleTabClick) |
||||||
|
}) |
||||||
|
}) |
@ -0,0 +1,279 @@ |
|||||||
|
module MergeRequestsHelper |
||||||
|
include GovukLinkHelper |
||||||
|
include GovukVisuallyHiddenHelper |
||||||
|
|
||||||
|
def display_value_or_placeholder(value, placeholder = "You didn't answer this question") |
||||||
|
value.presence || content_tag(:span, placeholder, class: "app-!-colour-muted") |
||||||
|
end |
||||||
|
|
||||||
|
def request_details(merge_request) |
||||||
|
[ |
||||||
|
{ label: "Requester", value: display_value_or_placeholder(merge_request.requester&.name) }, |
||||||
|
{ label: "Helpdesk ticket", value: merge_request.helpdesk_ticket.present? ? link_to("#{merge_request.helpdesk_ticket} (opens in a new tab)", "https://dluhcdigital.atlassian.net/browse/#{merge_request.helpdesk_ticket}", target: "_blank", rel: "noopener noreferrer") : display_value_or_placeholder(nil), action: merge_request_action(merge_request, "helpdesk_ticket") }, |
||||||
|
{ label: "Status", value: status_tag(merge_request.status) }, |
||||||
|
] |
||||||
|
end |
||||||
|
|
||||||
|
def merge_details(merge_request) |
||||||
|
[ |
||||||
|
{ label: "Absorbing organisation", value: display_value_or_placeholder(merge_request.absorbing_organisation_name), action: merge_request_action(merge_request, "absorbing_organisation") }, |
||||||
|
{ label: "Merging organisations", value: merge_request.merge_request_organisations.any? ? merge_request.merge_request_organisations.map(&:merging_organisation_name).join("<br>").html_safe : display_value_or_placeholder(nil), action: merge_request_action(merge_request, "merging_organisations") }, |
||||||
|
{ label: "Merge date", value: display_value_or_placeholder(merge_request.merge_date), action: merge_request_action(merge_request, "merge_date") }, |
||||||
|
{ label: "Absorbing organisation already active?", value: display_value_or_placeholder(merge_request.existing_absorbing_organisation_label), action: merge_request_action(merge_request, "existing_absorbing_organisation") }, |
||||||
|
] |
||||||
|
end |
||||||
|
|
||||||
|
def merge_outcomes(merge_request) |
||||||
|
[ |
||||||
|
{ label: "Total users after merge", value: display_value_or_placeholder(merge_request.total_users_label), action: merge_outcome_action(merge_request, "user_outcomes") }, |
||||||
|
{ label: "Total schemes after merge", value: display_value_or_placeholder(merge_request.total_schemes_label), action: merge_outcome_action(merge_request, "scheme_outcomes") }, |
||||||
|
{ label: "Total logs after merge", value: display_value_or_placeholder(merge_request.total_logs_label), action: merge_outcome_action(merge_request, "logs_outcomes") }, |
||||||
|
{ label: "Total stock owners & managing agents after merge", value: display_value_or_placeholder(merge_request.total_stock_owners_managing_agents_label), action: merge_outcome_action(merge_request, "relationship_outcomes") }, |
||||||
|
] |
||||||
|
end |
||||||
|
|
||||||
|
def ordered_merging_organisations(merge_request, new_merging_org_ids) |
||||||
|
Organisation.where(id: new_merging_org_ids) + merge_request.merge_request_organisations.order(created_at: :desc).map(&:merging_organisation) |
||||||
|
end |
||||||
|
|
||||||
|
def submit_merge_request_button_text(referrer) |
||||||
|
if accessed_from_check_answers?(referrer) |
||||||
|
"Save changes" |
||||||
|
else |
||||||
|
"Save and continue" |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
def secondary_merge_request_link_text(referrer, skip_for_now: false) |
||||||
|
if accessed_from_check_answers?(referrer) |
||||||
|
"Cancel" |
||||||
|
elsif skip_for_now |
||||||
|
"Skip for now" |
||||||
|
else |
||||||
|
"" |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
def accessed_from_check_answers?(referrer) |
||||||
|
%w[check_answers].include?(referrer) |
||||||
|
end |
||||||
|
|
||||||
|
def merge_request_back_link(merge_request, page, referrer) |
||||||
|
return merge_request_path(merge_request) if accessed_from_check_answers?(referrer) |
||||||
|
|
||||||
|
case page |
||||||
|
when "absorbing_organisation" |
||||||
|
organisations_path(tab: "merge-requests") |
||||||
|
when "merging_organisations" |
||||||
|
absorbing_organisation_merge_request_path(merge_request) |
||||||
|
when "merge_date" |
||||||
|
merging_organisations_merge_request_path(merge_request) |
||||||
|
when "existing_absorbing_organisation" |
||||||
|
merge_date_merge_request_path(merge_request) |
||||||
|
when "helpdesk_ticket" |
||||||
|
existing_absorbing_organisation_merge_request_path(merge_request) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
def merge_request_action(merge_request, page) |
||||||
|
unless merge_request.status == "request_merged" || merge_request.status == "processing" |
||||||
|
{ text: "Change", href: send("#{page}_merge_request_path", merge_request, referrer: "check_answers"), visually_hidden_text: page.humanize } |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
def merge_outcome_action(merge_request, page) |
||||||
|
unless merge_request.status == "request_merged" || merge_request.status == "processing" |
||||||
|
{ text: "View", href: send("#{page}_merge_request_path", merge_request), visually_hidden_text: page.humanize } |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
def submit_merge_request_url(referrer) |
||||||
|
referrer == "check_answers" ? merge_request_path(referrer: "check_answers") : merge_request_path |
||||||
|
end |
||||||
|
|
||||||
|
def merging_organisations_without_users_text(organisations) |
||||||
|
return "" unless organisations.count.positive? |
||||||
|
|
||||||
|
if organisations.count == 1 |
||||||
|
"#{organisations.first.name} has no users." |
||||||
|
else |
||||||
|
"#{organisations.map(&:name).to_sentence} have no users." |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
def link_to_merging_organisation_users(organisation) |
||||||
|
count_text = organisation.users.count == 1 ? "1 #{organisation.name} user" : "all #{organisation.users.count} #{organisation.name} users" |
||||||
|
govuk_link_to "View #{count_text} (opens in a new tab)", users_organisation_path(organisation), target: "_blank" |
||||||
|
end |
||||||
|
|
||||||
|
def total_users_after_merge_text(merge_request) |
||||||
|
count = merge_request.total_visible_users_after_merge |
||||||
|
"#{"#{count} user".pluralize(count)} after merge" |
||||||
|
end |
||||||
|
|
||||||
|
def total_stock_owners_after_merge_text(merge_request) |
||||||
|
count = merge_request.total_stock_owners_after_merge |
||||||
|
"#{"#{count} stock owner".pluralize(count)} after merge" |
||||||
|
end |
||||||
|
|
||||||
|
def total_managing_agents_after_merge_text(merge_request) |
||||||
|
count = merge_request.total_managing_agents_after_merge |
||||||
|
"#{"#{count} managing agent".pluralize(count)} after merge" |
||||||
|
end |
||||||
|
|
||||||
|
def related_organisations(merge_request, relationship_type) |
||||||
|
organisations = merge_request.absorbing_organisation.send(relationship_type.pluralize).visible + merge_request.merging_organisations.flat_map { |org| org.send(relationship_type.pluralize).visible } |
||||||
|
organisations += [merge_request.absorbing_organisation] + merge_request.merging_organisations |
||||||
|
organisations.group_by { |relationship| relationship }.select { |_, occurrences| occurrences.size > 1 }.keys |
||||||
|
end |
||||||
|
|
||||||
|
def related_organisations_text(merge_request, relationship_type) |
||||||
|
if related_organisations(merge_request, relationship_type).any? |
||||||
|
"Some of the organisations merging have common #{relationship_type.humanize(capitalize: false).pluralize}.<br><br>" |
||||||
|
else |
||||||
|
"" |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
def organisations_without_relationships(merge_request, relationship_type) |
||||||
|
([merge_request.absorbing_organisation] + merge_request.merging_organisations).select { |org| org.send(relationship_type.pluralize).visible.empty? } |
||||||
|
end |
||||||
|
|
||||||
|
def organisations_without_relationships_text(organisations_without_relationships, relationship_type) |
||||||
|
return "" unless organisations_without_relationships.any? |
||||||
|
|
||||||
|
org_names = organisations_without_relationships.map(&:name).to_sentence |
||||||
|
verb = organisations_without_relationships.count > 1 ? "have" : "has" |
||||||
|
"#{org_names} #{verb} no #{relationship_type.humanize(capitalize: false).pluralize}.<br><br>" |
||||||
|
end |
||||||
|
|
||||||
|
def generate_organisation_link_text(organisation_count, org, relationship_type) |
||||||
|
"View #{organisation_count == 1 ? 'the' : 'all'} #{organisation_count} #{org.name} #{relationship_type.humanize(capitalize: false).pluralize(organisation_count)} (opens in a new tab)" |
||||||
|
end |
||||||
|
|
||||||
|
def relationship_text(merge_request, relationship_type, organisation_path_helper) |
||||||
|
text = "" |
||||||
|
organisations_without_relationships = organisations_without_relationships(merge_request, relationship_type) |
||||||
|
|
||||||
|
text += related_organisations_text(merge_request, relationship_type) |
||||||
|
text += organisations_without_relationships_text(organisations_without_relationships, relationship_type) |
||||||
|
|
||||||
|
([merge_request.absorbing_organisation] + merge_request.merging_organisations).each do |org| |
||||||
|
organisation_count = org.send(relationship_type.pluralize).visible.count |
||||||
|
next if organisation_count.zero? |
||||||
|
|
||||||
|
link_text = generate_organisation_link_text(organisation_count, org, relationship_type) |
||||||
|
text += "#{govuk_link_to(link_text, send(organisation_path_helper, org), target: '_blank')}<br><br>" |
||||||
|
end |
||||||
|
|
||||||
|
text.html_safe |
||||||
|
end |
||||||
|
|
||||||
|
def stock_owners_text(merge_request) |
||||||
|
relationship_text(merge_request, "stock_owner", :stock_owners_organisation_path) |
||||||
|
end |
||||||
|
|
||||||
|
def managing_agent_text(merge_request) |
||||||
|
relationship_text(merge_request, "managing_agent", :managing_agents_organisation_path) |
||||||
|
end |
||||||
|
|
||||||
|
def merging_organisations_without_schemes_text(organisations) |
||||||
|
return "" unless organisations.count.positive? |
||||||
|
|
||||||
|
if organisations.count == 1 |
||||||
|
"#{organisations.first.name} has no schemes." |
||||||
|
else |
||||||
|
"#{organisations.map(&:name).to_sentence} have no schemes." |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
def link_to_merging_organisation_schemes(organisation) |
||||||
|
count_text = organisation.owned_schemes.count == 1 ? "1 #{organisation.name} scheme" : "all #{organisation.owned_schemes.count} #{organisation.name} schemes" |
||||||
|
govuk_link_to "View #{count_text} (opens in a new tab)", schemes_organisation_path(organisation), target: "_blank" |
||||||
|
end |
||||||
|
|
||||||
|
def total_schemes_after_merge_text(merge_request) |
||||||
|
count = merge_request.total_visible_schemes_after_merge |
||||||
|
"#{"#{count} scheme".pluralize(count)} after merge" |
||||||
|
end |
||||||
|
|
||||||
|
def total_lettings_logs_after_merge_text(merge_request) |
||||||
|
count = merge_request.total_visible_lettings_logs_after_merge |
||||||
|
"#{"#{count} lettings log".pluralize(count)} after merge" |
||||||
|
end |
||||||
|
|
||||||
|
def total_sales_logs_after_merge_text(merge_request) |
||||||
|
count = merge_request.total_visible_sales_logs_after_merge |
||||||
|
"#{"#{count} sales log".pluralize(count)} after merge" |
||||||
|
end |
||||||
|
|
||||||
|
def merging_organisations_lettings_logs_outcomes_text(merge_request) |
||||||
|
merging_organisations_logs_outcomes_text(merge_request, "lettings") |
||||||
|
end |
||||||
|
|
||||||
|
def merging_organisations_sales_logs_outcomes_text(merge_request) |
||||||
|
merging_organisations_logs_outcomes_text(merge_request, "sales") |
||||||
|
end |
||||||
|
|
||||||
|
def merging_organisations_logs_outcomes_text(merge_request, type) |
||||||
|
text = "" |
||||||
|
if any_organisations_have_logs?(merge_request.merging_organisations, type) |
||||||
|
managed_or_reported = type == "lettings" ? "managed" : "reported" |
||||||
|
merging_organisations = merge_request.merging_organisations.count == 1 ? "merging organisation" : "merging organisations" |
||||||
|
text += "#{merge_request.absorbing_organisation.name} users will have access to all #{type} logs owned or #{managed_or_reported} by the #{merging_organisations} after the merge.<br><br>" |
||||||
|
|
||||||
|
if any_organisations_have_logs_after_merge_date?(merge_request.merging_organisations, type, merge_request.merge_date) |
||||||
|
startdate = type == "lettings" ? "tenancy start date" : "sale completion date" |
||||||
|
text += "#{type.capitalize} logs that are owned or #{managed_or_reported} by the #{merging_organisations} and have a #{startdate} after the merge date will have their owning or managing organisation changed to #{merge_request.absorbing_organisation.name}.<br><br>" |
||||||
|
end |
||||||
|
|
||||||
|
if any_organisations_share_logs?(merge_request.merging_organisations, type) |
||||||
|
text += "Some logs are owned and #{managed_or_reported} by different organisations in this merge. They appear in the list for both the owning and the managing organisation.<br><br>" |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
organisations_without_logs, organisations_with_logs = merge_request.merging_organisations.partition { |organisation| organisation.send("#{type}_logs").count.zero? } |
||||||
|
if merge_request.absorbing_organisation.send("#{type}_logs").count.zero? |
||||||
|
organisations_without_logs = [merge_request.absorbing_organisation] + organisations_without_logs |
||||||
|
else |
||||||
|
organisations_with_logs = [merge_request.absorbing_organisation] + organisations_with_logs |
||||||
|
end |
||||||
|
|
||||||
|
if organisations_without_logs.any? |
||||||
|
text += "#{organisations_without_logs.map(&:name).to_sentence} #{organisations_without_logs.count == 1 ? 'has' : 'have'} no #{type} logs.<br><br>" |
||||||
|
end |
||||||
|
|
||||||
|
organisations_with_logs.each do |organisation| |
||||||
|
text += "#{link_to_merging_organisation_logs(organisation, type)}<br><br>" |
||||||
|
end |
||||||
|
|
||||||
|
text.html_safe |
||||||
|
end |
||||||
|
|
||||||
|
def link_to_merging_organisation_logs(organisation, type) |
||||||
|
count_text = organisation.send("#{type}_logs").count == 1 ? "1 #{organisation.name} #{type} log" : "all #{organisation.send("#{type}_logs").count} #{organisation.name} #{type} logs" |
||||||
|
govuk_link_to "View #{count_text} (opens in a new tab)", send("#{type}_logs_organisation_path", organisation), target: "_blank" |
||||||
|
end |
||||||
|
|
||||||
|
def lettings_logs_outcomes_header_text(merge_request) |
||||||
|
count = merge_request.total_visible_lettings_logs_after_merge |
||||||
|
"#{count} #{'lettings log'.pluralize(count)} after merge" |
||||||
|
end |
||||||
|
|
||||||
|
def sales_logs_outcomes_header_text(merge_request) |
||||||
|
count = merge_request.total_visible_sales_logs_after_merge |
||||||
|
"#{count} #{'sales log'.pluralize(count)} after merge" |
||||||
|
end |
||||||
|
|
||||||
|
def any_organisations_have_logs?(organisations, type) |
||||||
|
organisations.any? { |organisation| organisation.send("#{type}_logs").count.positive? } |
||||||
|
end |
||||||
|
|
||||||
|
def any_organisations_have_logs_after_merge_date?(organisations, type, merge_date) |
||||||
|
organisations.any? { |organisation| organisation.send("#{type}_logs").after_date(merge_date).exists? } |
||||||
|
end |
||||||
|
|
||||||
|
def any_organisations_share_logs?(organisations, type) |
||||||
|
organisations.any? { |organisation| organisation.send("#{type}_logs").filter_by_managing_organisation(organisations.where.not(id: organisation.id)).exists? } |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,15 @@ |
|||||||
|
class ProcessMergeRequestJob < ApplicationJob |
||||||
|
queue_as :default |
||||||
|
|
||||||
|
def perform(merge_request:) |
||||||
|
absorbing_organisation_id = merge_request.absorbing_organisation_id |
||||||
|
merging_organisation_ids = merge_request.merging_organisations.pluck(:id) |
||||||
|
merge_date = merge_request.merge_date |
||||||
|
absorbing_organisation_active_from_merge_date = !merge_request.existing_absorbing_organisation unless merge_request.existing_absorbing_organisation.nil? |
||||||
|
|
||||||
|
Merge::MergeOrganisationsService.new(absorbing_organisation_id:, merging_organisation_ids:, merge_date:, absorbing_organisation_active_from_merge_date:).call |
||||||
|
merge_request.update!(request_merged: true, last_failed_attempt: nil) |
||||||
|
rescue StandardError |
||||||
|
merge_request.set_back_to_ready_to_merge! |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,33 @@ |
|||||||
|
<%= govuk_summary_list do |summary_list| %> |
||||||
|
<% details.each do |detail| %> |
||||||
|
<% summary_list.with_row do |row| %> |
||||||
|
<% row.with_key { detail[:label] } %> |
||||||
|
|
||||||
|
<% row.with_value do %> |
||||||
|
<% if detail[:value].html_safe? %> |
||||||
|
<div class="govuk-!-margin-left-8 govuk-!-margin-right-4"> |
||||||
|
<%= raw(detail[:value]) %> |
||||||
|
</div> |
||||||
|
<% elsif detail[:value].is_a?(Date) || detail[:value].is_a?(Time) %> |
||||||
|
<div class="govuk-!-margin-left-8 govuk-!-margin-right-4"> |
||||||
|
<%= detail[:value].strftime("%d %B %Y") %> |
||||||
|
</div> |
||||||
|
<% else %> |
||||||
|
<%= simple_format( |
||||||
|
detail[:value], |
||||||
|
wrapper_tag: "span", |
||||||
|
class: "govuk-!-margin-left-8 govuk-!-margin-right-4", |
||||||
|
) %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
|
||||||
|
<% if detail[:action].present? %> |
||||||
|
<% row.with_action( |
||||||
|
text: detail[:action][:text], |
||||||
|
href: detail[:action][:href], |
||||||
|
visually_hidden_text: detail[:action][:visually_hidden_text], |
||||||
|
) %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
@ -0,0 +1,46 @@ |
|||||||
|
<section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>"> |
||||||
|
<% if @merge_requests.empty? %> |
||||||
|
<p>No merge requests</p> |
||||||
|
<% else %> |
||||||
|
<%= govuk_table do |table| %> |
||||||
|
<%= table.with_caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do %> |
||||||
|
<strong><%= @merge_requests.not_merged.count %></strong> unresolved merge <%= @merge_requests.not_merged.count == 1 ? "request" : "requests" %> |
||||||
|
<% end %> |
||||||
|
<%= table.with_head do |head| %> |
||||||
|
<%= head.with_row do |row| %> |
||||||
|
<% row.with_cell(header: true, text: "Absorbing organisation", html_attributes: { |
||||||
|
scope: "col", |
||||||
|
}) %> |
||||||
|
<% row.with_cell(header: true, text: "Merge date", html_attributes: { |
||||||
|
scope: "col", |
||||||
|
}) %> |
||||||
|
<% row.with_cell(header: true, text: "Status", html_attributes: { |
||||||
|
scope: "col", |
||||||
|
}) %> |
||||||
|
<% row.with_cell(header: true, text: "", html_attributes: { |
||||||
|
scope: "col", |
||||||
|
}) %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
<% @merge_requests.each do |merge_request| %> |
||||||
|
<%= table.with_body do |body| %> |
||||||
|
<%= body.with_row do |row| %> |
||||||
|
<%= row.with_cell(html_attributes: { scope: "row" }) do %> |
||||||
|
<%= display_value_or_placeholder(merge_request.absorbing_organisation_name) %> |
||||||
|
<% end %> |
||||||
|
<% merge_date = merge_request.merge_date %> |
||||||
|
<%= row.with_cell(html_attributes: { scope: "row" }) do %> |
||||||
|
<%= display_value_or_placeholder(merge_date&.strftime("%d %B %Y")) %> |
||||||
|
<% end %> |
||||||
|
<% row.with_cell(text: status_tag(merge_request.status)) %> |
||||||
|
<% row.with_cell(html_attributes: { |
||||||
|
scope: "row", |
||||||
|
}) do %> |
||||||
|
<%= govuk_link_to("View details", merge_request_path(merge_request.id)) %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
</section> |
@ -0,0 +1,21 @@ |
|||||||
|
<% unless @merge_request.absorbing_organisation_signed_dsa? || @merge_request.absorbing_organisation_id.blank? %> |
||||||
|
<%= govuk_notification_banner(title_text: "Important") do %> |
||||||
|
<p class="govuk-notification-banner__heading govuk-!-width-full" style="max-width: fit-content"> |
||||||
|
The absorbing organisation must accept the Data Sharing Agreement before merging. |
||||||
|
</p> |
||||||
|
<% if @merge_request.dpo_user %> |
||||||
|
Contact the Data Protection Officer: <%= link_to @merge_request.dpo_user.name, user_path(@merge_request.dpo_user.id) %> |
||||||
|
<% else %> |
||||||
|
<%= @merge_request.absorbing_organisation_name %> does not have a Data Protection Officer. You can assign one on the <%= link_to "users page", "#{organisation_path(@merge_request.absorbing_organisation_id)}/users" %>. |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
|
||||||
|
<% if @merge_request.last_failed_attempt.present? %> |
||||||
|
<%= govuk_notification_banner(title_text: "Important") do %> |
||||||
|
<p class="govuk-notification-banner__heading govuk-!-width-full" style="max-width: fit-content"> |
||||||
|
An error occurred while processing the merge. |
||||||
|
</p> |
||||||
|
No changes have been made. Try beginning the merge again. |
||||||
|
<% end %> |
||||||
|
<% end %> |
@ -0,0 +1,8 @@ |
|||||||
|
<div class="govuk-summary-card govuk-!-margin-bottom-6 govuk-!-width-three-quarters"> |
||||||
|
<div class="govuk-summary-card__title-wrapper"> |
||||||
|
<h3 class="govuk-summary-card__title govuk-!-font-weight-regular"><%= title %></h3> |
||||||
|
</div> |
||||||
|
<div class="govuk-summary-card__content"> |
||||||
|
<%= render partial: "merge_requests/details_list", locals: { details: } %> |
||||||
|
</div> |
||||||
|
</div> |
@ -1,36 +1,34 @@ |
|||||||
<% content_for :before_content do %> |
<% content_for :before_content do %> |
||||||
<% title = "Tell us if your organisation is merging" %> |
<% title = "Tell us if your organisation is merging" %> |
||||||
<% content_for :title, title %> |
<% content_for :title, title %> |
||||||
<%= govuk_back_link href: organisations_merge_request_path(id: @merge_request) %> |
<%= govuk_back_link href: merge_request_back_link(@merge_request, "absorbing_organisation", request.query_parameters["referrer"]) %> |
||||||
<% end %> |
<% end %> |
||||||
|
|
||||||
<%= form_with model: @merge_request, url: merge_request_path, method: :patch do |f| %> |
<%= form_with model: @merge_request, url: submit_merge_request_url(request.query_parameters["referrer"]), method: :patch do |f| %> |
||||||
<%= f.govuk_error_summary %> |
<%= f.govuk_error_summary %> |
||||||
|
|
||||||
<h2 class="govuk-heading-l">Which organisation is absorbing the others?</h2> |
<h1 class="govuk-heading-l">Which organisation is absorbing the others?</h1> |
||||||
<div class="govuk-grid-row"> |
<div class="govuk-grid-row"> |
||||||
<div class="govuk-grid-column-two-thirds-from-desktop"> |
<div class="govuk-grid-column-two-thirds-from-desktop"> |
||||||
<p class="govuk-body">Select the organisation that the other organisations are merging into.</p> |
<p class="govuk-hint">If organisations are merging into a new organisation, <%= govuk_link_to "create the new organisation", new_organisation_path %> first and then select it here.</p> |
||||||
|
<br> |
||||||
<%= f.govuk_radio_buttons_fieldset( |
<%= f.govuk_select(:absorbing_organisation_id, |
||||||
:absorbing_organisation_id, |
label: { text: "Select organisation name", class: "govuk-label--m" }, |
||||||
hint: { text: "For example, if Skype and Yammer merged into Microsoft, you would select Microsoft." }, |
"data-controller": "accessible-autocomplete") do %> |
||||||
legend: nil, |
<% @answer_options.map { |id, name| OpenStruct.new(id:, name:) }.each do |answer| %> |
||||||
) do %> |
<option value="<%= answer.id %>" |
||||||
<% @merge_request.merging_organisations.order(:name).each do |org| %> |
data-synonyms="<%= answer_option_synonyms(answer.resource) %>" |
||||||
<%= f.govuk_radio_button( |
data-append="<%= answer_option_append(answer.resource) %>" |
||||||
:absorbing_organisation_id, |
data-hint="<%= answer_option_hint(answer.resource) %>" |
||||||
org.id, |
<%= @merge_request.absorbing_organisation_id == answer.id ? "selected" : "" %>><%= answer.name || answer.resource %></option> |
||||||
label: { text: org.name }, |
<% end %> |
||||||
) %> |
|
||||||
<% end %> |
<% end %> |
||||||
<%= f.govuk_radio_divider %> |
|
||||||
<%= f.govuk_radio_button :absorbing_organisation_id, "other", checked: @merge_request.new_absorbing_organisation?, label: { text: "These organisations are merging into a new one" } %> |
|
||||||
<% end %> |
|
||||||
|
|
||||||
<%= f.hidden_field :page, value: "absorbing_organisation" %> |
<%= f.hidden_field :page, value: "absorbing_organisation" %> |
||||||
|
<div class="govuk-button-group"> |
||||||
<%= f.govuk_submit %> |
<%= f.govuk_submit submit_merge_request_button_text(request.query_parameters["referrer"]) %> |
||||||
|
<%= govuk_link_to(secondary_merge_request_link_text(request.query_parameters["referrer"]), merge_request_path(@merge_request)) %> |
||||||
|
</div> |
||||||
<% end %> |
<% end %> |
||||||
</div> |
</div> |
||||||
</div> |
</div> |
||||||
|
@ -1,41 +0,0 @@ |
|||||||
<% content_for :before_content do %> |
|
||||||
<% title = "Tell us if your organisation is merging" %> |
|
||||||
<% content_for :title, title %> |
|
||||||
<%= govuk_back_link href: absorbing_organisation_merge_request_path(id: @merge_request) %> |
|
||||||
<% end %> |
|
||||||
|
|
||||||
<%= form_with model: @merge_request, url: merge_request_path, method: :patch do |f| %> |
|
||||||
<%= f.govuk_error_summary %> |
|
||||||
|
|
||||||
<h2 class="govuk-heading-l">What is <%= @merge_request.absorbing_organisation.name %>'s telephone number?</h2> |
|
||||||
|
|
||||||
<div class="govuk-grid-row"> |
|
||||||
<div class="govuk-grid-column-two-thirds-from-desktop"> |
|
||||||
<% if @merge_request.absorbing_organisation.phone.present? %> |
|
||||||
<p class="govuk-body">Confirm the telephone number on file, or enter a new one.</p> |
|
||||||
<div class="govuk-inset-text"> |
|
||||||
<%= @merge_request.absorbing_organisation.phone %> |
|
||||||
</div> |
|
||||||
<% end %> |
|
||||||
|
|
||||||
<% if @merge_request.absorbing_organisation.phone.present? %> |
|
||||||
<%= f.govuk_radio_buttons_fieldset(:telephone_number_correct, legend: nil) do %> |
|
||||||
<%= f.govuk_radio_button :telephone_number_correct, true, checked: @merge_request.telephone_number_correct?, label: { text: "This telephone number is correct" }, link_errors: true %> |
|
||||||
<%= f.govuk_radio_button( |
|
||||||
:telephone_number_correct, |
|
||||||
false, |
|
||||||
checked: (@merge_request.new_telephone_number.present? || @merge_request.errors.key?(:new_telephone_number)), |
|
||||||
label: { text: "Enter a new phone number" }, |
|
||||||
) do %> |
|
||||||
<%= f.govuk_text_field :new_telephone_number, label: { text: "Telephone number" }, width: "two-thirds" %> |
|
||||||
<% end %> |
|
||||||
<%= f.hidden_field :page, value: "confirm_telephone_number" %> |
|
||||||
<% end %> |
|
||||||
<% else %> |
|
||||||
<%= f.govuk_text_field :new_telephone_number, label: nil, width: "two-thirds" %> |
|
||||||
<%= f.hidden_field :page, value: "confirm_telephone_number" %> |
|
||||||
<% end %> |
|
||||||
<%= f.govuk_submit %> |
|
||||||
<% end %> |
|
||||||
</div> |
|
||||||
</div> |
|
@ -0,0 +1,23 @@ |
|||||||
|
<% content_for :before_content do %> |
||||||
|
<% content_for :title, "Are you sure you want to delete this merge request?" %> |
||||||
|
<%= govuk_back_link(href: :back) %> |
||||||
|
<% end %> |
||||||
|
|
||||||
|
<div class="govuk-grid-row"> |
||||||
|
<div class="govuk-grid-column-two-thirds-from-desktop"> |
||||||
|
<h1 class="govuk-heading-xl"> |
||||||
|
<%= content_for(:title) %> |
||||||
|
</h1> |
||||||
|
|
||||||
|
<%= govuk_warning_text(text: "You will not be able to undo this action.") %> |
||||||
|
|
||||||
|
<div class="govuk-button-group"> |
||||||
|
<%= govuk_button_to( |
||||||
|
"Delete merge request", |
||||||
|
delete_merge_request_path(@merge_request), |
||||||
|
method: :delete, |
||||||
|
) %> |
||||||
|
<%= govuk_button_link_to "Cancel", merge_request_path(@merge_request), secondary: true %> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</div> |
@ -0,0 +1,27 @@ |
|||||||
|
<% content_for :before_content do %> |
||||||
|
<% title = "Tell us if your organisation is merging" %> |
||||||
|
<% content_for :title, title %> |
||||||
|
<%= govuk_back_link href: merge_request_back_link(@merge_request, "existing_absorbing_organisation", request.query_parameters["referrer"]) %> |
||||||
|
<% end %> |
||||||
|
<div class="govuk-grid-row"> |
||||||
|
<div class="govuk-grid-column-two-thirds-from-desktop"> |
||||||
|
<%= form_with model: @merge_request, url: submit_merge_request_url(request.query_parameters["referrer"]), method: :patch do |f| %> |
||||||
|
<%= f.govuk_error_summary %> |
||||||
|
<%= f.govuk_radio_buttons_fieldset :existing_absorbing_organisation, |
||||||
|
legend: { text: "Was #{@merge_request.absorbing_organisation&.name} already active before the merge date?", size: "l" } do %> |
||||||
|
<%= f.govuk_radio_button :existing_absorbing_organisation, |
||||||
|
"true", |
||||||
|
label: { text: "Yes, this organisation existed before the merge" } %> |
||||||
|
<%= f.govuk_radio_button :existing_absorbing_organisation, |
||||||
|
"false", |
||||||
|
label: { text: "No, it is a new organisation created by this merge" } %> |
||||||
|
<% end %> |
||||||
|
|
||||||
|
<%= f.hidden_field :page, value: "existing_absorbing_organisation" %> |
||||||
|
<div class="govuk-button-group"> |
||||||
|
<%= f.govuk_submit submit_merge_request_button_text(request.query_parameters["referrer"]) %> |
||||||
|
<%= govuk_link_to(secondary_merge_request_link_text(request.query_parameters["referrer"]), merge_request_path(@merge_request)) %> |
||||||
|
</div> |
||||||
|
<% end %> |
||||||
|
</div> |
||||||
|
</div> |
@ -0,0 +1,27 @@ |
|||||||
|
<% content_for :before_content do %> |
||||||
|
<% title = "Which helpdesk ticket reported this merge?" %> |
||||||
|
<% content_for :title, title %> |
||||||
|
<%= govuk_back_link href: merge_request_back_link(@merge_request, "helpdesk_ticket", request.query_parameters["referrer"]) %> |
||||||
|
<% end %> |
||||||
|
|
||||||
|
<%= form_with model: @merge_request, url: submit_merge_request_url(request.query_parameters["referrer"]), method: :patch do |f| %> |
||||||
|
<%= f.govuk_error_summary %> |
||||||
|
|
||||||
|
<h1 class="govuk-heading-l">Which helpdesk ticket reported this merge?</h1> |
||||||
|
<div class="govuk-grid-row"> |
||||||
|
<div class="govuk-grid-column-two-thirds-from-desktop"> |
||||||
|
<p class="govuk-hint">If this merge was reported via a helpdesk ticket, provide the ticket number.<br>The ticket will be linked to the merge request for reference.</p> |
||||||
|
<br> |
||||||
|
<div class="govuk-grid-row"> |
||||||
|
<div class="govuk-grid-column-two-thirds-from-desktop"> |
||||||
|
<%= f.govuk_text_field :helpdesk_ticket, caption: { text: "Ticket number", class: "govuk-label govuk-label--s" }, label: { text: "For example, MSD-12345", class: "app-!-colour-muted" } %> |
||||||
|
<%= f.hidden_field :page, value: "helpdesk_ticket" %> |
||||||
|
<div class="govuk-button-group"> |
||||||
|
<%= f.govuk_submit submit_merge_request_button_text(request.query_parameters["referrer"]) %> |
||||||
|
<%= govuk_link_to(secondary_merge_request_link_text(request.query_parameters["referrer"], skip_for_now: true), merge_request_path(@merge_request)) %> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
<% end %> |
||||||
|
</div> |
||||||
|
</div> |
@ -0,0 +1,27 @@ |
|||||||
|
<% content_for :before_content do %> |
||||||
|
<% title = "Users" %> |
||||||
|
<% content_for :title, title %> |
||||||
|
<%= govuk_back_link href: merge_request_path(@merge_request) %> |
||||||
|
<% end %> |
||||||
|
|
||||||
|
<h1 class="govuk-heading-l"> |
||||||
|
<span class="govuk-caption-l"><%= @merge_request.absorbing_organisation_name %></span> |
||||||
|
Logs |
||||||
|
</h1> |
||||||
|
<div class="govuk-grid-row"> |
||||||
|
<div class="govuk-grid-column-two-thirds"> |
||||||
|
<% unless @merge_request.status == "request_merged" || @merge_request.status == "processing" %> |
||||||
|
<h2 class="govuk-heading-m"><%= total_lettings_logs_after_merge_text(@merge_request) %></h2> |
||||||
|
<p class="govuk-body"> |
||||||
|
<%= merging_organisations_lettings_logs_outcomes_text(@merge_request) %> |
||||||
|
</p> |
||||||
|
|
||||||
|
<hr class="govuk-section-break govuk-section-break--m govuk-section-break--visible govuk-!-margin-bottom-7 govuk-!-width-three-quarters "> |
||||||
|
|
||||||
|
<h2 class="govuk-heading-m"><%= total_sales_logs_after_merge_text(@merge_request) %></h2> |
||||||
|
<p class="govuk-body"> |
||||||
|
<%= merging_organisations_sales_logs_outcomes_text(@merge_request) %> |
||||||
|
</p> |
||||||
|
<% end %> |
||||||
|
</div> |
||||||
|
</div> |
@ -1,8 +1,26 @@ |
|||||||
<% content_for :before_content do %> |
<% content_for :before_content do %> |
||||||
<% title = "Tell us if your organisation is merging" %> |
<% title = "Tell us if your organisation is merging" %> |
||||||
<% content_for :title, title %> |
<% content_for :title, title %> |
||||||
<%# TODO: Update this backlink to also work with the create org flow %> |
<%= govuk_back_link href: merge_request_back_link(@merge_request, "merge_date", request.query_parameters["referrer"]) %> |
||||||
<%= govuk_back_link href: confirm_telephone_number_merge_request_path(@merge_request) %> |
|
||||||
<% end %> |
<% end %> |
||||||
|
<div class="govuk-grid-row"> |
||||||
|
<div class="govuk-grid-column-two-thirds-from-desktop"> |
||||||
|
<%= form_with model: @merge_request, url: submit_merge_request_url(request.query_parameters["referrer"]), method: :patch do |f| %> |
||||||
|
<%= f.govuk_error_summary %> |
||||||
|
|
||||||
<h2 class="govuk-heading-l">What is the merge date?</h2> |
<h2 class="govuk-heading-l">What is the merge date?</h2> |
||||||
|
<p class="govuk-hint"> |
||||||
|
Enter the official merge date. Log and organisation page data will show the new organisation name from this date. <br><br> |
||||||
|
For example, <%= date_mid_collection_year_formatted(Time.zone.now) %></p> |
||||||
|
<%= f.govuk_date_field :merge_date, |
||||||
|
legend: { hidden: true }, |
||||||
|
width: 20 do %> |
||||||
|
<% end %> |
||||||
|
<%= f.hidden_field :page, value: "merge_date" %> |
||||||
|
<div class="govuk-button-group"> |
||||||
|
<%= f.govuk_submit submit_merge_request_button_text(request.query_parameters["referrer"]) %> |
||||||
|
<%= govuk_link_to(secondary_merge_request_link_text(request.query_parameters["referrer"]), merge_request_path(@merge_request)) %> |
||||||
|
</div> |
||||||
|
<% end %> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
@ -0,0 +1,27 @@ |
|||||||
|
<% content_for :before_content do %> |
||||||
|
<% content_for :title, "Are you sure you want to begin this merge?" %> |
||||||
|
<%= govuk_back_link href: merge_request_path(@merge_request) %> |
||||||
|
<% end %> |
||||||
|
|
||||||
|
<div class="govuk-grid-row"> |
||||||
|
<div class="govuk-grid-column-two-thirds-from-desktop"> |
||||||
|
<h1 class="govuk-heading-xl"> |
||||||
|
<%= content_for(:title) %> |
||||||
|
</h1> |
||||||
|
|
||||||
|
<%= govuk_warning_text(text: "You will not be able to undo this action.") %> |
||||||
|
|
||||||
|
<div class="govuk-button-group"> |
||||||
|
<%= govuk_button_to( |
||||||
|
"Begin merge", |
||||||
|
start_merge_merge_request_path(@merge_request), |
||||||
|
method: :patch, |
||||||
|
) %> |
||||||
|
<%= govuk_button_link_to( |
||||||
|
"Cancel", |
||||||
|
merge_request_path(@merge_request), |
||||||
|
secondary: true, |
||||||
|
) %> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</div> |
@ -0,0 +1,50 @@ |
|||||||
|
<% content_for :before_content do %> |
||||||
|
<% title = "Tell us if your organisation is merging" %> |
||||||
|
<% content_for :title, title %> |
||||||
|
<%= govuk_back_link href: merge_request_back_link(@merge_request, "merging_organisations", request.query_parameters["referrer"]) %> |
||||||
|
<% end %> |
||||||
|
|
||||||
|
<%= form_with model: @merge_request, url: merging_organisations_merge_request_path(referrer: request.query_parameters["referrer"]), method: :patch do |f| %> |
||||||
|
<%= f.govuk_error_summary %> |
||||||
|
<h2 class="govuk-heading-l">Which organisations are merging into <%= @merge_request.absorbing_organisation&.name %>?</h2> |
||||||
|
|
||||||
|
<div class="govuk-grid-row"> |
||||||
|
<div class="govuk-grid-column-two-thirds-from-desktop"> |
||||||
|
<p class="govuk-hint">Add all organisations that are merging.</p> |
||||||
|
<br> |
||||||
|
<%= render partial: "organisation_relationships/related_organisation_select_question", locals: { |
||||||
|
label: { text: "Select an organisation", class: "govuk-label--m" }, |
||||||
|
field: :merging_organisation, |
||||||
|
question: Form::Question.new("", { "answer_options" => @answer_options.reject { |id, _org_name| id != "" && id == @merge_request.absorbing_organisation_id } }, nil), |
||||||
|
f:, |
||||||
|
} %> |
||||||
|
<%= f.hidden_field :new_merging_org_ids, value: @new_merging_org_ids %> |
||||||
|
<%= f.govuk_submit "Add organisation", secondary: true, classes: "govuk-button--secondary" %> |
||||||
|
<%= govuk_table do |table| %> |
||||||
|
<% ordered_merging_organisations(@merge_request, @new_merging_org_ids).each do |merging_organisation| %> |
||||||
|
<%= table.with_body do |body| %> |
||||||
|
<%= body.with_row do |row| %> |
||||||
|
<% row.with_cell(text: merging_organisation.name) %> |
||||||
|
<% row.with_cell(html_attributes: { |
||||||
|
scope: "row", |
||||||
|
class: "govuk-!-text-align-right", |
||||||
|
}) do %> |
||||||
|
<%= govuk_link_to("Remove", merging_organisations_remove_merge_request_path(merge_request: { merging_organisation: merging_organisation.id, new_merging_org_ids: @new_merging_org_ids })) %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
<%= form_with model: @merge_request, url: merge_request_path(id: @merge_request.id), method: :patch do |f| %> |
||||||
|
<%= f.hidden_field :page, value: "merging_organisations" %> |
||||||
|
<%= f.hidden_field :new_merging_org_ids, value: @new_merging_org_ids %> |
||||||
|
<div class="govuk-button-group"> |
||||||
|
<% if @merge_request.merging_organisations.count.positive? || @new_merging_org_ids.count.positive? %> |
||||||
|
<%= f.govuk_submit submit_merge_request_button_text(request.query_parameters["referrer"]) %> |
||||||
|
<%= govuk_link_to secondary_merge_request_link_text(request.query_parameters["referrer"]), merge_request_path(@merge_request) %> |
||||||
|
<% end %> |
||||||
|
</div> |
||||||
|
<% end %> |
||||||
|
</div> |
||||||
|
</div> |
@ -1,33 +0,0 @@ |
|||||||
<% content_for :before_content do %> |
|
||||||
<% title = "New organisation address" %> |
|
||||||
<% content_for :title, title %> |
|
||||||
<%= govuk_back_link href: new_organisation_name_merge_request_path(@merge_request) %> |
|
||||||
<% end %> |
|
||||||
|
|
||||||
<%= form_with model: @merge_request, url: merge_request_path, method: :patch do |f| %> |
|
||||||
<%= f.govuk_error_summary %> |
|
||||||
|
|
||||||
<h2 class="govuk-heading-l">What is <%= @merge_request.new_organisation_name.possessive %> address?</h2> |
|
||||||
<div class="govuk-grid-row"> |
|
||||||
<div class="govuk-grid-column-two-thirds-from-desktop"> |
|
||||||
<%= f.govuk_text_field :new_organisation_address_line1, |
|
||||||
label: { text: "Address line 1", size: "m" }, |
|
||||||
autocomplete: "address-line1" %> |
|
||||||
|
|
||||||
<%= f.govuk_text_field :new_organisation_address_line2, |
|
||||||
label: { text: "Address line 2", size: "m" }, |
|
||||||
autocomplete: "address-line2" %> |
|
||||||
|
|
||||||
<%= f.govuk_text_field :new_organisation_postcode, |
|
||||||
label: { text: "Postcode", size: "m" }, |
|
||||||
autocomplete: "postal-code", |
|
||||||
width: 10 %> |
|
||||||
|
|
||||||
<%= f.hidden_field :page, value: "new_organisation_address" %> |
|
||||||
<div class="govuk-button-group"> |
|
||||||
<%= f.govuk_submit %> |
|
||||||
<%= govuk_link_to("Skip for now", new_organisation_telephone_number_merge_request_path(@merge_request)) %> |
|
||||||
</div> |
|
||||||
</div> |
|
||||||
</div> |
|
||||||
<% end %> |
|
@ -1,19 +0,0 @@ |
|||||||
<% content_for :before_content do %> |
|
||||||
<% title = "New organisation name" %> |
|
||||||
<% content_for :title, title %> |
|
||||||
<%= govuk_back_link href: absorbing_organisation_merge_request_path(id: @merge_request) %> |
|
||||||
<% end %> |
|
||||||
|
|
||||||
<%= form_with model: @merge_request, url: merge_request_path, method: :patch do |f| %> |
|
||||||
<%= f.govuk_error_summary %> |
|
||||||
|
|
||||||
<h2 class="govuk-heading-l">What is the new organisation called?</h2> |
|
||||||
|
|
||||||
<div class="govuk-grid-row"> |
|
||||||
<div class="govuk-grid-column-two-thirds-from-desktop"> |
|
||||||
<%= f.govuk_text_field :new_organisation_name, label: nil %> |
|
||||||
<%= f.hidden_field :page, value: "new_organisation_name" %> |
|
||||||
<%= f.govuk_submit %> |
|
||||||
<% end %> |
|
||||||
</div> |
|
||||||
</div> |
|
@ -1,20 +0,0 @@ |
|||||||
<% content_for :before_content do %> |
|
||||||
<% title = "New organisation telephone number" %> |
|
||||||
<% content_for :title, title %> |
|
||||||
<%= govuk_back_link href: new_organisation_address_merge_request_path(@merge_request) %> |
|
||||||
<% end %> |
|
||||||
|
|
||||||
<%= form_with model: @merge_request, url: merge_request_path, method: :patch do |f| %> |
|
||||||
<%= f.govuk_error_summary %> |
|
||||||
|
|
||||||
<h2 class="govuk-heading-l">What is <%= @merge_request.new_organisation_name.possessive %> telephone number?</h2> |
|
||||||
<div class="govuk-grid-row"> |
|
||||||
<div class="govuk-grid-column-two-thirds-from-desktop"> |
|
||||||
<%= f.govuk_text_field :new_organisation_telephone_number, label: nil, width: "two-thirds" %> |
|
||||||
<%= f.hidden_field :page, value: "new_organisation_telephone_number" %> |
|
||||||
<div class="govuk-button-group"> |
|
||||||
<%= f.govuk_submit %> |
|
||||||
</div> |
|
||||||
</div> |
|
||||||
</div> |
|
||||||
<% end %> |
|
@ -1,5 +0,0 @@ |
|||||||
<% content_for :before_content do %> |
|
||||||
<% title = "New organisation type" %> |
|
||||||
<% content_for :title, title %> |
|
||||||
<%= govuk_back_link href: new_organisation_telephone_number_merge_request_path(@merge_request) %> |
|
||||||
<% end %> |
|
@ -1,51 +0,0 @@ |
|||||||
<% content_for :before_content do %> |
|
||||||
<% title = "Tell us if your organisation is merging" %> |
|
||||||
<% content_for :title, title %> |
|
||||||
<%= govuk_back_link href: merge_request_organisation_path(id: @merge_request.requesting_organisation_id) %> |
|
||||||
<% end %> |
|
||||||
|
|
||||||
<%= form_with model: @merge_request, url: organisations_merge_request_path, method: :patch do |f| %> |
|
||||||
<%= f.govuk_error_summary %> |
|
||||||
<h2 class="govuk-heading-l">Which organisations are merging?</h2> |
|
||||||
|
|
||||||
<div class="govuk-grid-row"> |
|
||||||
<div class="govuk-grid-column-two-thirds-from-desktop"> |
|
||||||
<p class="govuk-body"> |
|
||||||
Add all organisations to be merged - we have already added your own. |
|
||||||
</p> |
|
||||||
|
|
||||||
<p class="govuk-body">Start typing to search</p> |
|
||||||
<%= render partial: "organisation_relationships/related_organisation_select_question", locals: { |
|
||||||
field: :merging_organisation, |
|
||||||
question: Form::Question.new("", { "answer_options" => @answer_options }, nil), |
|
||||||
f:, |
|
||||||
} %> |
|
||||||
<%= f.govuk_submit "Add organisation", classes: "govuk-button--secondary" %> |
|
||||||
<%= govuk_table do |table| %> |
|
||||||
<% @merge_request.merging_organisations.order(:name).each do |merging_organisation| %> |
|
||||||
<%= table.with_body do |body| %> |
|
||||||
<%= body.with_row do |row| %> |
|
||||||
<% row.with_cell(text: merging_organisation.name) %> |
|
||||||
<% row.with_cell(html_attributes: { |
|
||||||
scope: "row", |
|
||||||
class: "govuk-!-text-align-right", |
|
||||||
}) do %> |
|
||||||
<% if @merge_request.requesting_organisation != merging_organisation %> |
|
||||||
<%= govuk_link_to("Remove", organisations_remove_merge_request_path(merge_request: { merging_organisation: merging_organisation.id })) %> |
|
||||||
<% end %> |
|
||||||
<% end %> |
|
||||||
<% end %> |
|
||||||
<% end %> |
|
||||||
<% end %> |
|
||||||
<% end %> |
|
||||||
<% end %> |
|
||||||
<%= form_with model: @merge_request, url: merge_request_path(id: @merge_request.id), method: :patch do |f| %> |
|
||||||
<%= govuk_details(summary_text: "I cannot find an organisation on the list") do %> |
|
||||||
<%= f.govuk_text_area :other_merging_organisations, label: { text: "Other organisations" }, hint: { text: "List other organisations that are part of the merge but not registered on CORE." }, rows: 9 %> |
|
||||||
<% end %> |
|
||||||
<% if @merge_request.merging_organisations.count > 1 %> |
|
||||||
<%= f.hidden_field :page, value: "organisations" %> |
|
||||||
<%= f.govuk_submit "Continue" %> |
|
||||||
<% end %> |
|
||||||
<% end %> |
|
||||||
</div> |
|
@ -0,0 +1,25 @@ |
|||||||
|
<% content_for :before_content do %> |
||||||
|
<% title = "Stock owners & managing agents".html_safe %> |
||||||
|
<% content_for :title, title %> |
||||||
|
<%= govuk_back_link href: merge_request_path(@merge_request) %> |
||||||
|
<% end %> |
||||||
|
|
||||||
|
<h1 class="govuk-heading-l"> |
||||||
|
<span class="govuk-caption-l"><%= @merge_request.absorbing_organisation_name %></span> |
||||||
|
Stock owners & managing agents |
||||||
|
</h1> |
||||||
|
<div class="govuk-grid-row"> |
||||||
|
<div class="govuk-grid-column-two-thirds"> |
||||||
|
<% unless @merge_request.status == "request_merged" || @merge_request.status == "processing" %> |
||||||
|
<h2 class="govuk-heading-m"><%= total_stock_owners_after_merge_text(@merge_request) %></h2> |
||||||
|
<p class="govuk-body"> |
||||||
|
<%= stock_owners_text(@merge_request) %> |
||||||
|
</p> |
||||||
|
<hr class="govuk-section-break govuk-section-break--m govuk-section-break--visible govuk-!-margin-bottom-7 govuk-!-width-three-quarters "> |
||||||
|
<h2 class="govuk-heading-m"><%= total_managing_agents_after_merge_text(@merge_request) %></h2> |
||||||
|
<p class="govuk-body"> |
||||||
|
<%= managing_agent_text(@merge_request) %> |
||||||
|
</p> |
||||||
|
<% end %> |
||||||
|
</div> |
||||||
|
</div> |
@ -0,0 +1,23 @@ |
|||||||
|
<% content_for :before_content do %> |
||||||
|
<% title = "Schemes" %> |
||||||
|
<% content_for :title, title %> |
||||||
|
<%= govuk_back_link href: merge_request_path(@merge_request) %> |
||||||
|
<% end %> |
||||||
|
|
||||||
|
<h1 class="govuk-heading-l"> |
||||||
|
<span class="govuk-caption-l"><%= @merge_request.absorbing_organisation_name %></span> |
||||||
|
Schemes |
||||||
|
</h1> |
||||||
|
|
||||||
|
<% unless @merge_request.status == "request_merged" || @merge_request.status == "processing" %> |
||||||
|
<h2 class="govuk-heading-m"><%= total_schemes_after_merge_text(@merge_request) %></h2> |
||||||
|
<p class="govuk-body"> |
||||||
|
<%= merging_organisations_without_schemes_text(@merge_request.organisations_without_schemes) %> |
||||||
|
</p> |
||||||
|
|
||||||
|
<% @merge_request.organisations_with_schemes.map do |org| %> |
||||||
|
<p class="govuk-body"> |
||||||
|
<%= link_to_merging_organisation_schemes(org) %> |
||||||
|
</p> |
||||||
|
<% end %> |
||||||
|
<% end %> |
@ -0,0 +1,26 @@ |
|||||||
|
<% content_for :before_content do %> |
||||||
|
<% title = "Merge request: #{@merge_request.absorbing_organisation_name}" %> |
||||||
|
<% content_for :title, title %> |
||||||
|
<%= govuk_back_link href: organisations_path(tab: "merge-requests") %> |
||||||
|
<% end %> |
||||||
|
|
||||||
|
<%= render partial: "notification_banners" %> |
||||||
|
|
||||||
|
<h1 class="govuk-heading-l"> |
||||||
|
<span class="govuk-caption-l">Merge request</span> |
||||||
|
<%= display_value_or_placeholder(@merge_request.absorbing_organisation_name) %> |
||||||
|
</h1> |
||||||
|
<% unless @merge_request.status == "request_merged" || @merge_request.status == "processing" %> |
||||||
|
<div class="govuk-button-group"> |
||||||
|
<%= govuk_button_link_to "Begin merge", merge_start_confirmation_merge_request_path(@merge_request), disabled: @merge_request.status != "ready_to_merge" %> |
||||||
|
<%= govuk_button_link_to "Delete merge request", delete_confirmation_merge_request_path(@merge_request), warning: true %> |
||||||
|
</div> |
||||||
|
<% end %> |
||||||
|
|
||||||
|
<%= render partial: "merge_requests/summary_card", locals: { title: "Request details", details: request_details(@merge_request) } %> |
||||||
|
|
||||||
|
<%= render partial: "merge_requests/summary_card", locals: { title: "Merge details", details: merge_details(@merge_request) } %> |
||||||
|
|
||||||
|
<% unless @merge_request.status == "incomplete" %> |
||||||
|
<%= render partial: "merge_requests/summary_card", locals: { title: "Merge outcomes", details: merge_outcomes(@merge_request) } %> |
||||||
|
<% end %> |
@ -0,0 +1,23 @@ |
|||||||
|
<% content_for :before_content do %> |
||||||
|
<% title = "Users" %> |
||||||
|
<% content_for :title, title %> |
||||||
|
<%= govuk_back_link href: merge_request_path(@merge_request) %> |
||||||
|
<% end %> |
||||||
|
|
||||||
|
<h1 class="govuk-heading-l"> |
||||||
|
<span class="govuk-caption-l"><%= @merge_request.absorbing_organisation_name %></span> |
||||||
|
Users |
||||||
|
</h1> |
||||||
|
|
||||||
|
<% unless @merge_request.status == "request_merged" || @merge_request.status == "processing" %> |
||||||
|
<h2 class="govuk-heading-m"><%= total_users_after_merge_text(@merge_request) %></h2> |
||||||
|
<p class="govuk-body"> |
||||||
|
<%= merging_organisations_without_users_text(@merge_request.organisations_without_users) %> |
||||||
|
</p> |
||||||
|
|
||||||
|
<% @merge_request.organisations_with_users.map do |org| %> |
||||||
|
<p class="govuk-body"> |
||||||
|
<%= link_to_merging_organisation_users(org) %> |
||||||
|
</p> |
||||||
|
<% end %> |
||||||
|
<% end %> |
@ -1,3 +1,3 @@ |
|||||||
<% answers = question.answer_options.map { |key, value| OpenStruct.new(id: key, name: value) } %> |
<% answers = question.answer_options.map { |key, value| OpenStruct.new(id: key, name: value) } %> |
||||||
<%= f.govuk_collection_select field, answers, :id, :name, label: { hidden: true }, "data-controller": "accessible-autocomplete" do %> |
<%= f.govuk_collection_select field, answers, :id, :name, label:, "data-controller": "accessible-autocomplete" do %> |
||||||
<% end %> |
<% end %> |
||||||
|
@ -0,0 +1,5 @@ |
|||||||
|
class AddMergeDateToMergeRequests < ActiveRecord::Migration[7.0] |
||||||
|
def change |
||||||
|
add_column :merge_requests, :merge_date, :datetime |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,16 @@ |
|||||||
|
class AddAdditionalFieldsToMergeRequests < ActiveRecord::Migration[7.0] |
||||||
|
def change |
||||||
|
change_table :merge_requests, bulk: true do |t| |
||||||
|
t.integer :requester_id |
||||||
|
t.string :helpdesk_ticket |
||||||
|
t.integer :total_users |
||||||
|
t.integer :total_schemes |
||||||
|
t.integer :total_lettings_logs |
||||||
|
t.integer :total_sales_logs |
||||||
|
t.integer :total_stock_owners |
||||||
|
t.integer :total_managing_agents |
||||||
|
t.boolean :signed_dsa, default: false |
||||||
|
t.datetime :discarded_at |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,5 @@ |
|||||||
|
class RemoveOtherMergingOrgField < ActiveRecord::Migration[7.0] |
||||||
|
def change |
||||||
|
remove_column :merge_requests, :other_merging_organisations, :string |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,27 @@ |
|||||||
|
class RemoveNewOrgMergeRequestFields < ActiveRecord::Migration[7.0] |
||||||
|
def up |
||||||
|
change_table :merge_requests, bulk: true do |t| |
||||||
|
t.remove :new_absorbing_organisation |
||||||
|
t.remove :telephone_number_correct |
||||||
|
t.remove :new_telephone_number |
||||||
|
t.remove :new_organisation_name |
||||||
|
t.remove :new_organisation_address_line1 |
||||||
|
t.remove :new_organisation_address_line2 |
||||||
|
t.remove :new_organisation_postcode |
||||||
|
t.remove :new_organisation_telephone_number |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
def down |
||||||
|
change_table :merge_requests, bulk: true do |t| |
||||||
|
t.column :new_absorbing_organisation, :boolean |
||||||
|
t.column :telephone_number_correct, :boolean |
||||||
|
t.column :new_telephone_number, :string |
||||||
|
t.column :new_organisation_name, :string |
||||||
|
t.column :new_organisation_address_line1, :string |
||||||
|
t.column :new_organisation_address_line2, :string |
||||||
|
t.column :new_organisation_postcode, :string |
||||||
|
t.column :new_organisation_telephone_number, :string |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,5 @@ |
|||||||
|
class AddLastFailedAttempt < ActiveRecord::Migration[7.0] |
||||||
|
def change |
||||||
|
add_column :merge_requests, :last_failed_attempt, :datetime |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,17 @@ |
|||||||
|
class UpdateMergeRequestFieldsForStatus < ActiveRecord::Migration[7.0] |
||||||
|
def up |
||||||
|
change_table :merge_requests, bulk: true do |t| |
||||||
|
t.column :request_merged, :boolean |
||||||
|
t.column :processing, :boolean |
||||||
|
t.remove :status |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
def down |
||||||
|
change_table :merge_requests, bulk: true do |t| |
||||||
|
t.remove :request_merged |
||||||
|
t.remove :processing |
||||||
|
t.column :status, :string |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,5 @@ |
|||||||
|
class AddExistingAbsorbingOrganisationField < ActiveRecord::Migration[7.0] |
||||||
|
def change |
||||||
|
add_column :merge_requests, :existing_absorbing_organisation, :boolean |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,8 @@ |
|||||||
|
FactoryBot.define do |
||||||
|
factory :merge_request do |
||||||
|
status { "incomplete" } |
||||||
|
merge_date { nil } |
||||||
|
helpdesk_ticket { "MSD-99999" } |
||||||
|
association :requesting_organisation, factory: :organisation |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,6 @@ |
|||||||
|
FactoryBot.define do |
||||||
|
factory :merge_request_organisation do |
||||||
|
association :merging_organisation, factory: :organisation |
||||||
|
association :merge_request, factory: :merge_request |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,272 @@ |
|||||||
|
require "rails_helper" |
||||||
|
|
||||||
|
RSpec.describe MergeRequestsHelper do |
||||||
|
describe "#merging_organisations_without_users_text" do |
||||||
|
context "with 1 organisation" do |
||||||
|
let(:organisation) { build(:organisation, name: "Org 1") } |
||||||
|
|
||||||
|
it "returns the correct text" do |
||||||
|
expect(merging_organisations_without_users_text([organisation])).to eq("Org 1 has no users.") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "with 2 organisations" do |
||||||
|
let(:organisation) { build(:organisation, name: "Org 1") } |
||||||
|
let(:organisation_2) { build(:organisation, name: "Org 2") } |
||||||
|
|
||||||
|
it "returns the correct text" do |
||||||
|
expect(merging_organisations_without_users_text([organisation, organisation_2])).to eq("Org 1 and Org 2 have no users.") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "with 3 organisations" do |
||||||
|
let(:organisation) { build(:organisation, name: "Org 1") } |
||||||
|
let(:organisation_2) { build(:organisation, name: "Org 2") } |
||||||
|
let(:organisation_3) { build(:organisation, name: "Org 3") } |
||||||
|
|
||||||
|
it "returns the correct text" do |
||||||
|
expect(merging_organisations_without_users_text([organisation, organisation_2, organisation_3])).to eq("Org 1, Org 2, and Org 3 have no users.") |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "#link_to_merging_organisation_users" do |
||||||
|
context "with 1 organisation user" do |
||||||
|
let(:organisation) { create(:organisation, name: "Org 1") } |
||||||
|
|
||||||
|
it "returns the correct link" do |
||||||
|
expect(link_to_merging_organisation_users(organisation)).to include("View 1 Org 1 user (opens in a new tab)") |
||||||
|
expect(link_to_merging_organisation_users(organisation)).to include(users_organisation_path(organisation)) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "with multiple organisation users" do |
||||||
|
let(:organisation) { create(:organisation, name: "Org 1") } |
||||||
|
|
||||||
|
before do |
||||||
|
create(:user, organisation:) |
||||||
|
end |
||||||
|
|
||||||
|
it "returns the correct link" do |
||||||
|
expect(link_to_merging_organisation_users(organisation)).to include("View all 2 Org 1 users (opens in a new tab)") |
||||||
|
expect(link_to_merging_organisation_users(organisation)).to include(users_organisation_path(organisation)) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "#merging_organisations_without_schemes_text" do |
||||||
|
context "with 1 organisation" do |
||||||
|
let(:organisation) { build(:organisation, name: "Org 1") } |
||||||
|
|
||||||
|
it "returns the correct text" do |
||||||
|
expect(merging_organisations_without_schemes_text([organisation])).to eq("Org 1 has no schemes.") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "with 2 organisations" do |
||||||
|
let(:organisation) { build(:organisation, name: "Org 1") } |
||||||
|
let(:organisation_2) { build(:organisation, name: "Org 2") } |
||||||
|
|
||||||
|
it "returns the correct text" do |
||||||
|
expect(merging_organisations_without_schemes_text([organisation, organisation_2])).to eq("Org 1 and Org 2 have no schemes.") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "with 3 organisations" do |
||||||
|
let(:organisation) { build(:organisation, name: "Org 1") } |
||||||
|
let(:organisation_2) { build(:organisation, name: "Org 2") } |
||||||
|
let(:organisation_3) { build(:organisation, name: "Org 3") } |
||||||
|
|
||||||
|
it "returns the correct text" do |
||||||
|
expect(merging_organisations_without_schemes_text([organisation, organisation_2, organisation_3])).to eq("Org 1, Org 2, and Org 3 have no schemes.") |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "#link_to_merging_organisation_schemes" do |
||||||
|
context "with 1 organisation scheme" do |
||||||
|
let(:organisation) { create(:organisation, name: "Org 1") } |
||||||
|
|
||||||
|
before do |
||||||
|
create(:scheme, owning_organisation: organisation) |
||||||
|
end |
||||||
|
|
||||||
|
it "returns the correct link" do |
||||||
|
expect(link_to_merging_organisation_schemes(organisation)).to include("View 1 Org 1 scheme (opens in a new tab)") |
||||||
|
expect(link_to_merging_organisation_schemes(organisation)).to include(schemes_organisation_path(organisation)) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "with multiple organisation schemes" do |
||||||
|
let(:organisation) { create(:organisation, name: "Org 1") } |
||||||
|
|
||||||
|
before do |
||||||
|
create_list(:scheme, 2, owning_organisation: organisation) |
||||||
|
end |
||||||
|
|
||||||
|
it "returns the correct link" do |
||||||
|
expect(link_to_merging_organisation_schemes(organisation)).to include("View all 2 Org 1 schemes (opens in a new tab)") |
||||||
|
expect(link_to_merging_organisation_schemes(organisation)).to include(schemes_organisation_path(organisation)) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "when creating relationship outcomes content" do |
||||||
|
let(:stock_owner1) { create(:organisation, name: "Stock owner 1") } |
||||||
|
let(:stock_owner2) { create(:organisation, name: "Stock owner 2") } |
||||||
|
let(:managing_agent1) { create(:organisation, name: "Managing agent 1") } |
||||||
|
let(:managing_agent2) { create(:organisation, name: "Managing agent 2") } |
||||||
|
let(:absorbing_organisation) { create(:organisation, name: "Absorbing Org") } |
||||||
|
let(:merging_organisations) { create_list(:organisation, 2) { |org, i| org.name = "Dummy Org #{i + 1}" } } |
||||||
|
let(:merge_request) { create(:merge_request, absorbing_organisation:, merging_organisations:) } |
||||||
|
|
||||||
|
context "when there are no relationships" do |
||||||
|
it "returns text stating there are no stock owners" do |
||||||
|
expect(stock_owners_text(merge_request)).to eq("Absorbing Org, Dummy Org 1, and Dummy Org 2 have no stock owners.<br><br>") |
||||||
|
end |
||||||
|
|
||||||
|
it "returns text stating there are no managing agents" do |
||||||
|
expect(managing_agent_text(merge_request)).to eq("Absorbing Org, Dummy Org 1, and Dummy Org 2 have no managing agents.<br><br>") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "when there are stock owners" do |
||||||
|
before do |
||||||
|
create(:organisation_relationship, child_organisation: absorbing_organisation, parent_organisation: stock_owner1) |
||||||
|
create(:organisation_relationship, child_organisation: merging_organisations.first, parent_organisation: stock_owner2) |
||||||
|
create(:organisation_relationship, child_organisation: merging_organisations.first, parent_organisation: stock_owner1) |
||||||
|
end |
||||||
|
|
||||||
|
it "returns text stating the relationships" do |
||||||
|
expect(stock_owners_text(merge_request)).to include("Some of the organisations merging have common stock owners.") |
||||||
|
expect(stock_owners_text(merge_request)).to include("Dummy Org 2 has no stock owners.") |
||||||
|
expect(stock_owners_text(merge_request)).to include("<a class=\"govuk-link\" target=\"_blank\" href=\"/organisations/#{merging_organisations.first.id}/stock-owners\">View all 2 Dummy Org 1 stock owners (opens in a new tab)</a>") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "when there are managing agents" do |
||||||
|
before do |
||||||
|
create(:organisation_relationship, parent_organisation: absorbing_organisation, child_organisation: managing_agent1) |
||||||
|
create(:organisation_relationship, parent_organisation: absorbing_organisation, child_organisation: managing_agent2) |
||||||
|
create(:organisation_relationship, parent_organisation: merging_organisations.first, child_organisation: managing_agent2) |
||||||
|
end |
||||||
|
|
||||||
|
it "returns text stating the relationships" do |
||||||
|
expect(managing_agent_text(merge_request)).to include("Some of the organisations merging have common managing agents.") |
||||||
|
expect(managing_agent_text(merge_request)).to include("Dummy Org 2 has no managing agents.") |
||||||
|
expect(managing_agent_text(merge_request)).to include("<a class=\"govuk-link\" target=\"_blank\" href=\"/organisations/#{merging_organisations.first.id}/managing-agents\">View the 1 Dummy Org 1 managing agent (opens in a new tab)</a>") |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "logs outcomes summary" do |
||||||
|
let(:organisation) { create(:organisation, name: "Org 1") } |
||||||
|
let(:merging_organisation) { create(:organisation, name: "Org 2") } |
||||||
|
let(:merging_organisation_2) { create(:organisation, name: "Org 3") } |
||||||
|
let(:merge_request) { create(:merge_request, absorbing_organisation: organisation, merge_date: Time.zone.today) } |
||||||
|
|
||||||
|
before do |
||||||
|
create(:merge_request_organisation, merge_request:, merging_organisation:) |
||||||
|
end |
||||||
|
|
||||||
|
context "when merging organisations don't have logs" do |
||||||
|
it "returns the correct merging_organisations_lettings_logs_outcomes_text text" do |
||||||
|
outcome_text = merging_organisations_lettings_logs_outcomes_text(merge_request) |
||||||
|
expect(outcome_text).not_to include("Org 1 users will have access to all lettings logs owned or managed by the merging organisation after the merge.") |
||||||
|
expect(outcome_text).not_to include("Lettings logs that are owned or managed by the merging organisation and have a tenancy start date after the merge date will have their owning or managing organisation changed to Org 1.") |
||||||
|
expect(outcome_text).not_to include("Some logs are owned and managed by different organisations in this merge. They appear in the list for both the owning and the managing organisation.") |
||||||
|
expect(outcome_text).to include("Org 1 and Org 2 have no lettings logs.") |
||||||
|
end |
||||||
|
|
||||||
|
it "returns correct lettings_logs_outcomes_header_text" do |
||||||
|
expect(lettings_logs_outcomes_header_text(merge_request)).to eq("0 lettings logs after merge") |
||||||
|
end |
||||||
|
|
||||||
|
it "returns the correct merging_organisations_sales_logs_outcomes_text text" do |
||||||
|
outcome_text = merging_organisations_sales_logs_outcomes_text(merge_request) |
||||||
|
expect(outcome_text).not_to include("Org 1 users will have access to all sales logs owned or reported by the merging organisation after the merge.") |
||||||
|
expect(outcome_text).not_to include("Sales logs that are owned or reported by the merging organisation and have a sale completion date after the merge date will have their owning or managing organisation changed to Org 1.") |
||||||
|
expect(outcome_text).not_to include("Some logs are owned and reported by different organisation in this merge. They appear in the list for both the owning and the managing organisation.") |
||||||
|
expect(outcome_text).to include("Org 1 and Org 2 have no sales logs.") |
||||||
|
end |
||||||
|
|
||||||
|
it "returns correct sales_logs_outcomes_header_text" do |
||||||
|
expect(sales_logs_outcomes_header_text(merge_request)).to eq("0 sales logs after merge") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "when merging organisations have logs" do |
||||||
|
before do |
||||||
|
create(:lettings_log, owning_organisation: organisation) |
||||||
|
create(:lettings_log, owning_organisation: merging_organisation, startdate: Time.zone.tomorrow) |
||||||
|
create(:lettings_log, owning_organisation: merging_organisation, startdate: Time.zone.yesterday) |
||||||
|
create(:sales_log, owning_organisation: organisation) |
||||||
|
create(:sales_log, owning_organisation: merging_organisation, saledate: Time.zone.tomorrow) |
||||||
|
create(:sales_log, owning_organisation: merging_organisation, saledate: Time.zone.yesterday) |
||||||
|
end |
||||||
|
|
||||||
|
it "returns the correct merging_organisations_lettings_logs_outcomes_text text" do |
||||||
|
outcome_text = merging_organisations_lettings_logs_outcomes_text(merge_request) |
||||||
|
expect(outcome_text).to include("Org 1 users will have access to all lettings logs owned or managed by the merging organisation after the merge.") |
||||||
|
expect(outcome_text).to include("Lettings logs that are owned or managed by the merging organisation and have a tenancy start date after the merge date will have their owning or managing organisation changed to Org 1.") |
||||||
|
expect(outcome_text).not_to include("Some logs are owned and managed by different organisations in this merge. They appear in the list for both the owning and the managing organisation.") |
||||||
|
expect(outcome_text).not_to include("Org 2 has no lettings logs.") |
||||||
|
expect(outcome_text).to include("View all 2 Org 2 lettings logs (opens in a new tab)") |
||||||
|
end |
||||||
|
|
||||||
|
it "returns correct lettings_logs_outcomes_header_text" do |
||||||
|
expect(lettings_logs_outcomes_header_text(merge_request)).to eq("3 lettings logs after merge") |
||||||
|
end |
||||||
|
|
||||||
|
it "returns the correct merging_organisations_sales_logs_outcomes_text text" do |
||||||
|
outcome_text = merging_organisations_sales_logs_outcomes_text(merge_request) |
||||||
|
expect(outcome_text).to include("Org 1 users will have access to all sales logs owned or reported by the merging organisation after the merge.") |
||||||
|
expect(outcome_text).to include("Sales logs that are owned or reported by the merging organisation and have a sale completion date after the merge date will have their owning or managing organisation changed to Org 1.") |
||||||
|
expect(outcome_text).not_to include("Some logs are owned and reported by different organisations in this merge. They appear in the list for both the owning and the managing organisation.") |
||||||
|
expect(outcome_text).not_to include("Org 2 has no sales logs.") |
||||||
|
expect(outcome_text).to include("View all 2 Org 2 sales logs (opens in a new tab)") |
||||||
|
end |
||||||
|
|
||||||
|
it "returns correct sales_logs_outcomes_header_text" do |
||||||
|
expect(sales_logs_outcomes_header_text(merge_request)).to eq("3 sales logs after merge") |
||||||
|
end |
||||||
|
|
||||||
|
context "when logs are owned and managed by organisations in the same merge" do |
||||||
|
before do |
||||||
|
create(:organisation_relationship, parent_organisation: merging_organisation_2, child_organisation: merging_organisation) |
||||||
|
create(:merge_request_organisation, merge_request:, merging_organisation: merging_organisation_2) |
||||||
|
create(:lettings_log, assigned_to: merging_organisation_2.users.first, owning_organisation: merging_organisation_2, managing_organisation: merging_organisation, startdate: Time.zone.yesterday) |
||||||
|
create(:sales_log, assigned_to: merging_organisation_2.users.first, owning_organisation: merging_organisation_2, managing_organisation: merging_organisation, saledate: Time.zone.yesterday) |
||||||
|
end |
||||||
|
|
||||||
|
it "returns the correct merging_organisations_lettings_logs_outcomes_text text" do |
||||||
|
outcome_text = merging_organisations_lettings_logs_outcomes_text(merge_request) |
||||||
|
expect(outcome_text).to include("Org 1 users will have access to all lettings logs owned or managed by the merging organisations after the merge.") |
||||||
|
expect(outcome_text).to include("Lettings logs that are owned or managed by the merging organisations and have a tenancy start date after the merge date will have their owning or managing organisation changed to Org 1.") |
||||||
|
expect(outcome_text).to include("Some logs are owned and managed by different organisations in this merge. They appear in the list for both the owning and the managing organisation.") |
||||||
|
expect(outcome_text).not_to include("Org 2 has no lettings logs.") |
||||||
|
expect(outcome_text).to include("View all 3 Org 2 lettings logs (opens in a new tab)") |
||||||
|
expect(outcome_text).to include("View 1 Org 3 lettings log (opens in a new tab)") |
||||||
|
end |
||||||
|
|
||||||
|
it "returns correct lettings_logs_outcomes_header_text" do |
||||||
|
expect(lettings_logs_outcomes_header_text(merge_request)).to eq("4 lettings logs after merge") |
||||||
|
end |
||||||
|
|
||||||
|
it "returns the correct merging_organisations_sales_logs_outcomes_text text" do |
||||||
|
outcome_text = merging_organisations_sales_logs_outcomes_text(merge_request) |
||||||
|
expect(outcome_text).to include("Org 1 users will have access to all sales logs owned or reported by the merging organisations after the merge.") |
||||||
|
expect(outcome_text).to include("Sales logs that are owned or reported by the merging organisations and have a sale completion date after the merge date will have their owning or managing organisation changed to Org 1.") |
||||||
|
expect(outcome_text).to include("Some logs are owned and reported by different organisations in this merge. They appear in the list for both the owning and the managing organisation.") |
||||||
|
expect(outcome_text).not_to include("Org 2 has no sales logs.") |
||||||
|
expect(outcome_text).to include("View all 3 Org 2 sales logs (opens in a new tab)") |
||||||
|
expect(outcome_text).to include("View 1 Org 3 sales log (opens in a new tab)") |
||||||
|
end |
||||||
|
|
||||||
|
it "returns correct sales_logs_outcomes_header_text" do |
||||||
|
expect(sales_logs_outcomes_header_text(merge_request)).to eq("4 sales logs after merge") |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,65 @@ |
|||||||
|
require "rails_helper" |
||||||
|
|
||||||
|
describe ProcessMergeRequestJob do |
||||||
|
let(:job) { described_class.new } |
||||||
|
let(:merge_organisations_service) { instance_double(Merge::MergeOrganisationsService) } |
||||||
|
|
||||||
|
before do |
||||||
|
allow(Merge::MergeOrganisationsService).to receive(:new).and_return(merge_organisations_service) |
||||||
|
allow(merge_organisations_service).to receive(:call).and_return(nil) |
||||||
|
end |
||||||
|
|
||||||
|
context "when processing a merge request" do |
||||||
|
let(:organisation) { create(:organisation) } |
||||||
|
let(:merging_organisation) { create(:organisation) } |
||||||
|
let(:other_merging_organisation) { create(:organisation) } |
||||||
|
let(:merge_request) { MergeRequest.create!(requesting_organisation: organisation, absorbing_organisation: organisation, merge_date: Time.zone.local(2022, 3, 3), total_users: 5, total_schemes: 5, total_lettings_logs: 2, total_sales_logs: 8, total_managing_agents: 2, total_stock_owners: 1, existing_absorbing_organisation: true) } |
||||||
|
|
||||||
|
before do |
||||||
|
create(:merge_request_organisation, merge_request:, merging_organisation:) |
||||||
|
create(:merge_request_organisation, merge_request:, merging_organisation: other_merging_organisation) |
||||||
|
end |
||||||
|
|
||||||
|
it "calls the merge organisations service with correct arguments" do |
||||||
|
expect(Merge::MergeOrganisationsService).to receive(:new).with(absorbing_organisation_id: organisation.id, merging_organisation_ids: [merging_organisation.id, other_merging_organisation.id], merge_date: Time.zone.local(2022, 3, 3), absorbing_organisation_active_from_merge_date: false) |
||||||
|
|
||||||
|
job.perform(merge_request:) |
||||||
|
expect(merge_request.reload.status).to eq("request_merged") |
||||||
|
end |
||||||
|
|
||||||
|
context "with new absorbing organisation" do |
||||||
|
let(:merge_request) { MergeRequest.create!(requesting_organisation: organisation, absorbing_organisation: organisation, merge_date: Time.zone.local(2022, 3, 3), existing_absorbing_organisation: false) } |
||||||
|
|
||||||
|
it "calls the merge organisations service with correct arguments" do |
||||||
|
expect(Merge::MergeOrganisationsService).to receive(:new).with(absorbing_organisation_id: organisation.id, merging_organisation_ids: [merging_organisation.id, other_merging_organisation.id], merge_date: Time.zone.local(2022, 3, 3), absorbing_organisation_active_from_merge_date: true) |
||||||
|
|
||||||
|
job.perform(merge_request:) |
||||||
|
expect(merge_request.reload.status).to eq("request_merged") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
it "clears last_failed_attempt value" do |
||||||
|
merge_request.update!(last_failed_attempt: Time.zone.now) |
||||||
|
job.perform(merge_request:) |
||||||
|
|
||||||
|
expect(merge_request.reload.last_failed_attempt).to be_nil |
||||||
|
end |
||||||
|
|
||||||
|
it "sets last_failed_attempt value, sets processing to false and clears all outcomes if there's an error" do |
||||||
|
allow(merge_organisations_service).to receive(:call).and_raise(ActiveRecord::Rollback) |
||||||
|
|
||||||
|
expect(merge_request.last_failed_attempt).to be_nil |
||||||
|
job.perform(merge_request:) |
||||||
|
|
||||||
|
merge_request.reload |
||||||
|
expect(merge_request.last_failed_attempt).to be_within(10.seconds).of(Time.zone.now) |
||||||
|
expect(merge_request.processing).to eq(false) |
||||||
|
expect(merge_request.total_users).to be_nil |
||||||
|
expect(merge_request.total_schemes).to be_nil |
||||||
|
expect(merge_request.total_managing_agents).to be_nil |
||||||
|
expect(merge_request.total_stock_owners).to be_nil |
||||||
|
expect(merge_request.total_lettings_logs).to be_nil |
||||||
|
expect(merge_request.total_sales_logs).to be_nil |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,451 @@ |
|||||||
|
require "rails_helper" |
||||||
|
|
||||||
|
RSpec.describe MergeRequest, type: :model do |
||||||
|
describe ".visible" do |
||||||
|
let(:open_collection_period_start_date) { 1.year.ago } |
||||||
|
let!(:merged_recent) { create(:merge_request, request_merged: true, merge_date: 3.months.ago) } |
||||||
|
let!(:merged_old) { create(:merge_request, request_merged: true, merge_date: 18.months.ago) } |
||||||
|
let!(:not_merged) { create(:merge_request, request_merged: false) } |
||||||
|
|
||||||
|
before do |
||||||
|
allow(FormHandler.instance).to receive(:start_date_of_earliest_open_collection_period).and_return(open_collection_period_start_date) |
||||||
|
end |
||||||
|
|
||||||
|
it "includes merged requests with merge dates after the open collection period start date" do |
||||||
|
expect(described_class.visible).to include(merged_recent) |
||||||
|
end |
||||||
|
|
||||||
|
it "excludes merged requests with merge dates before the open collection period start date" do |
||||||
|
expect(described_class.visible).not_to include(merged_old) |
||||||
|
end |
||||||
|
|
||||||
|
it "includes not_merged requests" do |
||||||
|
expect(described_class.visible).to include(not_merged) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "#discard!" do |
||||||
|
let(:merge_request) { create(:merge_request) } |
||||||
|
|
||||||
|
it "sets the discarded_at field" do |
||||||
|
merge_request.discard! |
||||||
|
expect(merge_request.discarded_at).not_to be_nil |
||||||
|
end |
||||||
|
|
||||||
|
it "does not delete the record" do |
||||||
|
merge_request.discard! |
||||||
|
expect(merge_request).to be_persisted |
||||||
|
end |
||||||
|
|
||||||
|
it "is not visible in the visible scope" do |
||||||
|
merge_request.discard! |
||||||
|
expect(described_class.visible).not_to include(merge_request) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "#status" do |
||||||
|
it "returns the correct status for deleted merge request" do |
||||||
|
merge_request = build(:merge_request, id: 1, discarded_at: Time.zone.today) |
||||||
|
expect(merge_request.status).to eq MergeRequest::STATUS[:deleted] |
||||||
|
end |
||||||
|
|
||||||
|
it "returns the correct status for a merged request" do |
||||||
|
merge_request = build(:merge_request, id: 1, request_merged: true) |
||||||
|
expect(merge_request.status).to eq MergeRequest::STATUS[:request_merged] |
||||||
|
end |
||||||
|
|
||||||
|
it "returns the correct status for a ready to merge request" do |
||||||
|
merge_request = build(:merge_request, id: 1, absorbing_organisation: create(:organisation), merge_date: Time.zone.today, existing_absorbing_organisation: true) |
||||||
|
create(:merge_request_organisation, merge_request:) |
||||||
|
expect(merge_request.status).to eq MergeRequest::STATUS[:ready_to_merge] |
||||||
|
end |
||||||
|
|
||||||
|
it "returns the correct status for a ready to merge request when existing_absorbing_organisation is false" do |
||||||
|
merge_request = build(:merge_request, id: 1, absorbing_organisation: create(:organisation), merge_date: Time.zone.today, existing_absorbing_organisation: false) |
||||||
|
create(:merge_request_organisation, merge_request:) |
||||||
|
expect(merge_request.status).to eq MergeRequest::STATUS[:ready_to_merge] |
||||||
|
end |
||||||
|
|
||||||
|
it "returns the merge issues if dsa is not signed for absorbing organisation" do |
||||||
|
merge_request = build(:merge_request, id: 1, absorbing_organisation: create(:organisation, with_dsa: false), merge_date: Time.zone.today, existing_absorbing_organisation: true) |
||||||
|
create(:merge_request_organisation, merge_request:) |
||||||
|
expect(merge_request.status).to eq MergeRequest::STATUS[:merge_issues] |
||||||
|
end |
||||||
|
|
||||||
|
it "returns the incomplete if absorbing organisation is missing" do |
||||||
|
merge_request = build(:merge_request, id: 1, absorbing_organisation: nil, merge_date: Time.zone.today) |
||||||
|
create(:merge_request_organisation, merge_request:) |
||||||
|
expect(merge_request.status).to eq MergeRequest::STATUS[:incomplete] |
||||||
|
end |
||||||
|
|
||||||
|
it "returns the incomplete if merge requests organisation is missing" do |
||||||
|
merge_request = build(:merge_request, id: 1, absorbing_organisation: create(:organisation), merge_date: Time.zone.today) |
||||||
|
expect(merge_request.status).to eq MergeRequest::STATUS[:incomplete] |
||||||
|
end |
||||||
|
|
||||||
|
it "returns the incomplete if merge date is missing" do |
||||||
|
merge_request = build(:merge_request, id: 1, absorbing_organisation: create(:organisation)) |
||||||
|
create(:merge_request_organisation, merge_request:) |
||||||
|
expect(merge_request.status).to eq MergeRequest::STATUS[:incomplete] |
||||||
|
end |
||||||
|
|
||||||
|
it "returns the incomplete if existing absorbing organisation is missing" do |
||||||
|
merge_request = build(:merge_request, id: 1, absorbing_organisation: create(:organisation, with_dsa: false), merge_date: Time.zone.today) |
||||||
|
create(:merge_request_organisation, merge_request:) |
||||||
|
expect(merge_request.status).to eq MergeRequest::STATUS[:incomplete] |
||||||
|
end |
||||||
|
|
||||||
|
it "returns processing if merge is processing" do |
||||||
|
merge_request = build(:merge_request, id: 1, absorbing_organisation: create(:organisation), processing: true) |
||||||
|
create(:merge_request_organisation, merge_request:) |
||||||
|
expect(merge_request.status).to eq MergeRequest::STATUS[:processing] |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "#organisations_with_users" do |
||||||
|
context "when absorbing organisation has users" do |
||||||
|
let(:merge_request) { create(:merge_request, absorbing_organisation:) } |
||||||
|
let(:absorbing_organisation) { create(:organisation) } |
||||||
|
|
||||||
|
before do |
||||||
|
create(:merge_request_organisation, merge_request:, merging_organisation: merging_organisation_1) |
||||||
|
create(:merge_request_organisation, merge_request:, merging_organisation: merging_organisation_2) |
||||||
|
end |
||||||
|
|
||||||
|
context "and some merging organisations have users" do |
||||||
|
let(:merging_organisation_1) { create(:organisation) } |
||||||
|
let(:merging_organisation_2) { create(:organisation, with_dsa: false) } |
||||||
|
|
||||||
|
it "returns correct organisations with users" do |
||||||
|
expect(absorbing_organisation.users.count).to eq(1) |
||||||
|
expect(merging_organisation_1.users.count).to eq(1) |
||||||
|
expect(merging_organisation_2.users.count).to eq(0) |
||||||
|
|
||||||
|
expect(merge_request.organisations_with_users.count).to eq(2) |
||||||
|
expect(merge_request.organisations_with_users).to include(merging_organisation_1) |
||||||
|
expect(merge_request.organisations_with_users).to include(absorbing_organisation) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "and no merging organisations have users" do |
||||||
|
let(:merging_organisation_1) { create(:organisation, with_dsa: false) } |
||||||
|
let(:merging_organisation_2) { create(:organisation, with_dsa: false) } |
||||||
|
|
||||||
|
it "returns correct organisations with users" do |
||||||
|
expect(absorbing_organisation.users.count).to eq(1) |
||||||
|
expect(merging_organisation_1.users.count).to eq(0) |
||||||
|
expect(merging_organisation_2.users.count).to eq(0) |
||||||
|
|
||||||
|
expect(merge_request.organisations_with_users.count).to eq(1) |
||||||
|
expect(merge_request.organisations_with_users).to include(absorbing_organisation) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "when absorbing organisation has no users" do |
||||||
|
let(:merge_request) { create(:merge_request, absorbing_organisation:) } |
||||||
|
let(:absorbing_organisation) { create(:organisation, with_dsa: false) } |
||||||
|
|
||||||
|
before do |
||||||
|
create(:merge_request_organisation, merge_request:, merging_organisation: merging_organisation_1) |
||||||
|
create(:merge_request_organisation, merge_request:, merging_organisation: merging_organisation_2) |
||||||
|
end |
||||||
|
|
||||||
|
context "and some merging organisations have users" do |
||||||
|
let(:merging_organisation_1) { create(:organisation) } |
||||||
|
let(:merging_organisation_2) { create(:organisation, with_dsa: false) } |
||||||
|
|
||||||
|
it "returns correct organisations with users" do |
||||||
|
expect(merging_organisation_1.users.count).to eq(1) |
||||||
|
expect(absorbing_organisation.users.count).to eq(0) |
||||||
|
expect(merging_organisation_2.users.count).to eq(0) |
||||||
|
|
||||||
|
expect(merge_request.organisations_with_users.count).to eq(1) |
||||||
|
expect(merge_request.organisations_with_users).to include(merging_organisation_1) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "and no merging organisations have users" do |
||||||
|
let(:merging_organisation_1) { create(:organisation, with_dsa: false) } |
||||||
|
let(:merging_organisation_2) { create(:organisation, with_dsa: false) } |
||||||
|
|
||||||
|
it "returns correct organisations with users" do |
||||||
|
expect(absorbing_organisation.users.count).to eq(0) |
||||||
|
expect(merging_organisation_1.users.count).to eq(0) |
||||||
|
expect(merging_organisation_2.users.count).to eq(0) |
||||||
|
|
||||||
|
expect(merge_request.organisations_with_users.count).to eq(0) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "#organisations_with_schemes" do |
||||||
|
let(:merge_request) { create(:merge_request, absorbing_organisation:) } |
||||||
|
let(:absorbing_organisation) { create(:organisation) } |
||||||
|
let(:merging_organisation_1) { create(:organisation) } |
||||||
|
let(:merging_organisation_2) { create(:organisation) } |
||||||
|
|
||||||
|
before do |
||||||
|
create(:merge_request_organisation, merge_request:, merging_organisation: merging_organisation_1) |
||||||
|
create(:merge_request_organisation, merge_request:, merging_organisation: merging_organisation_2) |
||||||
|
end |
||||||
|
|
||||||
|
context "when absorbing organisation has schemes" do |
||||||
|
before do |
||||||
|
create(:scheme, owning_organisation: absorbing_organisation) |
||||||
|
end |
||||||
|
|
||||||
|
context "and some merging organisations have schemes" do |
||||||
|
before do |
||||||
|
create(:scheme, owning_organisation: merging_organisation_1) |
||||||
|
end |
||||||
|
|
||||||
|
it "returns correct organisations with schemes" do |
||||||
|
expect(absorbing_organisation.owned_schemes.count).to eq(1) |
||||||
|
expect(merging_organisation_1.owned_schemes.count).to eq(1) |
||||||
|
expect(merging_organisation_2.owned_schemes.count).to eq(0) |
||||||
|
|
||||||
|
expect(merge_request.organisations_with_schemes.count).to eq(2) |
||||||
|
expect(merge_request.organisations_with_schemes).to include(merging_organisation_1) |
||||||
|
expect(merge_request.organisations_with_schemes).to include(absorbing_organisation) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "and no merging organisations have schemes" do |
||||||
|
it "returns correct organisations with schemes" do |
||||||
|
expect(absorbing_organisation.owned_schemes.count).to eq(1) |
||||||
|
expect(merging_organisation_1.owned_schemes.count).to eq(0) |
||||||
|
expect(merging_organisation_2.owned_schemes.count).to eq(0) |
||||||
|
|
||||||
|
expect(merge_request.organisations_with_schemes.count).to eq(1) |
||||||
|
expect(merge_request.organisations_with_schemes).to include(absorbing_organisation) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "when absorbing organisation has no schemes" do |
||||||
|
context "and some merging organisations have schemes" do |
||||||
|
before do |
||||||
|
create(:scheme, owning_organisation: merging_organisation_1) |
||||||
|
end |
||||||
|
|
||||||
|
it "returns correct organisations with schemes" do |
||||||
|
expect(merging_organisation_1.owned_schemes.count).to eq(1) |
||||||
|
expect(absorbing_organisation.owned_schemes.count).to eq(0) |
||||||
|
expect(merging_organisation_2.owned_schemes.count).to eq(0) |
||||||
|
|
||||||
|
expect(merge_request.organisations_with_schemes.count).to eq(1) |
||||||
|
expect(merge_request.organisations_with_schemes).to include(merging_organisation_1) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "and no merging organisations have schemes" do |
||||||
|
it "returns correct organisations with schemes" do |
||||||
|
expect(absorbing_organisation.owned_schemes.count).to eq(0) |
||||||
|
expect(merging_organisation_1.owned_schemes.count).to eq(0) |
||||||
|
expect(merging_organisation_2.owned_schemes.count).to eq(0) |
||||||
|
|
||||||
|
expect(merge_request.organisations_with_schemes.count).to eq(0) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "#organisations_without_users" do |
||||||
|
context "when absorbing organisation has users" do |
||||||
|
let(:merge_request) { create(:merge_request, absorbing_organisation:) } |
||||||
|
let(:absorbing_organisation) { create(:organisation) } |
||||||
|
|
||||||
|
before do |
||||||
|
create(:merge_request_organisation, merge_request:, merging_organisation: merging_organisation_1) |
||||||
|
create(:merge_request_organisation, merge_request:, merging_organisation: merging_organisation_2) |
||||||
|
end |
||||||
|
|
||||||
|
context "and some merging organisations have users" do |
||||||
|
let(:merging_organisation_1) { create(:organisation) } |
||||||
|
let(:merging_organisation_2) { create(:organisation, with_dsa: false) } |
||||||
|
|
||||||
|
it "returns correct organisations with users" do |
||||||
|
expect(absorbing_organisation.users.count).to eq(1) |
||||||
|
expect(merging_organisation_1.users.count).to eq(1) |
||||||
|
expect(merging_organisation_2.users.count).to eq(0) |
||||||
|
|
||||||
|
expect(merge_request.organisations_without_users.count).to eq(1) |
||||||
|
expect(merge_request.organisations_without_users).to include(merging_organisation_2) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "and no merging organisations have users" do |
||||||
|
let(:merging_organisation_1) { create(:organisation, with_dsa: false) } |
||||||
|
let(:merging_organisation_2) { create(:organisation, with_dsa: false) } |
||||||
|
|
||||||
|
it "returns correct organisations with users" do |
||||||
|
expect(absorbing_organisation.users.count).to eq(1) |
||||||
|
expect(merging_organisation_1.users.count).to eq(0) |
||||||
|
expect(merging_organisation_2.users.count).to eq(0) |
||||||
|
|
||||||
|
expect(merge_request.organisations_without_users.count).to eq(2) |
||||||
|
expect(merge_request.organisations_without_users).to include(merging_organisation_1) |
||||||
|
expect(merge_request.organisations_without_users).to include(merging_organisation_2) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "when absorbing organisation has no users" do |
||||||
|
let(:merge_request) { create(:merge_request, absorbing_organisation:) } |
||||||
|
let(:absorbing_organisation) { create(:organisation, with_dsa: false) } |
||||||
|
|
||||||
|
before do |
||||||
|
create(:merge_request_organisation, merge_request:, merging_organisation: merging_organisation_1) |
||||||
|
create(:merge_request_organisation, merge_request:, merging_organisation: merging_organisation_2) |
||||||
|
end |
||||||
|
|
||||||
|
context "and some merging organisations have users" do |
||||||
|
let(:merging_organisation_1) { create(:organisation) } |
||||||
|
let(:merging_organisation_2) { create(:organisation, with_dsa: false) } |
||||||
|
|
||||||
|
it "returns correct organisations with users" do |
||||||
|
expect(merging_organisation_1.users.count).to eq(1) |
||||||
|
expect(absorbing_organisation.users.count).to eq(0) |
||||||
|
expect(merging_organisation_2.users.count).to eq(0) |
||||||
|
|
||||||
|
expect(merge_request.organisations_without_users.count).to eq(2) |
||||||
|
expect(merge_request.organisations_without_users).to include(absorbing_organisation) |
||||||
|
expect(merge_request.organisations_without_users).to include(merging_organisation_2) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "and no merging organisations have users" do |
||||||
|
let(:merging_organisation_1) { create(:organisation, with_dsa: false) } |
||||||
|
let(:merging_organisation_2) { create(:organisation, with_dsa: false) } |
||||||
|
|
||||||
|
it "returns correct organisations with users" do |
||||||
|
expect(absorbing_organisation.users.count).to eq(0) |
||||||
|
expect(merging_organisation_1.users.count).to eq(0) |
||||||
|
expect(merging_organisation_2.users.count).to eq(0) |
||||||
|
|
||||||
|
expect(merge_request.organisations_without_users.count).to eq(3) |
||||||
|
expect(merge_request.organisations_without_users).to include(absorbing_organisation) |
||||||
|
expect(merge_request.organisations_without_users).to include(merging_organisation_1) |
||||||
|
expect(merge_request.organisations_without_users).to include(merging_organisation_2) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "#organisations_without_schemes" do |
||||||
|
let(:merge_request) { create(:merge_request, absorbing_organisation:) } |
||||||
|
let(:absorbing_organisation) { create(:organisation) } |
||||||
|
let(:merging_organisation_1) { create(:organisation) } |
||||||
|
let(:merging_organisation_2) { create(:organisation) } |
||||||
|
|
||||||
|
before do |
||||||
|
create(:merge_request_organisation, merge_request:, merging_organisation: merging_organisation_1) |
||||||
|
create(:merge_request_organisation, merge_request:, merging_organisation: merging_organisation_2) |
||||||
|
end |
||||||
|
|
||||||
|
context "when absorbing organisation has schemes" do |
||||||
|
before do |
||||||
|
create(:scheme, owning_organisation: absorbing_organisation) |
||||||
|
end |
||||||
|
|
||||||
|
context "and some merging organisations have schemes" do |
||||||
|
before do |
||||||
|
create(:scheme, owning_organisation: merging_organisation_1) |
||||||
|
end |
||||||
|
|
||||||
|
it "returns correct organisations with schemes" do |
||||||
|
expect(absorbing_organisation.owned_schemes.count).to eq(1) |
||||||
|
expect(merging_organisation_1.owned_schemes.count).to eq(1) |
||||||
|
expect(merging_organisation_2.owned_schemes.count).to eq(0) |
||||||
|
|
||||||
|
expect(merge_request.organisations_without_schemes.count).to eq(1) |
||||||
|
expect(merge_request.organisations_without_schemes).to include(merging_organisation_2) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "and no merging organisations have schemes" do |
||||||
|
it "returns correct organisations with schemes" do |
||||||
|
expect(absorbing_organisation.owned_schemes.count).to eq(1) |
||||||
|
expect(merging_organisation_1.owned_schemes.count).to eq(0) |
||||||
|
expect(merging_organisation_2.owned_schemes.count).to eq(0) |
||||||
|
|
||||||
|
expect(merge_request.organisations_without_schemes.count).to eq(2) |
||||||
|
expect(merge_request.organisations_without_schemes).to include(merging_organisation_1) |
||||||
|
expect(merge_request.organisations_without_schemes).to include(merging_organisation_2) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "when absorbing organisation has no schemes" do |
||||||
|
context "and some merging organisations have schemes" do |
||||||
|
before do |
||||||
|
create(:scheme, owning_organisation: merging_organisation_1) |
||||||
|
end |
||||||
|
|
||||||
|
it "returns correct organisations with schemes" do |
||||||
|
expect(merging_organisation_1.owned_schemes.count).to eq(1) |
||||||
|
expect(absorbing_organisation.owned_schemes.count).to eq(0) |
||||||
|
expect(merging_organisation_2.owned_schemes.count).to eq(0) |
||||||
|
|
||||||
|
expect(merge_request.organisations_without_schemes.count).to eq(2) |
||||||
|
expect(merge_request.organisations_without_schemes).to include(absorbing_organisation) |
||||||
|
expect(merge_request.organisations_without_schemes).to include(merging_organisation_2) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "and no merging organisations have schemes" do |
||||||
|
it "returns correct organisations with schemes" do |
||||||
|
expect(absorbing_organisation.owned_schemes.count).to eq(0) |
||||||
|
expect(merging_organisation_1.owned_schemes.count).to eq(0) |
||||||
|
expect(merging_organisation_2.owned_schemes.count).to eq(0) |
||||||
|
|
||||||
|
expect(merge_request.organisations_without_schemes.count).to eq(3) |
||||||
|
expect(merge_request.organisations_without_schemes).to include(absorbing_organisation) |
||||||
|
expect(merge_request.organisations_without_schemes).to include(merging_organisation_1) |
||||||
|
expect(merge_request.organisations_without_schemes).to include(merging_organisation_2) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "relationship outcomes" do |
||||||
|
let(:stock_owner1) { create(:organisation, name: "Stock owner 1") } |
||||||
|
let(:stock_owner2) { create(:organisation, name: "Stock owner 2") } |
||||||
|
let(:stock_owner3) { create(:organisation, name: "Stock owner 3") } |
||||||
|
let(:managing_agent1) { create(:organisation, name: "Managing agent 1") } |
||||||
|
let(:managing_agent2) { create(:organisation, name: "Managing agent 2") } |
||||||
|
let(:absorbing_organisation) { create(:organisation, name: "Absorbing Org") } |
||||||
|
let(:merging_organisations) { create_list(:organisation, 2) { |org, i| org.name = "Dummy Org #{i + 1}" } } |
||||||
|
let(:merge_request) { create(:merge_request, absorbing_organisation:, merging_organisations:) } |
||||||
|
|
||||||
|
before do |
||||||
|
create(:organisation_relationship, child_organisation: absorbing_organisation, parent_organisation: stock_owner1) |
||||||
|
create(:organisation_relationship, child_organisation: merging_organisations.first, parent_organisation: stock_owner2) |
||||||
|
create(:organisation_relationship, child_organisation: merging_organisations.first, parent_organisation: stock_owner1) |
||||||
|
create(:organisation_relationship, child_organisation: merging_organisations.first, parent_organisation: stock_owner3) |
||||||
|
create(:organisation_relationship, parent_organisation: absorbing_organisation, child_organisation: managing_agent1) |
||||||
|
create(:organisation_relationship, parent_organisation: absorbing_organisation, child_organisation: managing_agent2) |
||||||
|
create(:organisation_relationship, parent_organisation: merging_organisations.first, child_organisation: managing_agent2) |
||||||
|
end |
||||||
|
|
||||||
|
describe "#total_stock_owners_after_merge" do |
||||||
|
it "returns the correct count of stock owners after merge" do |
||||||
|
expect(merge_request.total_stock_owners_after_merge).to eq(3) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "#total_managing_agents_after_merge" do |
||||||
|
it "returns the correct count of managing agents after merge" do |
||||||
|
expect(merge_request.total_managing_agents_after_merge).to eq(2) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "#total_stock_owners_managing_agents_label" do |
||||||
|
it "returns the correct label" do |
||||||
|
expect(merge_request.total_stock_owners_managing_agents_label).to eq("3 stock owners\n2 managing agents") |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,28 @@ |
|||||||
|
require "rails_helper" |
||||||
|
|
||||||
|
RSpec.describe MergeRequest, type: :request do |
||||||
|
let(:user) { create(:user, :data_coordinator) } |
||||||
|
let(:organisation) { user.organisation } |
||||||
|
let(:merge_request) { create(:merge_request) } |
||||||
|
let(:support_user) { create(:user, :support, organisation:) } |
||||||
|
let(:page) { Capybara::Node::Simple.new(response.body) } |
||||||
|
|
||||||
|
before do |
||||||
|
allow(support_user).to receive(:need_two_factor_authentication?).and_return(false) |
||||||
|
sign_in support_user |
||||||
|
end |
||||||
|
|
||||||
|
context "when deleting a merge request" do |
||||||
|
it "discards the merge request" do |
||||||
|
delete delete_merge_request_path(merge_request) |
||||||
|
expect(merge_request.reload.discarded_at).not_to be_nil |
||||||
|
end |
||||||
|
|
||||||
|
it "redirects to the merge request list" do |
||||||
|
delete delete_merge_request_path(merge_request) |
||||||
|
expect(response).to redirect_to(organisations_path(tab: "merge-requests")) |
||||||
|
follow_redirect! |
||||||
|
expect(page).to have_content("Merge requests") |
||||||
|
end |
||||||
|
end |
||||||
|
end |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,93 @@ |
|||||||
|
require "rails_helper" |
||||||
|
|
||||||
|
RSpec.describe "merge_requests/show.html.erb", type: :view do |
||||||
|
let(:absorbing_organisation) { create(:organisation, name: "Absorbing Org", with_dsa: false) } |
||||||
|
let(:dpo_user) { create(:user, name: "DPO User", is_dpo: true, organisation: absorbing_organisation) } |
||||||
|
let(:merge_request) { create(:merge_request, absorbing_organisation_id: absorbing_organisation.id, signed_dsa: false) } |
||||||
|
|
||||||
|
before do |
||||||
|
assign(:merge_request, merge_request) |
||||||
|
render |
||||||
|
end |
||||||
|
|
||||||
|
it "displays the correct title" do |
||||||
|
expect(rendered).to have_selector("h1.govuk-heading-l") do |h1| |
||||||
|
expect(h1).to have_selector("span.govuk-caption-l", text: "Merge request") |
||||||
|
expect(h1).to have_content("Absorbing Org") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
it "displays the notification banner when DSA is not signed" do |
||||||
|
expect(rendered).to have_selector(".govuk-notification-banner") |
||||||
|
expect(rendered).to have_content("The absorbing organisation must accept the Data Sharing Agreement before merging.") |
||||||
|
end |
||||||
|
|
||||||
|
it "displays the requester details" do |
||||||
|
expect(rendered).to have_selector("dt", text: "Requester") |
||||||
|
expect(rendered).to have_selector("dd", text: merge_request.requester&.name || "You didn't answer this question") |
||||||
|
end |
||||||
|
|
||||||
|
it "displays the helpdesk ticket details" do |
||||||
|
expect(rendered).to have_selector("dt", text: "Helpdesk ticket") |
||||||
|
if merge_request.helpdesk_ticket.present? |
||||||
|
expect(rendered).to have_link(merge_request.helpdesk_ticket, href: "https://dluhcdigital.atlassian.net/browse/#{merge_request.helpdesk_ticket}") |
||||||
|
else |
||||||
|
expect(rendered).to have_selector("dd", text: "You didn't answer this question") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
it "displays the status details" do |
||||||
|
expect(rendered).to have_selector("dt", text: "Status") |
||||||
|
expect(rendered).to have_selector("dd", text: "Incomplete") |
||||||
|
end |
||||||
|
|
||||||
|
it "displays the absorbing organisation details" do |
||||||
|
expect(rendered).to have_selector("dt", text: "Absorbing organisation") |
||||||
|
expect(rendered).to have_selector("dd", text: merge_request.absorbing_organisation_name) |
||||||
|
end |
||||||
|
|
||||||
|
it "displays the merge date details" do |
||||||
|
expect(rendered).to have_selector("dt", text: "Merge date") |
||||||
|
expect(rendered).to have_selector("dd", text: merge_request.merge_date || "You didn't answer this question") |
||||||
|
end |
||||||
|
|
||||||
|
context "when the merge request is complete" do |
||||||
|
before do |
||||||
|
merge_request.update!(request_merged: true, signed_dsa: true, total_users: 10, total_schemes: 5, total_lettings_logs: 20, total_sales_logs: 30, total_stock_owners: 40, total_managing_agents: 50) |
||||||
|
assign(:merge_request, merge_request) |
||||||
|
render |
||||||
|
end |
||||||
|
|
||||||
|
it "has status of 'Merged'" do |
||||||
|
expect(rendered).to have_selector("dd", text: "Merged") |
||||||
|
end |
||||||
|
|
||||||
|
it "displays the total users after merge details" do |
||||||
|
expect(rendered).to have_selector("dt", text: "Total users after merge") |
||||||
|
expect(rendered).to have_selector("dd", text: merge_request.total_users) |
||||||
|
end |
||||||
|
|
||||||
|
it "displays the total schemes after merge details" do |
||||||
|
expect(rendered).to have_selector("dt", text: "Total schemes after merge") |
||||||
|
expect(rendered).to have_selector("dd", text: merge_request.total_schemes) |
||||||
|
end |
||||||
|
|
||||||
|
it "displays the total logs after merge details" do |
||||||
|
expect(rendered).to have_selector("dt", text: "Total logs after merge") |
||||||
|
if merge_request.total_lettings_logs.present? || merge_request.total_sales_logs.present? |
||||||
|
combined_text = [] |
||||||
|
combined_text << "#{merge_request.total_lettings_logs} lettings logs" if merge_request.total_lettings_logs.present? |
||||||
|
combined_text << "#{merge_request.total_sales_logs} sales logs" if merge_request.total_sales_logs.present? |
||||||
|
expect(rendered).to have_selector("dd", text: combined_text.join("")) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
it "displays the total stock owners & managing agents after merge details" do |
||||||
|
expect(rendered).to have_selector("dt", text: "Total stock owners & managing agents after merge") |
||||||
|
combined_text = [] |
||||||
|
combined_text << "#{merge_request.total_stock_owners} stock owners" if merge_request.total_stock_owners.present? |
||||||
|
combined_text << "#{merge_request.total_managing_agents} managing agents" if merge_request.total_managing_agents.present? |
||||||
|
expect(rendered).to have_selector("dd", text: combined_text.join("\n")) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue