Browse Source

Merge branch 'main' into CLDC-2691-support-nav-bug

pull/2031/head
natdeanlewissoftwire 2 years ago
parent
commit
45d8af8c6b
  1. 2
      app/components/lettings_log_summary_component.html.erb
  2. 2
      app/components/sales_log_summary_component.html.erb
  3. 4
      app/helpers/filters_helper.rb
  4. 3
      app/helpers/schemes_helper.rb
  5. 12
      app/models/form/lettings/questions/managing_organisation.rb
  6. 1
      app/models/lettings_log.rb
  7. 4
      app/models/organisation.rb
  8. 1
      app/models/sales_log.rb
  9. 8
      app/services/bulk_upload/lettings/year2023/row_parser.rb
  10. 2
      app/views/schemes/details.html.erb
  11. 2
      app/views/schemes/edit_name.html.erb
  12. 2
      app/views/schemes/new.html.erb
  13. 22
      spec/models/form/lettings/questions/managing_organisation_spec.rb
  14. 83
      spec/requests/form_controller_spec.rb
  15. 14
      spec/requests/lettings_logs_controller_spec.rb
  16. 20
      spec/requests/sales_logs_controller_spec.rb
  17. 41
      spec/requests/schemes_controller_spec.rb
  18. 17
      spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb

2
app/components/lettings_log_summary_component.html.erb

@ -34,7 +34,7 @@
<% end %>
</p>
<% end %>
<% if current_user.support? || current_user.organisation.has_managing_agents? %>
<% if current_user.support? || current_user.organisation.has_managing_agents? || current_user.organisation.has_recent_absorbed_organisations? %>
<dl class="app-metadata">
<% if log.owning_organisation %>
<div class="app-metadata__item">

2
app/components/sales_log_summary_component.html.erb

@ -24,7 +24,7 @@
Sale completed <time datetime="<%= log.saledate.iso8601 %>"><%= log.saledate.to_formatted_s(:govuk_date) %></time>
<% end %>
</p>
<% if current_user.support? || current_user.organisation.has_managing_agents? %>
<% if current_user.support? || current_user.organisation.has_managing_agents? || current_user.organisation.has_recent_absorbed_organisations? %>
<dl class="app-metadata">
<% if log.owning_organisation %>
<div class="app-metadata__item">

4
app/helpers/filters_helper.rb

@ -124,11 +124,11 @@ module FiltersHelper
end
def non_support_with_multiple_owning_orgs?
current_user.organisation.stock_owners.count > 1 && user_lettings_path?
current_user.organisation.stock_owners.count > 1 && user_lettings_path? || current_user.organisation.has_recent_absorbed_organisations?
end
def non_support_with_multiple_managing_orgs?
current_user.organisation.managing_agents.count > 1 && user_lettings_path?
current_user.organisation.managing_agents.count > 1 && user_lettings_path? || current_user.organisation.has_recent_absorbed_organisations?
end
def user_lettings_path?

3
app/helpers/schemes_helper.rb

@ -38,7 +38,8 @@ module SchemesHelper
all_orgs = Organisation.all.map { |org| OpenStruct.new(id: org.id, name: org.name) }
user_org = [OpenStruct.new(id: current_user.organisation_id, name: current_user.organisation.name)]
stock_owners = current_user.organisation.stock_owners.map { |org| OpenStruct.new(id: org.id, name: org.name) }
current_user.support? ? all_orgs : user_org + stock_owners
merged_organisations = current_user.organisation.absorbed_organisations.merged_during_open_collection_period.map { |org| OpenStruct.new(id: org.id, name: org.name) }
current_user.support? ? all_orgs : user_org + stock_owners + merged_organisations
end
def null_option

12
app/models/form/lettings/questions/managing_organisation.rb

