From 3d02ba90b653e90c436a5117269f3e10b169146b Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Fri, 3 Nov 2023 16:32:49 +0000 Subject: [PATCH] feat: match email regardless of casing in bulk upload --- .../bulk_upload/lettings/year2022/row_parser.rb | 2 +- .../bulk_upload/lettings/year2023/row_parser.rb | 2 +- app/services/bulk_upload/sales/year2022/row_parser.rb | 2 +- app/services/bulk_upload/sales/year2023/row_parser.rb | 2 +- .../bulk_upload/lettings/year2022/row_parser_spec.rb | 10 ++++++++++ .../bulk_upload/lettings/year2023/row_parser_spec.rb | 10 ++++++++++ .../bulk_upload/sales/year2022/row_parser_spec.rb | 10 ++++++++++ .../bulk_upload/sales/year2023/row_parser_spec.rb | 10 ++++++++++ 8 files changed, 44 insertions(+), 4 deletions(-) diff --git a/app/services/bulk_upload/lettings/year2022/row_parser.rb b/app/services/bulk_upload/lettings/year2022/row_parser.rb index ce950b6db..6c86e8dd1 100644 --- a/app/services/bulk_upload/lettings/year2022/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2022/row_parser.rb @@ -513,7 +513,7 @@ private end def created_by - @created_by ||= User.find_by(email: field_112) + @created_by ||= User.where("lower(email) = ?", field_112.downcase).first end def duplicate_check_fields diff --git a/app/services/bulk_upload/lettings/year2023/row_parser.rb b/app/services/bulk_upload/lettings/year2023/row_parser.rb index 84bf2481b..7ece50a20 100644 --- a/app/services/bulk_upload/lettings/year2023/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2023/row_parser.rb @@ -542,7 +542,7 @@ private end def created_by - @created_by ||= User.find_by(email: field_3) + @created_by ||= User.where("lower(email) = ?", field_3.downcase).first end def validate_uprn_exists_if_any_key_address_fields_are_blank diff --git a/app/services/bulk_upload/sales/year2022/row_parser.rb b/app/services/bulk_upload/sales/year2022/row_parser.rb index a1663fafc..0f1dfa17f 100644 --- a/app/services/bulk_upload/sales/year2022/row_parser.rb +++ b/app/services/bulk_upload/sales/year2022/row_parser.rb @@ -934,7 +934,7 @@ private end def created_by - @created_by ||= User.find_by(email: field_93) + @created_by ||= User.where("lower(email) = ?", field_93.downcase).first end def hhregres diff --git a/app/services/bulk_upload/sales/year2023/row_parser.rb b/app/services/bulk_upload/sales/year2023/row_parser.rb index 17303346f..62c9c230b 100644 --- a/app/services/bulk_upload/sales/year2023/row_parser.rb +++ b/app/services/bulk_upload/sales/year2023/row_parser.rb @@ -1112,7 +1112,7 @@ private end def created_by - @created_by ||= User.find_by(email: field_2) + @created_by ||= User.where("lower(email) = ?", field_2.downcase).first end def previous_la_known diff --git a/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb index f699b730a..b0ee35d29 100644 --- a/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb @@ -1125,6 +1125,16 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do end end + context "when email matches other than casing" do + let(:other_user) { create(:user, organisation: owning_org) } + + let(:attributes) { { bulk_upload:, field_111: owning_org.old_visible_id, field_112: other_user.email.upcase!, field_113: managing_org.old_visible_id } } + + it "is permitted" do + expect(parser.errors[:field_112]).to be_blank + end + end + context "when an user part of managing org" do let(:other_user) { create(:user, organisation: managing_org) } diff --git a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb index d12d833f5..c1fef1d25 100644 --- a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb @@ -753,6 +753,16 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do end end + context "when email matches other than casing" do + let(:other_user) { create(:user, organisation: owning_org) } + + let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_3: other_user.email.upcase!, field_2: managing_org.old_visible_id } } + + it "is permitted" do + expect(parser.errors[:field_3]).to be_blank + end + end + context "when an user part of managing org" do let(:other_user) { create(:user, organisation: managing_org) } diff --git a/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb index 3b18333df..c305c67ed 100644 --- a/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb @@ -510,6 +510,16 @@ RSpec.describe BulkUpload::Sales::Year2022::RowParser do expect(parser.errors[:field_93]).to be_blank end end + + context "when email matches other than casing" do + let(:other_user) { create(:user, organisation: owning_org) } + + let(:attributes) { { bulk_upload:, field_92: owning_org.old_visible_id, field_93: other_user.email.upcase! } } + + it "is permitted" do + expect(parser.errors[:field_93]).to be_blank + end + end end [ diff --git a/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb index e1137ea84..2e38e4f2c 100644 --- a/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb @@ -459,6 +459,16 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do expect(parser.errors[:field_2]).to be_blank end end + + context "when email matches other than casing" do + let(:other_user) { create(:user, organisation: owning_org) } + + let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: other_user.email.upcase! } } + + it "is permitted" do + expect(parser.errors[:field_2]).to be_blank + end + end end describe "fields 3, 4, 5 => saledate" do