hryvinskyi / magento2-gdpr
Data-subject requests for Magento 2: export, erase and anonymise a shopper's personal data, with the request lifecycle, journal, e-mails, cron and CLI
Package info
github.com/hryvinskyi/magento2-gdpr
Type:magento2-module
pkg:composer/hryvinskyi/magento2-gdpr
Requires
- php: ~8.3.0||~8.4.0||~8.5.0
- ext-intl: *
- hryvinskyi/magento2-clock: ^1.0
- hryvinskyi/magento2-document-export: ^1.0
- hryvinskyi/magento2-gdpr-api: ^1.0
- hryvinskyi/magento2-logger: ^1.2
- hryvinskyi/magento2-rate-limit: ^1.0
- magento/framework: *
- magento/module-authorization: *
- magento/module-backend: *
- magento/module-config: *
- magento/module-cron: *
- magento/module-customer: *
- magento/module-email: *
- magento/module-integration: *
- magento/module-store: *
- magento/module-user: *
- magento/module-webapi: *
- psr/clock: ^1.0
- psr/log: ^1.1 || ^2.0 || ^3.0
- symfony/console: ^5.4 || ^6.0 || ^7.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
The engine of the data-subject rights suite. A shopper, or a store operator for them, asks to export, erase or anonymise the personal data a store holds about a customer account or an e-mail address. This module owns the request and its life, the entity and anonymisation pools other modules contribute to, the export archive, the privacy action log, the e-mails, the cron jobs, the command line and the REST routes. The admin screens, the storefront pages and the GraphQL schema are separate packages of the suite.
What it does for a store
- Three request types.
exporthands the subject a copy of their data and changes nothing.eraseapplies each kind of data's configured method, delete or anonymise.anonymiseanonymises every kind of data that can be anonymised and deletes every kind that can only be deleted. - Two kinds of subject. A customer subject is an account, and covers the rows tied to its customer id. A guest subject is an e-mail address in one website, and covers the rows of that address that no account holds: guest orders, carts and subscriptions, and the rows of an account that was deleted. Rows tied only to an e-mail address are never added to a customer subject, because an account proves a password, not control of the address.
- One open request of a kind. A subject has at most one open export request and at most one open destructive request (
eraseoranonymise). A second one is refused with a reason the caller can show. A unique index enforces it, so two requests made at the same moment cannot both succeed. - The life of a request.
pending_confirmationmoves toscheduled,cancelledorexpired.scheduledmoves torunningorcancelled.runningmoves tocompletedorfailed.failedmoves toscheduled(a retry) orcancelled.completed,cancelledandexpiredare final. Any other move throws. The subject may cancel a request while it waits for confirmation or for its run, up to the moment a run claims it; a store operator may also cancel a failed request. What the failed run already erased stays erased. - The delay. An
eraseoranonymiserequest runs after the website's delay (default 60 minutes) so the subject can change their mind. Anexportruns at the next cron run. A request made by an operator, from the command line or by the automatic clean-up has no delay. A guest's request is scheduled when the guest confirms it. - The respond-by date. One calendar month after the day the request was made, counted in the timezone of the request's store: 31 January gives 28 or 29 February, 31 March gives 30 April. The date does not move off weekends. A request that is not final is overdue once that day has passed.
- A run stops at the first failure. Entities run in ascending sort order, the customer account last. Each entity runs in its own database transaction together with its progress row. The first entity that throws is rolled back, the request becomes
failedwith that entity's code, and nothing after it runs, so the account never goes while an earlier entity failed. A retry resumes after the entities already done, and running an entity twice leaves the same state as running it once. - Orders are anonymised, never deleted. The order entity (package
hryvinskyi/magento2-gdpr-sales) has no deleter. Its anonymiser keeps every amount, tax, currency, SKU, product name, quantity, status, store, date, country, region and payment method, and replaces only the fields the erasure rule names. - Erasure rules per website. Each entity has a method and a list of fields the store can change, and an entity that supports it can be anonymised by age.
- One archive for an export. Every enabled format (JSON, one CSV file per section, one HTML page, a PDF) goes into one ZIP archive under
var/hryvinskyi_gdpr/exports/. A download link holds a token that is stored only as a SHA-256 hash and expires with the archive. - The privacy action log never holds personal data. Its rows hold codes, ids, counts, the subject key and the admin username. The subject key is a keyed hash of the subject's identity, not of its address: the account for a customer, the address in its website for a guest. A customer who changes their e-mail address keeps their key, and a customer and a guest of one address are two subjects with a place each for an open request of a kind. Never an e-mail address, a name, an address, an IP address, a phone number or a token. The log is append-only: the module has no code path that updates or deletes a row.
- E-mails go only to requests the subject made. A request of origin
customerorguestsends an accepted, confirmation, completed or export-ready e-mail. A request made by an operator, from the command line or by the automatic clean-up sends the subject nothing. An e-mail names the request and never the subject. - Guests prove an order. A guest names an order number, its e-mail address and the billing lastname or postcode. The installed ownership verifiers are asked in turn until one matches. The answer is the same whether or not the claim matches, and no e-mail is sent while the claim is answered: a match only adds its database writes. Only the order's own address receives an e-mail. A match waits for the guest to confirm through the e-mailed link. The confirmation e-mail is sent by cron within minutes, and its link lasts for the confirmation window counted from the moment it is sent. Confirming and cancelling with the link keep working while the storefront features are off, so a guest can always finish or withdraw what was started.
- For operators. A request is made by customer id, or by e-mail address and website with an optional subject kind (
customerorguest). Kindguestnames the guest of an address even when an account holds it. The same references work in the REST routes (fieldsubjectKind,subject_kindin a JSON body) and in the command line (--guest). - Clean-up on a schedule. Age-based anonymisation anonymises the records older than the months set in an entity's rule, for every subject. The inactive-subject clean-up creates an automatic erase or anonymise request for each subject whose activity is older than the configured months. Both are off by default.
Requirements
- Magento Open Source or Adobe Commerce 2.4.8 or 2.4.9, PHP 8.3 to 8.5 and
ext-intl. - The suite's packages:
hryvinskyi/magento2-gdpr-api^1.0,hryvinskyi/magento2-rate-limit^1.0,hryvinskyi/magento2-document-export^1.0,hryvinskyi/magento2-clock^1.0 andhryvinskyi/magento2-logger^1.2. - The platform's Store, Customer, Email, Cron, Webapi, Backend, Config, Authorization, Integration and User modules,
psr/clock,psr/logand a console component (whatcomposer.jsonandetc/module.xmldeclare). - Magento's cron must run. Requests are carried out by the
hryvinskyi_gdprcron group.
Installation
Run from the Magento root. hryvinskyi/magento2-gdpr-pack installs this module with the screens, the storefront pages, the GraphQL schema and the providers. To install the engine alone:
composer require hryvinskyi/magento2-gdpr
bin/magento module:enable Hryvinskyi_GdprApi Hryvinskyi_Clock Hryvinskyi_RateLimit Hryvinskyi_DocumentExport Hryvinskyi_Logger Hryvinskyi_Gdpr
bin/magento setup:upgrade
bin/magento setup:di:compile # production mode only
bin/magento cache:flush
On its own the engine knows two kinds of data, the customer account and its addresses, and is driven by the command line and the REST routes. The kinds of data other modules add are in Entities.
To check the install, print the plan of an export. It changes nothing.
bin/magento gdpr:export --customer-id=<customer_id> --dry-run
Dry run; nothing was changed.
customer_address 1
customer 1
Every installed entity is listed, in the order a run takes them, with the number of records the subject holds. Replace <customer_id> with the id of an account.
Configuration
Settings are in the section hryvinskyi_gdpr. The admin screen of them is in hryvinskyi/magento2-gdpr-admin-ui (Stores › Configuration › Hryvinskyi Extensions › Data Subject Rights (GDPR)); this module ships the defaults and reads them. The Scope column is the lowest scope a value can be set at. Without that package, set a value with bin/magento config:set <path> <value>, which stores the value shown in the Default column.
| Path | Default | Scope | Meaning |
|---|---|---|---|
hryvinskyi_gdpr/general/enabled |
1 |
store view | The storefront features are on. A signed-in customer is refused, with one fixed message, by the store the account belongs to, whichever store the customer browses: the customer's own REST routes and GraphQL mutations, and every page that offers the privacy features. A guest's submission is refused by the store it is made in. Confirming and cancelling a guest's request with its e-mailed link keep working. Operators, the command line and cron are never refused. |
hryvinskyi_gdpr/requests/destructive_delay_minutes |
60 |
website | Whole minutes, 0 to 10080, between the moment an erase or anonymise request is scheduled and the moment it may run. |
hryvinskyi_gdpr/requests/guest_enabled |
1 |
store view | The guest flow is on. |
hryvinskyi_gdpr/requests/guest_confirmation_hours |
24 |
website | 1 to 168. How long a guest has to confirm, counted from the moment the confirmation e-mail is sent, before the request expires. |
hryvinskyi_gdpr/requests/guest_rate_limit |
5 |
website | 1 to 100 claims per window, counted for each client address and for each order number. |
hryvinskyi_gdpr/requests/guest_rate_window_minutes |
15 |
website | 1 to 1440. The length of that window. |
hryvinskyi_gdpr/export/formats |
json,csv,html,pdf |
website | The formats in every archive: codes from the renderer pool, comma separated. When no stored format is installed, the archive holds JSON alone and a warning is logged. |
hryvinskyi_gdpr/export/archive_lifetime_hours |
168 |
website | 1 to 720. The archive and its download links are deleted after this time. |
hryvinskyi_gdpr/email/identity |
general |
store view | The sender of every e-mail. |
hryvinskyi_gdpr/email/request_accepted_template |
hryvinskyi_gdpr_email_request_accepted_template |
store view | Template of the accepted e-mail. |
hryvinskyi_gdpr/email/request_completed_template |
hryvinskyi_gdpr_email_request_completed_template |
store view | Template of the completed e-mail. |
hryvinskyi_gdpr/email/export_ready_template |
hryvinskyi_gdpr_email_export_ready_template |
store view | Template of the export-ready e-mail. |
hryvinskyi_gdpr/email/guest_confirmation_template |
hryvinskyi_gdpr_email_guest_confirmation_template |
store view | Template of the guest confirmation e-mail. |
hryvinskyi_gdpr/erasure/rules |
empty | website | A JSON object of erasure rules (below). Empty gives every entity its defaults. |
hryvinskyi_gdpr/retention/enabled |
0 |
default | Age-based anonymisation is on. |
hryvinskyi_gdpr/inactivity/enabled |
0 |
default | The inactive-subject clean-up is on. |
hryvinskyi_gdpr/inactivity/months |
36 |
default | 1 to 600. A subject is inactive when every source's last activity is older than this. |
hryvinskyi_gdpr/inactivity/type |
anonymise |
default | erase or anonymise: the type of request the clean-up creates. |
hryvinskyi_gdpr/inactivity/batch_size |
100 |
default | 1 to 1000 subjects queued in one run, across all sources (customer logins, and guest orders when hryvinskyi/magento2-gdpr-sales is installed). Each source is read in pages of this size, up to ten times this many of its candidates per run. |
crontab/hryvinskyi_gdpr/jobs/hryvinskyi_gdpr_run_due/schedule/cron_expr |
*/5 * * * * |
default | Schedule of the job that runs due requests. |
crontab/hryvinskyi_gdpr/jobs/hryvinskyi_gdpr_housekeeping/schedule/cron_expr |
17 * * * * |
default | Schedule of the housekeeping job. |
crontab/hryvinskyi_gdpr/jobs/hryvinskyi_gdpr_guest_mail/schedule/cron_expr |
* * * * * |
default | Schedule of the job that sends the guests' confirmation e-mails. |
crontab/hryvinskyi_gdpr/jobs/hryvinskyi_gdpr_retention/schedule/cron_expr |
40 3 * * * |
default | Schedule of the job that runs the age-based anonymisation and then the inactive-subject clean-up. |
hryvinskyi_gdpr/developer/log_enabled |
1 |
default | The GDPR log channel writes var/log/hryvinskyi/gdpr.log. |
hryvinskyi_gdpr/subject/key_secret |
made at install | default | The secret every subject key is made with: 32 random bytes, encrypted with the store's encryption key. setup:upgrade creates it once and never replaces it; changing or deleting it orphans the subject key of every stored request and log row. A new store encryption key keeps it readable. It is sensitive configuration: app:config:dump writes it to app/etc/env.php, never to the shared app/etc/config.php. Never set it by hand. |
The admin screen validates every value. config:set does not, so the code reads defensively: the delay, the confirmation hours and the guest limit and window are clamped into their range, an archive lifetime below 1 reads as 1, and an inactivity setting below 1 keeps the inactive-subject clean-up from running, and an inactivity setting above its range reads as the top of it.
Erasure rules
hryvinskyi_gdpr/erasure/rules is a JSON object keyed by entity code. Every part of an entry may be left out, and a left-out part is the entity's default.
{
"order": {"method": "anonymise", "fields": ["customer_email", "firstname", "lastname", "street"], "retention_months": 72},
"quote": {"method": "delete"}
}
methodisdeleteoranonymise, and applies to aneraserequest. Ananonymiserequest ignores it.fieldslists the fields an anonymisation replaces; each one must be a field the entity describes.retention_monthsis a whole number of 1 or more: the age, in months, after which the entity's records are anonymised for everyone when age-based anonymisation is on. Only an entity whose provider can anonymise by age has it; today that isorder.
An entry the engine cannot read (a method that is neither delete nor anonymise, fields that are not a list of texts, a retention that is not a whole number of 1 or more) is left out with a warning that names the entity, so that entity runs on its defaults and every other entry still applies. A stored value that is no JSON object gives no rules, with one warning. Some entries are valid JSON the entity cannot use, and these are ignored without a warning: a method the entity does not support (the entity's default method applies), a field the entity does not describe (the known fields still apply, and the entity's default fields apply when none is known), and a retention on an entity that cannot be anonymised by age (it does nothing).
Timezone
Moments are stored in UTC. A request's respond-by date and its overdue flag count the day in the timezone of the request's store, which is general/locale/timezone at website scope; the time in an e-mail and in an export is told in that timezone too. A store view that no longer exists takes the default scope's timezone, and a value PHP does not know gives UTC. Cron and the command line run in the default store view's timezone unless a store is emulated, and a request runs in an emulation of its own store view. hryvinskyi/magento2-clock has the rules.
Entities
An entity is one kind of personal data. A run takes them in ascending sort order.
| Entity code | Data | Sort order | Default method | Erase | Anonymise | Package |
|---|---|---|---|---|---|---|
newsletter_subscriber |
Newsletter subscription | 300 | delete | yes | no | hryvinskyi/magento2-gdpr-newsletter |
quote |
Shopping carts | 400 | delete | yes | yes | hryvinskyi/magento2-gdpr-sales |
order |
Orders | 500 | anonymise | no | yes, and by age | hryvinskyi/magento2-gdpr-sales |
review |
Product reviews | 600 | anonymise | yes | yes | hryvinskyi/magento2-gdpr-review |
wishlist |
Wishlist | 700 | delete | yes | no | hryvinskyi/magento2-gdpr-wishlist |
customer_address |
Customer addresses | 900 | delete | yes | yes | this module |
customer |
Customer account | 1000 | delete | yes | yes | this module |
The customer account runs last on purpose. An entity that supports only one method uses it for every request type.
Stored data
The module creates five tables. A time stored in them is UTC.
| Table | What it holds |
|---|---|
hryvinskyi_gdpr_request |
One row per request. Identity: request_id (32 hexadecimal characters, public), type, status, origin, subject_kind, customer_id (no foreign key, kept after the account is deleted), website_id, store_id. Subject: subject_email and subject_key. Time: requested_at, respond_by (a date), confirmed_at, execute_after, started_at, finished_at. Run: lease_until, run_token, attempts, failure_reason (entity_failed, error, interrupted or subject_missing), failed_entity. Guest link: access_token_hash, access_token_expires_at. Archive: archive_file, archive_expires_at, archive_deleted_at. Admin who made the request: admin_user_id. One more column, open_slot, carries the unique index that allows one open request of a kind for a subject. |
hryvinskyi_gdpr_request_entity |
One row for each entity a request has finished: entity_code, records, finished_at. Unique for a request and an entity, deleted with the request. A retry skips these entities. |
hryvinskyi_gdpr_download_token |
The SHA-256 hash of each download token (the token itself is never stored), its request and expires_at. |
hryvinskyi_gdpr_guest_mail |
The confirmation e-mails of guest requests waiting for the cron job that sends them: request_entity_id (unique, deleted with the request), attempts, created_at. A row is written in the transaction that writes its request. |
hryvinskyi_gdpr_action_log |
The privacy action log: occurred_at, action, actor_type (admin, customer, guest, cli, cron, integration, runner or subject), actor_id, actor_name (an admin username), request_id, subject_kind, customer_id, subject_key, entity_code, records, detail_code. |
Which columns of a request are cleared, and when:
| Column | Held until |
|---|---|
subject_email |
The request is final. A run needs the address to reach rows an account no longer links, so it is kept until the update that makes the request final clears it. The last e-mail to the subject goes to the address the run read when it claimed the request. |
access_token_hash, access_token_expires_at |
The request is final. They are empty until the cron job sends the confirmation e-mail, which issues the token. A guest's token also stops confirming while the request waits for confirmation once access_token_expires_at has passed. |
open_slot |
The request is final, in the same update, which frees the subject to make another request. |
run_token, lease_until |
The run ends, or the housekeeping job fails a run whose lease has ended. |
failure_reason, failed_entity |
A retry. The privacy action log keeps the history. |
archive_file |
Stays. archive_deleted_at is set when the cleanup deletes the file after archive_expires_at. |
subject_key |
Never. It is a keyed hash of the subject's identity (customer|<account id>, or guest|<website id>|<trimmed lower-case address>) under the installed secret, which finds a subject's requests and log rows without storing the address. |
An export archive is var/hryvinskyi_gdpr/exports/<32 random hexadecimal characters>.zip. The directory has mode 0770 and each file mode 0660, and nothing is written below pub/. The archive holds data.json, a <section>.csv for each section, data.html and data.pdf, for the formats the website enables.
The privacy action log records these actions (Hryvinskyi\GdprApi\Api\Data\JournalAction): request_created, request_confirmed, request_cancelled, request_expired, request_started, entity_processed, request_completed, request_failed, request_retried, request_interrupted, export_downloaded, archive_deleted, reauth_failed, retention_anonymised and inactive_subject_queued. Nothing deletes a log row.
Limits
- Orders are never deleted. A store keeps them for its accounts. They are anonymised, and an anonymised order stays in the sales grids without its personal details.
- A guest subject covers only what an e-mail address ties together. A review or a wishlist cannot be tied to an address, so a guest request touches neither. A customer subject covers rows by customer id and never a guest order that happens to carry the account's address; an operator makes a second request for the guest subject of that address.
- The guest limit counts per client address. Behind a proxy that does not pass the client address on, every shopper has the proxy's address and shares one limit. Configure the web server or the platform's
Magento\Framework\HTTP\PhpEnvironment\RemoteAddress(itsalternativeHeadersargument, and itstrustedProxiesargument where the installed Magento has it) so the client address is the real one. The limit also counts per order number, whatever the address. - Counters are approximate. The guest limit lives in the cache; a cache that fails grants every attempt.
- No automatic retry. A failed request waits for an operator: the retry action of the admin screen, the
retryREST route, orgdpr:run-scheduled --retry=<request_id>. - A customer's destructive request needs the account's password. The service checks it as a sign-in, so a wrong password counts towards the lockout, and a locked account is refused with its own message even with the right password. An owner who does not know the account's password (a sign-up through a social login, for example) sets one first.
- Only installed providers count. Data kept by a module that registers no entity provider is not exported, erased or anonymised. Add a provider (below) for it.
- An archive is personal data. Keep
var/out of the web root and out of backups that outlive the archive lifetime. A link works only with its token. - Anonymisation cannot be undone. Values are replaced by deterministic values for the request, so a repeated run writes the same values, but the originals are gone.
- No storefront pages. The module binds no storefront links, so its e-mails carry none.
hryvinskyi/magento2-gdpr-frontendprovides them.
Registrations
Cron
Cron group hryvinskyi_gdpr (use_separate_process 1).
| Job | Class | Does |
|---|---|---|
hryvinskyi_gdpr_run_due |
Hryvinskyi\Gdpr\Cron\RunDueRequests |
Runs up to 20 due requests. |
hryvinskyi_gdpr_housekeeping |
Hryvinskyi\Gdpr\Cron\Housekeeping |
Expires unconfirmed guest requests, fails a running request whose lease ended (reason interrupted), deletes expired archives and download tokens. |
hryvinskyi_gdpr_guest_mail |
Hryvinskyi\Gdpr\Cron\SendGuestConfirmations |
Every minute, sends up to 50 queued guest confirmation e-mails, each with a new link. A failed e-mail stays queued and is tried at the next run; after the fifth failure it is dropped, the request expires and the failure is logged without the address. |
hryvinskyi_gdpr_retention |
Hryvinskyi\Gdpr\Cron\Retention |
Runs the age-based anonymisation in batches of 200, then the inactive-subject clean-up. |
Each step of a job runs on its own, so a step that fails is logged by its name and the exception's class and code, and the steps after it still run.
Command line
Run from the Magento root. Each command makes a request of origin cli, with no delay, and runs it at once.
| Command | Options | Does |
|---|---|---|
gdpr:export |
--customer-id, --email with --website, --guest, --dry-run |
Exports the subject's data and prints the archive path. |
gdpr:erase |
the same, and --type=erase|anonymise (default erase) |
Erases or anonymises the subject's data. It asks This cannot be undone. Continue? [y/N] unless run with -n. |
gdpr:run-scheduled |
--limit=<n> (default 20), --retry=<request_id>, --cancel=<request_id> |
Runs the due requests, or retries one failed request now, or cancels one waiting or failed request. --retry and --cancel exclude each other. |
--dry-run prints each entity with its record count, and with its method for gdpr:erase, and changes nothing. The exit code is 0 for a completed request, 1 when the request did not complete or was refused, and 2 for input the command cannot use.
bin/magento gdpr:erase --customer-id=<customer_id> --dry-run bin/magento gdpr:erase --email=<address> --website=<website_id> --guest --type=anonymise -n bin/magento gdpr:run-scheduled --retry=<request_id>
REST routes
| Method | URL | Service method | Resource |
|---|---|---|---|
| POST | /V1/gdpr/mine/requests |
CustomerRequestManagementInterface::create |
self |
| GET | /V1/gdpr/mine/requests |
CustomerRequestManagementInterface::getList |
self |
| POST | /V1/gdpr/mine/requests/:requestId/cancel |
CustomerRequestManagementInterface::cancel |
self |
| POST | /V1/gdpr/mine/requests/:requestId/download-link |
CustomerRequestManagementInterface::issueDownloadLink |
self |
| POST | /V1/gdpr/guest/requests |
GuestRequestManagementInterface::submit |
anonymous |
| POST | /V1/gdpr/guest/requests/:requestId/confirm |
GuestRequestManagementInterface::confirm |
anonymous |
| POST | /V1/gdpr/guest/requests/:requestId/cancel |
GuestRequestManagementInterface::cancel |
anonymous |
| GET | /V1/gdpr/requests |
AdminRequestManagementInterface::getList |
Hryvinskyi_Gdpr::requests |
| GET | /V1/gdpr/requests/:requestId |
AdminRequestManagementInterface::get |
Hryvinskyi_Gdpr::requests |
| POST | /V1/gdpr/requests/export |
AdminExportRequestInterface::create |
Hryvinskyi_Gdpr::request_export |
| POST | /V1/gdpr/requests/erase |
AdminEraseRequestInterface::create |
Hryvinskyi_Gdpr::request_erase |
| POST | /V1/gdpr/requests/anonymise |
AdminAnonymiseRequestInterface::create |
Hryvinskyi_Gdpr::request_anonymise |
| POST | /V1/gdpr/requests/:requestId/cancel |
AdminRequestActionsInterface::cancel |
Hryvinskyi_Gdpr::request_cancel |
| POST | /V1/gdpr/requests/:requestId/retry |
AdminRequestActionsInterface::retry |
Hryvinskyi_Gdpr::request_retry |
The mine routes take the customer id from the customer token and never from the body. The guest submission is made in the store the URL's store code selects. An admin route that creates, cancels or retries journals the token's own user (an admin user, or an integration), never an actor the caller sends. An admin creates a request with a subject reference:
{"subject": {"email": "<address>", "website_id": 1, "subject_kind": "guest"}}
subject_kind is optional. Without it, an address names the account that holds it in the website, else the guest.
ACL resources
The tree is Customers (Magento_Customer::customer) › Data Subject Requests (Hryvinskyi_Gdpr::gdpr).
| Resource ID | Title |
|---|---|
Hryvinskyi_Gdpr::requests |
View requests |
Hryvinskyi_Gdpr::request_export |
Create export requests |
Hryvinskyi_Gdpr::request_erase |
Create erase requests |
Hryvinskyi_Gdpr::request_anonymise |
Create anonymise requests |
Hryvinskyi_Gdpr::request_cancel |
Cancel requests |
Hryvinskyi_Gdpr::request_retry |
Retry failed requests |
Hryvinskyi_Gdpr::export_download |
Download export archives |
Hryvinskyi_Gdpr::action_log |
View the privacy action log |
Hryvinskyi_Gdpr::config |
Data Subject Rights (GDPR), under Stores › Settings › Configuration |
The constants are on Hryvinskyi\Gdpr\Api\AclResourcesInterface, which other modules name instead of the strings.
E-mail templates
All four are HTML templates of the storefront area, listed under Marketing › Communications › Email Templates.
| Template ID | Label | File | Chosen by |
|---|---|---|---|
hryvinskyi_gdpr_email_request_accepted_template |
Data Subject Request Accepted | view/frontend/email/request_accepted.html |
hryvinskyi_gdpr/email/request_accepted_template |
hryvinskyi_gdpr_email_request_completed_template |
Data Subject Request Completed | view/frontend/email/request_completed.html |
hryvinskyi_gdpr/email/request_completed_template |
hryvinskyi_gdpr_email_export_ready_template |
Data Subject Export Ready | view/frontend/email/export_ready.html |
hryvinskyi_gdpr/email/export_ready_template |
hryvinskyi_gdpr_email_guest_confirmation_template |
Data Subject Request Confirmation (Guest) | view/frontend/email/guest_confirmation.html |
hryvinskyi_gdpr/email/guest_confirmation_template |
A template may print request_type_label, respond_by, store_frontend_name and the variables of its own e-mail: execute_after, archive_expires_at, and the links confirm_url, cancel_url, download_url and privacy_url. A link variable is absent when the store has no storefront page for it, so wrap it in {{depend …}}. No variable carries the subject's name, address or orders; the subject's address is only the recipient.
Routes and layout
The module registers no storefront or admin route and no layout handle. One base template, Hryvinskyi_Gdpr::export/document.phtml, renders the HTML export.
Preferences
Every Hryvinskyi\GdprApi\Api\… service and factory interface has a preference to a class of Hryvinskyi\Gdpr\Model\…, with one default: SubjectLinksInterface is bound to Model\Links\NoSubjectLinks, which returns no link. A module that provides storefront pages replaces that preference.
Extension points
The contracts are in hryvinskyi/magento2-gdpr-api. A module registers its part in its own etc/di.xml, in the global di.xml and never in an area one, because an area di.xml that names an argument replaces the whole list. Each pool takes its items by key.
Add an entity provider
A provider is a virtual type of Hryvinskyi\Gdpr\Model\Entity\EntityProvider, a holder of two required parts and three optional ones, and an item of the pool keyed by the entity code.
<virtualType name="Vendor\Module\Model\Provider\TicketProvider" type="Hryvinskyi\Gdpr\Model\Entity\EntityProvider"> <arguments> <argument name="description" xsi:type="object">Vendor\Module\Model\Provider\TicketDescription</argument> <argument name="exporter" xsi:type="object">Vendor\Module\Model\Provider\TicketExporter</argument> <argument name="deleter" xsi:type="object">Vendor\Module\Model\Provider\TicketDeleter</argument> <argument name="anonymiser" xsi:type="null"/> </arguments> </virtualType> <type name="Hryvinskyi\Gdpr\Model\Entity\EntityProviderPool"> <arguments> <argument name="providers" xsi:type="array"> <item name="ticket" xsi:type="object">Vendor\Module\Model\Provider\TicketProvider</item> </argument> </arguments> </type>
The arguments of the holder are description and exporter, which are required, and deleter, anonymiser and agedRecordAnonymiser, which are optional; an optional part left out or set to null is not supported, and the engine never asks for it. The pool checks every provider the first time it is used and throws \LogicException for an item that is not an entity provider, a code outside ^[a-z][a-z0-9_]{0,63}\z, two providers with one code, a key that differs from the code, a default method the provider has no part for, and a provider other than the customer account sorted at or above EntityDescriptionInterface::ACCOUNT_SORT_ORDER (1000): the account runs last.
What a provider must keep to:
- Read the rows of a customer subject by its customer id, and the rows of a guest subject by its e-mail address in its website where no customer id is set. Never add the rows of the customer's e-mail address to a customer subject.
- Never begin or commit a transaction on a connection itself: the runner wraps each entity in a transaction, so after-commit callbacks run when it commits. The repositories a provider calls may nest their own.
- Be idempotent. Deleting what is gone deletes 0 rows, and anonymising what is anonymised changes nothing. Anonymised values come from the instruction, which makes them deterministic for the request, the entity, the record and the field.
- Throw, and do not log, when something fails. The runner logs the request id, the entity code and the exception's class and code, never its message, which can carry a value.
- Put the field codes an anonymiser can replace in
getFieldTypes()(field code to field type), a subset of them ingetDefaultFields(), and replace only a field the instruction includes:AnonymisationInstructionInterface::replacement()throws for one it does not.
Add a field type
A field type is an item of Hryvinskyi\Gdpr\Model\Anonymisation\FieldAnonymiserPool, keyed by the type code a description uses. The module ships email, name, phone, address, ip, free_text and date_of_birth. A strategy that replaces a value with a fixed text is a virtual type of FixedTextAnonymiser:
<virtualType name="Vendor\Module\Model\Anonymisation\TicketReferenceAnonymiser" type="Hryvinskyi\Gdpr\Model\Anonymisation\FixedTextAnonymiser"> <arguments> <argument name="text" xsi:type="string">REMOVED</argument> </arguments> </virtualType> <type name="Hryvinskyi\Gdpr\Model\Anonymisation\FieldAnonymiserPool"> <arguments> <argument name="anonymisers" xsi:type="array"> <item name="ticket_reference" xsi:type="object">Vendor\Module\Model\Anonymisation\TicketReferenceAnonymiser</item> </argument> </arguments> </type>
A description that names a type no pool item has makes building the anonymisation instruction throw, naming the type. Other strategies implement Hryvinskyi\GdprApi\Api\Anonymisation\FieldAnonymiserInterface, take the replacement from the seed (AnonymisationSeedInterface::token() is a keyed hash of the request, entity, record and field), and are registered the same way.
Add an export format
A renderer implements Hryvinskyi\GdprApi\Api\Export\ExportRendererInterface and is an item of Hryvinskyi\Gdpr\Model\Export\ExportRendererPool, keyed by the format code. It returns the files of the format as a map of relative path to bytes; a path matches ^[a-z0-9][a-z0-9_./-]*\z and has no ... The format is then offered in hryvinskyi_gdpr/export/formats.
<type name="Hryvinskyi\Gdpr\Model\Export\ExportRendererPool"> <arguments> <argument name="renderers" xsi:type="array"> <item name="xml" xsi:type="object">Vendor\Module\Model\Export\XmlRenderer</item> </argument> </arguments> </type>
Add a guest ownership check, or an inactivity source
Hryvinskyi\Gdpr\Model\Guest\GuestOwnership::verifierstakesHryvinskyi\GdprApi\Api\Guest\GuestOwnershipVerifierInterfaceitems. With none installed, every guest claim fails and the guest still gets the same answer.Hryvinskyi\Gdpr\Model\Inactivity\InactiveSubjects::sourcestakesInactiveSubjectSourceInterfaceitems, which propose subjects, and::activitiestakesSubjectActivityInterfaceitems, which tell when a subject was last active. A subject is inactive when every activity is older than the configured months, or when it has no activity at all and its account is older than that. An anonymised subject (an address in the.invalidtop-level domain), a subject with an open request, and a subject whose last completed erase or anonymise finished after its last activity are never queued. A source names its candidates in one stable order, the longest inactive first, and returns the page the limit and the offset ask for; it returns fewer than the limit only when it has no more, since the clean-up then reads no further page.
The log channel
The GDPR log is a virtual type pair, Hryvinskyi\Gdpr\Model\Log\Handler (file /var/log/hryvinskyi/gdpr.log, switched by hryvinskyi_gdpr/developer/log_enabled) and Hryvinskyi\Gdpr\Model\Log\Logger. A class of the suite that logs takes it as its logger, and so can yours:
<type name="Vendor\Module\Model\SomeService"> <arguments> <argument name="logger" xsi:type="object">Hryvinskyi\Gdpr\Model\Log\Logger</argument> </arguments> </type>
Log ids, codes and exception classes. Never log an e-mail address, a name or a token.
Listing sources
Screens that list requests or the privacy action log read the resource models Hryvinskyi\Gdpr\Model\ResourceModel\Request and Hryvinskyi\Gdpr\Model\ResourceModel\ActionLog (column constants on both), and may name them in di.xml:
<virtualType name="Vendor\Module\Ui\DataProvider\RequestSearchResult" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult"> <arguments> <argument name="mainTable" xsi:type="string">hryvinskyi_gdpr_request</argument> <argument name="resourceModel" xsi:type="string">Hryvinskyi\Gdpr\Model\ResourceModel\Request</argument> </arguments> </virtualType>
The collection of the privacy action log, Hryvinskyi\Gdpr\Model\ResourceModel\ActionLog\Collection, is read-only: its items have no save or delete.
Tests
Run from the Magento root.
- Unit:
vendor/bin/phpunit -c app/code/Hryvinskyi/Gdpr/phpunit.xml.dist. - Integration: the platform's harness in
dev/tests/integration, against its own database, one run at a time.cd dev/tests/integration && php -d memory_limit=4G ../../../vendor/bin/phpunit -c phpunit.xml ../../../app/code/Hryvinskyi/Gdpr/Test/Integration. - Static analysis: PHPStan 2.x at level 10 with the package's
phpstan.neon.dist(phpstan analyse -c app/code/Hryvinskyi/Gdpr/phpstan.neon.dist --level=10), andvendor/bin/phpcs --standard=app/code/Hryvinskyi/Gdpr/phpcs.xml.dist app/code/Hryvinskyi/Gdpr.
Translations
The e-mail templates, messages and labels ship in en_US and 25 more locales: the official languages of the European Union, Norwegian Bokmål and Ukrainian. The translations are machine-made; have them read by a native speaker before a store relies on them, and override a phrase in a theme or a language pack.