@ -35,13 +35,21 @@ class Form::Lettings::Questions::ManagingOrganisation < ::Form::Question
user.organisation.managing_agents + log.owning_organisation.managing_agents
else
user.organisation.managing_agents
end.pluck(:id, :name).to_h
end
user.organisation.absorbed_organisations.each do |absorbed_org|
opts[absorbed_org.id] = "#{absorbed_org.name} (inactive as of #{absorbed_org.merge_date.to_fs(:govuk_date)})"
end
opts.merge(orgs)
orgs.each do |org|
opts[org.id] = if org.merge_date.present?
"#{org.name} (inactive as of #{org.merge_date.to_fs(:govuk_date)})"
else
org.name
end
end
opts
end
def displayed_answer_options(log, user)

1
app/models/lettings_log.rb

@ -559,6 +559,7 @@ class LettingsLog < Log
return unless updated_by&.support?
return if owning_organisation.blank? || managing_organisation.blank? || created_by.blank?
return if created_by&.organisation == managing_organisation || created_by&.organisation == owning_organisation
return if created_by&.organisation == owning_organisation.absorbing_organisation || created_by&.organisation == managing_organisation.absorbing_organisation
update!(created_by: nil)
end

4
app/models/organisation.rb

@ -146,4 +146,8 @@ class Organisation < ApplicationRecord
absorbed_organisations.merged_during_open_collection_period.group_by(&:merge_date)
end
def has_recent_absorbed_organisations?
absorbed_organisations&.merged_during_open_collection_period.present?
end
end

1
app/models/sales_log.rb

@ -318,6 +318,7 @@ class SalesLog < Log
return unless updated_by&.support?
return if owning_organisation.blank? || created_by.blank?
return if created_by&.organisation == owning_organisation
return if created_by&.organisation == owning_organisation.absorbing_organisation
update!(created_by: nil)
end

8
app/services/bulk_upload/lettings/year2023/row_parser.rb

@ -329,6 +329,14 @@ class BulkUpload::Lettings::Year2023::RowParser
},
on: :after_log
validates :field_11,
presence: {
if: proc { renttype == :intermediate },
message: I18n.t("validations.not_answered", question: "intermediate rent type"),
category: :setup,
},
on: :after_log
validates :field_15,
presence: {
if: proc { supported_housing? && log_uses_old_scheme_id? },

2
app/views/schemes/details.html.erb

@ -44,7 +44,7 @@
:description,
legend: { text: "Is this scheme registered under the Care Standards Act 2000?", size: "m" } %>
<% if current_user.data_coordinator? && current_user.organisation.stock_owners.count.zero? %>
<% if current_user.data_coordinator? && current_user.organisation.stock_owners.count.zero? && !current_user.organisation.has_recent_absorbed_organisations? %>
<%= f.hidden_field :owning_organisation_id, value: current_user.organisation.id %>
<% else %>
<%= f.govuk_collection_select :owning_organisation_id,

2
app/views/schemes/edit_name.html.erb

@ -25,7 +25,7 @@
label: { text: "This scheme contains confidential information" } %>
<% end %>
<% if current_user.data_coordinator? && current_user.organisation.stock_owners.count.zero? %>
<% if current_user.data_coordinator? && current_user.organisation.stock_owners.count.zero? && !current_user.organisation.has_recent_absorbed_organisations? %>
<%= f.hidden_field :owning_organisation_id, value: current_user.organisation.id %>
<% else %>
<%= f.govuk_collection_select :owning_organisation_id,

2
app/views/schemes/new.html.erb

@ -44,7 +44,7 @@
:description,
legend: { text: "Is this scheme registered under the Care Standards Act 2000?", size: "m" } %>
<% if current_user.data_coordinator? && current_user.organisation.stock_owners.count.zero? %>
<% if current_user.data_coordinator? && current_user.organisation.stock_owners.count.zero? && !current_user.organisation.has_recent_absorbed_organisations? %>
<%= f.hidden_field :owning_organisation_id, value: current_user.organisation.id %>
<% else %>
<%= f.govuk_collection_select :owning_organisation_id,

22
spec/models/form/lettings/questions/managing_organisation_spec.rb

@ -119,6 +119,28 @@ RSpec.describe Form::Lettings::Questions::ManagingOrganisation, type: :model do
end
end
context "when org owns stock and has merged managing agents" do
let(:options) do
{
"" => "Select an option",
log.managing_organisation.id => "Managing org 1",
log_owning_org.id => "Owning org (Owning organisation)",
org_rel1.child_organisation.id => "Managing org 2 (inactive as of 2 August 2023)",
org_rel2.child_organisation.id => "Managing org 3 (inactive as of 2 August 2023)",
}
end
before do
org_rel1.child_organisation.update!(merge_date: Time.zone.local(2023, 8, 2), absorbing_organisation_id: log_owning_org.id)
org_rel2.child_organisation.update!(merge_date: Time.zone.local(2023, 8, 2), absorbing_organisation_id: log_owning_org.id)
end
it "shows current managing agent at top, followed by the current owning organisation (with hint), followed by the managing agents of the current owning organisation" do
log_owning_org.update!(holds_own_stock: true)
expect(question.displayed_answer_options(log, user)).to eq(options)
end
end
context "when org does not own stock" do
let(:options) do
{

83
spec/requests/form_controller_spec.rb

@ -189,6 +189,62 @@ RSpec.describe FormController, type: :request do
end
end
context "when submitting a sales log with valid owning organisation" do
let(:sales_log) { create(:sales_log) }
let(:created_by) { managing_organisation.users.first }
let(:params) do
{
id: sales_log.id,
sales_log: {
page: "organisation",
owning_organisation_id: managing_organisation.id,
},
}
end
before do
sales_log.update!(owning_organisation: managing_organisation, created_by:)
sales_log.reload
end
it "does not reset created by" do
post "/sales-logs/#{sales_log.id}/organisation", params: params
expect(response).to redirect_to("/sales-logs/#{sales_log.id}/created-by")
follow_redirect!
sales_log.reload
expect(sales_log.created_by).to eq(created_by)
end
end
context "when submitting a sales log with valid merged owning organisation" do
let(:sales_log) { create(:sales_log) }
let(:created_by) { managing_organisation.users.first }
let(:merged_organisation) { create(:organisation) }
let(:params) do
{
id: sales_log.id,
sales_log: {
page: "organisation",
owning_organisation_id: merged_organisation.id,
},
}
end
before do
merged_organisation.update!(merge_date: Time.zone.today, absorbing_organisation: managing_organisation)
sales_log.update!(owning_organisation: managing_organisation, created_by:)
sales_log.reload
end
it "does not reset created by" do
post "/sales-logs/#{sales_log.id}/organisation", params: params
expect(response).to redirect_to("/sales-logs/#{sales_log.id}/created-by")
follow_redirect!
sales_log.reload
expect(sales_log.created_by).to eq(created_by)
end
end
context "with valid managing organisation" do
let(:params) do
{
@ -214,6 +270,33 @@ RSpec.describe FormController, type: :request do
end
end
context "with valid absorbed managing organisation" do
let(:params) do
{
id: lettings_log.id,
lettings_log: {
page: "stock_owner",
owning_organisation_id: stock_owner.id,
},
}
end
let(:merged_org) { create(:organisation) }
before do
merged_org.update!(merge_date: Time.zone.today, absorbing_organisation: organisation)
lettings_log.update!(owning_organisation: merged_org, created_by: user, managing_organisation: merged_org)
lettings_log.reload
end
it "does not reset created by" do
post "/lettings-logs/#{lettings_log.id}/stock-owner", params: params
expect(response).to redirect_to("/lettings-logs/#{lettings_log.id}/managing-organisation")
follow_redirect!
lettings_log.reload
expect(lettings_log.created_by).to eq(user)
end
end
context "with only adding the stock owner" do
let(:params) do
{

14
spec/requests/lettings_logs_controller_spec.rb

@ -277,6 +277,20 @@ RSpec.describe LettingsLogsController, type: :request do
expect(page).not_to have_link "Delete logs"
end
end
context "and organisation has absorbed organisations" do
let(:merged_organisation) { FactoryBot.create(:organisation) }
before do
merged_organisation.update!(absorbing_organisation: organisation, merge_date: Time.zone.yesterday)
end
it "shows organisation labels" do
get "/lettings-logs", headers:, params: {}
expect(page).to have_content("Owned by")
expect(page).to have_content("Managed by")
end
end
end
context "when the user is a customer support user" do

20
spec/requests/sales_logs_controller_spec.rb

@ -559,6 +559,26 @@ RSpec.describe SalesLogsController, type: :request do
sign_in user
end
it "does not show organisation labels" do
get "/sales-logs", headers: headers, params: {}
expect(page).not_to have_content("Owned by")
expect(page).not_to have_content("Managed by")
end
context "and organisation has absorbed organisations" do
let(:merged_organisation) { FactoryBot.create(:organisation) }
before do
merged_organisation.update!(absorbing_organisation: organisation, merge_date: Time.zone.yesterday)
end
it "shows organisation labels" do
get "/sales-logs", headers: headers, params: {}
expect(page).to have_content("Owned by")
expect(page).not_to have_content("Managed by")
end
end
it "does not have organisation columns" do
get "/sales-logs", headers: headers, params: {}
expect(page).not_to have_content("Owning organisation")

41
spec/requests/schemes_controller_spec.rb

@ -2224,6 +2224,47 @@ RSpec.describe SchemesController, type: :request do
end
end
context "when there are no stock owners" do
before do
get "/schemes/#{scheme.id}/edit-name"
end
context "and there are no absorbed organisations" do
it "does not include the owning organisation question" do
expect(response).to have_http_status(:ok)
expect(page).not_to have_content("Which organisation owns the housing stock for this scheme?")
end
end
context "and there are organisations absorbed during an open collection period" do
let(:merged_organisation) { create(:organisation) }
before do
merged_organisation.update!(absorbing_organisation: user.organisation, merge_date: Time.zone.today)
get "/schemes/#{scheme.id}/edit-name"
end
it "includes the owning organisation question" do
expect(response).to have_http_status(:ok)
expect(page).to have_content("Which organisation owns the housing stock for this scheme?")
end
end
context "and there are no recently absorbed organisations" do
let(:merged_organisation) { create(:organisation) }
before do
merged_organisation.update!(absorbing_organisation: user.organisation, merge_date: Time.zone.today - 2.years)
get "/schemes/#{scheme.id}/edit-name"
end
it "does not include the owning organisation question" do
expect(response).to have_http_status(:ok)
expect(page).not_to have_content("Which organisation owns the housing stock for this scheme?")
end
end
end
context "when attempting to access secondary-client-group scheme page for another organisation" do
before do
get "/schemes/#{another_scheme.id}/edit-name"

17
spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb

@ -809,6 +809,23 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
end
end
context "when intermediate rent and field_11 (Which type of Intermediate Rent) is not given" do
let(:attributes) { { bulk_upload:, field_5: "9", field_11: nil } }
it "adds error on field_11" do
expect(parser.errors[:field_5]).to be_present
expect(parser.errors[:field_11]).to eq(["You must answer intermediate rent type"])
end
end
context "when intermediate rent other and field_12 is not given" do
let(:attributes) { { bulk_upload:, field_5: "9", field_11: "3", field_12: nil } }
it "adds error on field_12" do
expect(parser.errors[:field_12]).to eq(["You must answer product name"])
end
end
context "when bulk upload is for general needs" do
context "when general needs option selected" do
let(:attributes) { { bulk_upload:, field_5: "1", field_4: "1" } }

Loading…
Cancel
Save