mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Extract data masking to service
This commit is contained in:
35
app/services/order_data_masker.rb
Normal file
35
app/services/order_data_masker.rb
Normal file
@@ -0,0 +1,35 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class OrderDataMasker
|
||||
def initialize(order)
|
||||
@order = order
|
||||
end
|
||||
|
||||
def call
|
||||
mask_customer_names unless customer_names_allowed?
|
||||
mask_contact_data
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
attr_accessor :order
|
||||
|
||||
def customer_names_allowed?
|
||||
order.distributor.preferences[:show_customer_names_to_suppliers]
|
||||
end
|
||||
|
||||
def mask_customer_names
|
||||
order.bill_address&.assign_attributes(firstname: I18n.t('admin.reports.hidden'),
|
||||
lastname: "")
|
||||
order.ship_address&.assign_attributes(firstname: I18n.t('admin.reports.hidden'),
|
||||
lastname: "")
|
||||
end
|
||||
|
||||
def mask_contact_data
|
||||
order.bill_address&.assign_attributes(phone: "", address1: "", address2: "",
|
||||
city: "", zipcode: "", state: nil)
|
||||
order.ship_address&.assign_attributes(phone: "", address1: "", address2: "",
|
||||
city: "", zipcode: "", state: nil)
|
||||
order.assign_attributes(email: I18n.t('admin.reports.hidden'))
|
||||
end
|
||||
end
|
||||
@@ -45,23 +45,7 @@ module OpenFoodNetwork
|
||||
orders = search.result
|
||||
|
||||
orders.select{ |order| orders_with_hidden_details(orders).include? order }.each do |order|
|
||||
# TODO We should really be hiding customer code here too, but until we
|
||||
# have an actual association between order and customer, it's a bit tricky
|
||||
|
||||
unless order.distributor.preferences[:show_customer_names_to_suppliers]
|
||||
order.bill_address.andand.
|
||||
assign_attributes(firstname: I18n.t('admin.reports.hidden'), lastname: "")
|
||||
order.ship_address.andand.
|
||||
assign_attributes(firstname: I18n.t('admin.reports.hidden'), lastname: "")
|
||||
end
|
||||
|
||||
order.bill_address.andand.
|
||||
assign_attributes(phone: "", address1: "", address2: "",
|
||||
city: "", zipcode: "", state: nil)
|
||||
order.ship_address.andand.
|
||||
assign_attributes(phone: "", address1: "", address2: "",
|
||||
city: "", zipcode: "", state: nil)
|
||||
order.assign_attributes(email: I18n.t('admin.reports.hidden'))
|
||||
OrderDataMasker.new(order).call
|
||||
end
|
||||
|
||||
line_item_details orders
|
||||
|
||||
@@ -27,23 +27,7 @@ module OpenFoodNetwork
|
||||
line_items.reject{ |li|
|
||||
editable_line_items.include? li
|
||||
}.each do |line_item|
|
||||
# TODO We should really be hiding customer code here too, but until we
|
||||
# have an actual association between order and customer, it's a bit tricky
|
||||
|
||||
unless line_item.order.distributor.preferences[:show_customer_names_to_suppliers]
|
||||
line_item.order.bill_address.andand.
|
||||
assign_attributes(firstname: I18n.t('admin.reports.hidden'), lastname: "")
|
||||
line_item.order.ship_address.andand.
|
||||
assign_attributes(firstname: I18n.t('admin.reports.hidden'), lastname: "")
|
||||
end
|
||||
|
||||
line_item.order.bill_address.andand.
|
||||
assign_attributes(phone: "", address1: "", address2: "",
|
||||
city: "", zipcode: "", state: nil)
|
||||
line_item.order.ship_address.andand.
|
||||
assign_attributes(phone: "", address1: "", address2: "",
|
||||
city: "", zipcode: "", state: nil)
|
||||
line_item.order.assign_attributes(email: I18n.t('admin.reports.hidden'))
|
||||
OrderDataMasker.new(line_item.order).call
|
||||
end
|
||||
|
||||
line_items
|
||||
|
||||
Reference in New Issue
Block a user