Customers page: export, correct and erase personal data; automatic retention
Admin /customers finds a customer by name, email, phone or notes (orders and unpaid checkouts), exports everything stored as JSON, corrects details on every record, and erases them — anonymising orders (amounts, services and dates stay for the accounts) and deleting unpaid checkouts. A daily cron (and PocketBase start) deletes unpaid checkouts after N days and, when set, anonymises orders after M months, skipping orders with a booking ahead. A paid basket's copy of the details is cleared when its order is created. All writes are in pocketbase/pb_hooks/privacy (orders and baskets are superuser-only); migration 1793000000 makes orders.email optional and adds orders.anonymisedAt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VaXE9U7AmW3dfD2w6cbLfk
This commit is contained in:
parent
5828d65a00
commit
971efebcdb
13 changed files with 749 additions and 8 deletions
40
pocketbase/pb_migrations/1793000000_orders_anonymise.js
Normal file
40
pocketbase/pb_migrations/1793000000_orders_anonymise.js
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/// <reference path="../pb_data/types.d.ts" />
|
||||
|
||||
// GDPR erasure keeps an order (amounts, services, dates — needed for the
|
||||
// accounts) but strips who it was for. See pb_hooks/privacy/lib.js.
|
||||
//
|
||||
// 1. orders.email no longer required: an anonymised order has none.
|
||||
// 2. orders.anonymisedAt: when the personal details were removed.
|
||||
// 3. Index orders.email, for looking a customer up in the admin.
|
||||
|
||||
function find(app, name) {
|
||||
try {
|
||||
return app.findCollectionByNameOrId(name);
|
||||
} catch (e) {
|
||||
return null; // fresh install: pb_schema.json (already in this shape) is imported later
|
||||
}
|
||||
}
|
||||
|
||||
migrate(
|
||||
(app) => {
|
||||
const orders = find(app, 'orders');
|
||||
if (!orders) return;
|
||||
const email = orders.fields.getByName('email');
|
||||
if (email) email.required = false;
|
||||
if (!orders.fields.getByName('anonymisedAt')) {
|
||||
orders.fields.add(new DateField({ id: 'date_ordanonym01', name: 'anonymisedAt' }));
|
||||
}
|
||||
if (!orders.indexes.some((index) => index.includes('idx_orders_email'))) {
|
||||
orders.indexes = [...orders.indexes, 'CREATE INDEX `idx_orders_email` ON `orders` (`email`)'];
|
||||
}
|
||||
app.save(orders);
|
||||
},
|
||||
(app) => {
|
||||
// Anonymised orders have an empty email, so `required` is not restored.
|
||||
const orders = find(app, 'orders');
|
||||
if (!orders) return;
|
||||
if (orders.fields.getByName('anonymisedAt')) orders.fields.removeByName('anonymisedAt');
|
||||
orders.indexes = orders.indexes.filter((index) => !index.includes('idx_orders_email'));
|
||||
app.save(orders);
|
||||
}
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue