Browse Source

CLDC-3028 Allow bulk uploading for merged organisations (#2067)

* Allow bulk uploading for merged organisations

* Allow bu for absorbed orgs with moved users
pull/2081/head
kosiakkatrina 1 year ago committed by GitHub
parent
commit
1098e6f2c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      app/models/organisation.rb
  2. 8
      app/services/bulk_upload/lettings/year2023/row_parser.rb
  3. 7
      app/services/bulk_upload/sales/year2023/row_parser.rb
  4. 22
      spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb
  5. 40
      spec/services/bulk_upload/sales/year2023/row_parser_spec.rb

5
app/models/organisation.rb

@ -25,6 +25,11 @@ class Organisation < ApplicationRecord
ids << id
end
absorbed_organisations.each do |organisation|
ids.concat(organisation.stock_owners.pluck(:id))
ids << organisation.id if organisation.holds_own_stock?
end
ids.concat(stock_owners.pluck(:id))
Organisation.where(id: ids)

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

@ -540,11 +540,11 @@ private
def validate_created_by_related
return unless created_by
return if created_by.organisation == owning_organisation || created_by.organisation == managing_organisation
return if created_by.organisation == owning_organisation&.absorbing_organisation || created_by.organisation == managing_organisation&.absorbing_organisation
unless (created_by.organisation == owning_organisation) || (created_by.organisation == managing_organisation)
block_log_creation!
errors.add(:field_3, "User must be related to owning organisation or managing organisation")
end
block_log_creation!
errors.add(:field_3, "User must be related to owning organisation or managing organisation")
end
def created_by

7
app/services/bulk_upload/sales/year2023/row_parser.rb

@ -1195,11 +1195,10 @@ private
def validate_created_by_related
return unless created_by
return if created_by.organisation == owning_organisation || created_by.organisation == owning_organisation&.absorbing_organisation
unless created_by.organisation == owning_organisation
block_log_creation!
errors.add(:field_2, "User must be related to owning organisation", category: :setup)
end
block_log_creation!
errors.add(:field_2, "User must be related to owning organisation", category: :setup)
end
def setup_question?(question)

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

@ -1384,6 +1384,28 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
expect(parser).to be_block_log_creation
end
end
context "when user's org has absorbed owning organisation" do
let(:merged_org) { create(:organisation, :with_old_visible_id, holds_own_stock: true) }
let(:merged_org_stock_owner) { create(:organisation, :with_old_visible_id, holds_own_stock: true) }
let(:attributes) { { bulk_upload:, field_1: merged_org_stock_owner.old_visible_id, field_2: merged_org.old_visible_id, field_3: user.email } }
before do
create(:organisation_relationship, parent_organisation: merged_org_stock_owner, child_organisation: merged_org)
merged_org.update!(absorbing_organisation: user.organisation, merge_date: Time.zone.today)
merged_org.reload
user.organisation.reload
end
it "is permitted" do
parser = described_class.new(attributes)
parser.valid?
expect(parser.errors.where(:field_1)).not_to be_present
expect(parser.errors.where(:field_3)).not_to be_present
end
end
end
describe "#field_2" do # managing org

40
spec/services/bulk_upload/sales/year2023/row_parser_spec.rb

@ -417,6 +417,46 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do
expect(parser).to be_block_log_creation
end
end
context "when user's org has absorbed owning organisation with stock owners" do
let(:merged_org) { create(:organisation, :with_old_visible_id, holds_own_stock: true) }
let(:merged_org_stock_owner) { create(:organisation, :with_old_visible_id, holds_own_stock: true) }
let(:attributes) { { bulk_upload:, field_1: merged_org_stock_owner.old_visible_id } }
before do
create(:organisation_relationship, parent_organisation: merged_org_stock_owner, child_organisation: merged_org)
merged_org.update!(absorbing_organisation: user.organisation, merge_date: Time.zone.today)
merged_org.reload
user.organisation.reload
end
it "is permitted" do
parser.valid?
expect(parser.errors.where(:field_1)).not_to be_present
end
end
context "when user's org has absorbed owning organisation" do
let(:merged_org) { create(:organisation, :with_old_visible_id, holds_own_stock: true) }
let(:attributes) { { bulk_upload:, field_1: merged_org.old_visible_id, field_2: user.email } }
before do
merged_org.update!(absorbing_organisation: user.organisation, merge_date: Time.zone.today)
merged_org.reload
user.organisation.reload
user.reload
end
it "is permitted" do
parser = described_class.new(attributes)
parser.valid?
expect(parser.errors.where(:field_1)).not_to be_present
expect(parser.errors.where(:field_2)).not_to be_present
end
end
end
describe "#field_2" do # username for created_by

Loading…
Cancel
Save