From f3177f612d568fdab75825d2a800381ae629a99f Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire <94526761+natdeanlewissoftwire@users.noreply.github.com> Date: Tue, 7 Nov 2023 15:49:35 +0000 Subject: [PATCH] CLDC-2982 Make bulk upload user emails case insensitive (#2017) * feat: match email regardless of casing in bulk upload * feat: allow null emails * feat: set encoding by bom for file IO before parsing * Revert "feat: set encoding by bom for file IO before parsing" This reverts commit 03d2d17e7b83dcb5f4c527b11582d7e7aebdb4da. --- .../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 7081353d8..5a9ef579c 100644 --- a/app/services/bulk_upload/lettings/year2022/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2022/row_parser.rb @@ -511,7 +511,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 875d7ac30..0ba078efc 100644 --- a/app/services/bulk_upload/lettings/year2023/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2023/row_parser.rb @@ -540,7 +540,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..55f5f0ed1 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..6ce207abf 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 5b3262d0b..3d77ff467 100644 --- a/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb @@ -1128,6 +1128,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 58aa79a26..399001dbc 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