Class: Spree::DataRequest

Inherits:
Object
  • Object
show all
Includes:
HasStatus, NumberIdentifier, SingleStoreResource
Defined in:
app/models/spree/data_request.rb

Overview

A GDPR data subject request: access (Art. 15) or erasure (Art. 17).

The record exists so a request leaves a trace. A response that was streamed and forgotten proves nothing, and Art. 30 record-keeping asks a controller to show which requests arrived and how they were answered. It also serves as the cooldown: a pending request is returned rather than starting a second build, so a customer cannot queue an unbounded number of expensive exports.

Erasure is carried out by Spree::Customers::Anonymize; this model records that it was asked for and when it finished.

Constant Summary collapse

ACCESS =
'access'.freeze
ERASURE =
'erasure'.freeze
KINDS =
[ACCESS, ERASURE].freeze
DEFAULT_EXPIRY =

How long a generated export stays downloadable. Long enough for a person to act on the email, short enough that a copy of everything a shop knows about them is not left lying around.

7.days
CONFIRMATION_WINDOW =

How long a request a customer raised waits for confirmation from its email address before it lapses.

24.hours

Instance Method Summary collapse

Instance Method Details

#access? ⇒ Boolean

Returns a request for a copy of the data (Art. 15).

Returns:

  • (Boolean) —

    a request for a copy of the data (Art. 15)



89
90
91
# File 'app/models/spree/data_request.rb', line 89

def access?
  kind == ACCESS
end

#addressed_to_customer? ⇒ Boolean

Whether the request names the address the account has now. The work matches guest rows by the account's address when it runs, so a request for an address the account has since left would reach rows it never named.

Returns:

  • (Boolean)


121
122
123
# File 'app/models/spree/data_request.rb', line 121

def addressed_to_customer?
  customer.present? && email.to_s.casecmp?(customer.email.to_s)
end

#confirmable? ⇒ Boolean

Whether the request is still waiting for confirmation, within the window to receive it, and still names the account's address.

Returns:

  • (Boolean)


112
113
114
# File 'app/models/spree/data_request.rb', line 112

def confirmable?
  awaiting_confirmation? && requested_at > CONFIRMATION_WINDOW.ago && addressed_to_customer?
end

#downloadable? ⇒ Boolean

Whether the generated file is still downloadable.

Returns:

  • (Boolean)


100
101
102
# File 'app/models/spree/data_request.rb', line 100

def downloadable?
  completed? && export_file.attached? && !expired?
end

#erasure? ⇒ Boolean

Returns a request to erase it (Art. 17).

Returns:

  • (Boolean) —

    a request to erase it (Art. 17)



94
95
96
# File 'app/models/spree/data_request.rb', line 94

def erasure?
  kind == ERASURE
end

#event_serializer_class ⇒ Class?

The event payload must never carry the download credential — see Api::V3::DataRequestEventSerializer.

Returns:

  • (Class, nil)


84
85
86
# File 'app/models/spree/data_request.rb', line 84

def event_serializer_class
  'Spree::Api::V3::DataRequestEventSerializer'.safe_constantize
end

#expired? ⇒ Boolean

Returns:

  • (Boolean)


105
106
107
# File 'app/models/spree/data_request.rb', line 105

def expired?
  expires_at.present? && expires_at.past?
end