Class: Spree::Customers::DataExport

Inherits:
Object
  • Object
show all
Includes:
PersonalDataMatching
Defined in:
app/services/spree/customers/data_export.rb

Overview

Assembles everything a store holds about one person, for GDPR Art. 15 (right of access) and Art. 20 (portability).

Art. 20 asks for a "structured, commonly used and machine-readable" format, which is why this returns a plain hash destined for JSON rather than the CSV the admin exports use — a customer's data is nested, and flattening orders and their line items into a spreadsheet loses the structure the regulation asks to preserve.

Read-only and side-effect free: the caller decides whether the result is streamed, written to a file or attached to a request record.

Instance Method Summary collapse

Constructor Details

#initialize(customer:, store: nil) ⇒ DataExport

Returns a new instance of DataExport.

Parameters:

  • customer (Spree::Customer)
  • store (Spree::Store, nil) (defaults to: nil) —

    the store the request came in through, recorded on the request rather than used to narrow this payload. Nothing here is scoped to one store: erasure never is, and an access response that showed less than the erasure removes would understate what the controller holds. Kept for host apps that override this service and for the sections a multi-store build may want to label.



24
25
26
27
# File 'app/services/spree/customers/data_export.rb', line 24

def initialize(customer:, store: nil)
  @customer = customer
  @store = store
end

Instance Method Details

#call ⇒ Hash

Returns:

  • (Hash)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/services/spree/customers/data_export.rb', line 30

def call
  {
    account: ,
    marketing_consent: marketing_consent,
    consent_records: consent_records,
    addresses: addresses,
    orders: orders,
    draft_orders: draft_orders,
    order_groups: order_groups,
    carts: carts,
    payment_sources: payment_sources,
    connected_logins: connected_logins,
    store_credits: store_credits,
    gift_cards: gift_cards,
    wishlists: wishlists,
    custom_fields: custom_fields,
    companies: companies,
    tax_identifiers: tax_identifiers,
    exported_at: Time.current.iso8601
  }
end