Display customer emails & phone numbers to suppliers

when permitted.

The MaskDataService is used by the report framework, so this should affect all reports. It would be nice to test all reports, but I figured it wasn't worth it (already we only test one report for masking names).
This commit is contained in:
David Cook
2025-03-05 16:36:31 +11:00
parent b05a42f3bb
commit 47b6888fe6
3 changed files with 40 additions and 1 deletions

View File

@@ -8,7 +8,7 @@ module Orders
def call
mask_customer_names unless customer_names_allowed?
mask_contact_data
mask_contact_data unless cutomer_contacts_allowed?
mask_address
end
@@ -27,6 +27,10 @@ module Orders
lastname: "")
end
def cutomer_contacts_allowed?
order.distributor.show_customer_contacts_to_suppliers
end
def mask_contact_data
order.bill_address&.assign_attributes(phone: "")
order.ship_address&.assign_attributes(phone: "")

View File

@@ -134,6 +134,17 @@ RSpec.describe Reporting::Reports::OrdersAndDistributors::Base do
expect(row[2..5]).to eq [bill_address.full_name, "HIDDEN", "", ""]
end
end
context "where the distributor allows suppliers to see customer phone and email" do
before do
distributor.update_columns show_customer_contacts_to_suppliers: true
end
it "shows line items supplied by my producers, with only contact details shown" do
expect(row).not_to include("FirstName LastName", "City")
expect(row[2..5]).to eq ["HIDDEN", order.email, "123-456", ""]
end
end
end
it "minimises database queries" do

View File

@@ -82,5 +82,29 @@ RSpec.describe Orders::MaskDataService do
include_examples "mask customer contact data"
include_examples "mask customer address"
end
context 'when displaying customer contact data is allowed' do
before { distributor.show_customer_contacts_to_suppliers = true }
include_examples "mask customer name"
include_examples "mask customer address"
it 'does not mask the phone or email' do
described_class.new(order).call
expect(order.bill_address.attributes).not_to include('phone' => '')
expect(order.ship_address.attributes).not_to include('phone' => '')
expect(order.email).not_to eq('HIDDEN')
end
end
context 'when displaying customer contact data is not allowed' do
before { distributor.show_customer_contacts_to_suppliers = false }
include_examples "mask customer name"
include_examples "mask customer contact data"
include_examples "mask customer address"
end
end
end