Class: Spree::ConsentRecord
- Inherits:
-
Object
- Object
- Spree::ConsentRecord
- Includes:
- SingleStoreResource
- Defined in:
- app/models/spree/consent_record.rb
Overview
Proof that a person accepted something at a moment in time.
GDPR Art. 7(1) puts the burden of demonstrating consent on the controller, and a boolean on the customer cannot carry that burden: it says what is true now, not what was agreed when. So acceptance is recorded as an event. A person consents more than once — at registration, then again at each checkout — and each occasion is its own row.
The owner is a customer where one exists and the cart or order otherwise, because guest checkout produces consent with no account behind it.
Constant Summary collapse
- TERMS_OF_SERVICE =
What was agreed to. An open set: a store with its own consent gesture records it under its own purpose without reopening this class.
'terms_of_service'.freeze
- EMAIL_MARKETING =
'email_marketing'.freeze
- CHECKOUT =
Where the gesture happened.
'checkout'.freeze
- REGISTRATION =
'registration'.freeze
- ACCOUNT =
'account'.freeze
- ADMIN =
A staff member changed it on the person's behalf. Distinct from ACCOUNT, which claims the person did it themselves — recording one as the other is evidence of a gesture that never happened.
'admin'.freeze
- NEWSLETTER =
The person confirmed a newsletter sign-up, which is a different gesture from editing their profile and is the stronger evidence of the two: a double opt-in proves the address reaches them.
'newsletter'.freeze
- ANONYMIZATION =
Core's own: erasure withdraws marketing consent on the person's behalf, and that withdrawal is a consent event like any other.
'anonymization'.freeze
- UNKNOWN =
The flag changed but nothing said where. Recording it as ACCOUNT would claim the person visited their profile and clicked, which is the same fabrication the ADMIN constant exists to avoid.
'unknown'.freeze
- SOURCES =
[CHECKOUT, REGISTRATION, ACCOUNT, ADMIN, NEWSLETTER, ANONYMIZATION, UNKNOWN, 'import', 'storefront'].freeze
Class Method Summary collapse
-
.document_snapshot(policy) ⇒ Hash
The document as it read at the moment of agreement.
-
.record!(store:, owner:, purpose:, source:, accepted: true, email: nil, ip_address: nil, user_agent: nil, policies: nil) ⇒ Spree::ConsentRecord
Records acceptance of the store's consent-gated policies, snapshotting each document as it read at the time.
Instance Method Summary collapse
Class Method Details
.document_snapshot(policy) ⇒ Hash
The document as it read at the moment of agreement.
Stores the body itself, not only a hash of it. A digest can show that a policy has since changed, but it cannot say what the person actually read — and reproducing the text they agreed to is the whole point of keeping the row. The digest rides along as a cheap equality check.
The locale is recorded because policies are translated: the same document is different text in each language.
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'app/models/spree/consent_record.rb', line 100 def self.document_snapshot(policy) body = policy.body.to_s { 'slug' => policy.slug, 'name' => policy.name, 'locale' => Spree::Current.locale || I18n.locale.to_s, 'body' => body, 'digest' => Digest::SHA256.hexdigest(body), 'updated_at' => policy.updated_at&.iso8601 } end |
.record!(store:, owner:, purpose:, source:, accepted: true, email: nil, ip_address: nil, user_agent: nil, policies: nil) ⇒ Spree::ConsentRecord
Records acceptance of the store's consent-gated policies, snapshotting each document as it read at the time. The digest is what makes the row evidence rather than an assertion: a merchant who later edits their terms can still show which text this person agreed to.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/models/spree/consent_record.rb', line 73 def self.record!(store:, owner:, purpose:, source:, accepted: true, email: nil, ip_address: nil, user_agent: nil, policies: nil) create!( store: store, owner: owner, purpose: purpose.to_s, source: source.to_s, accepted: accepted, email: email, ip_address: ip_address, user_agent: user_agent, documents: policies.present? ? policies.map { |policy| document_snapshot(policy) } : nil ) end |
Instance Method Details
#documents_list ⇒ Array<Hash>
114 115 116 |
# File 'app/models/spree/consent_record.rb', line 114 def documents_list Array(documents) end |