Let Cards players delete their account and read a privacy notice
Add a Compte section with a privacy notice and a confirmed deletion that anonymises the player row, erases their possessions and cancels open trades. The public contact comes from CARDS_PRIVACY_CONTACT, which production now requires before enabling the game. The admin E2E no longer relies on a pull from the previous test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
155187d01f
commit
e60fbd4e9b
16 changed files with 319 additions and 10 deletions
|
|
@ -7,6 +7,7 @@ import { CardsService, DEV_DISCORD_ID } from "./service.js";
|
|||
|
||||
const JSON_LIMIT = 64 * 1024;
|
||||
const DISCORD_TIMEOUT_MS = 10_000;
|
||||
const EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
|
||||
function bool(value, fallback = false) {
|
||||
if (value == null || value === "") return fallback;
|
||||
|
|
@ -131,12 +132,16 @@ export function createCardsApiHandler({
|
|||
// Cette connexion accorde les droits administrateur à n'importe quel visiteur.
|
||||
const devAuth = requestedDevAuth && (env.NODE_ENV !== "production" || allowProductionDevAuth);
|
||||
if (requestedDevAuth && !devAuth) console.error("CARDS_DEV_AUTH is ignored in production.");
|
||||
const configuredContact = String(env.CARDS_PRIVACY_CONTACT || "").trim();
|
||||
const privacyContact = EMAIL_PATTERN.test(configuredContact) ? configuredContact : null;
|
||||
let database = null;
|
||||
let service = null;
|
||||
if (enabled) {
|
||||
if (env.NODE_ENV === "production" && !env.CARDS_DB_PATH) throw new TypeError("CARDS_DB_PATH is required when Sokko TCG is enabled in production.");
|
||||
// Sans origine fixe, le retour OAuth et le contrôle CSRF dépendraient de l'en-tête Host envoyé par le client.
|
||||
if (env.NODE_ENV === "production" && !env.CARDS_PUBLIC_ORIGIN) throw new TypeError("CARDS_PUBLIC_ORIGIN is required when Sokko TCG is enabled in production.");
|
||||
// La notice de confidentialité doit indiquer à qui s'adresser avant d'ouvrir le jeu à de vrais comptes.
|
||||
if (env.NODE_ENV === "production" && !privacyContact) throw new TypeError("CARDS_PRIVACY_CONTACT must be a valid e-mail address when Sokko TCG is enabled in production.");
|
||||
const catalog = loadCardsCatalog(catalogPath);
|
||||
database = new CardsDatabase(databasePath);
|
||||
service = new CardsService({ database, catalog, now, random, devPerks });
|
||||
|
|
@ -179,7 +184,8 @@ export function createCardsApiHandler({
|
|||
enabled,
|
||||
devAuth: enabled && devAuth,
|
||||
discordConfigured: enabled && Boolean(env.DISCORD_CLIENT_ID && env.DISCORD_CLIENT_SECRET),
|
||||
catalog: enabled ? publicCatalog(service.catalog) : null
|
||||
catalog: enabled ? publicCatalog(service.catalog) : null,
|
||||
privacyContact: enabled ? privacyContact : null
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
|
@ -259,6 +265,12 @@ export function createCardsApiHandler({
|
|||
json(res, 200, { ok: true });
|
||||
return true;
|
||||
}
|
||||
if (req.method === "DELETE" && url.pathname === "/api/cards/account") {
|
||||
service.deleteAccount(session.player.id);
|
||||
res.setHeader("Set-Cookie", sessionCookie("", secureCookies, 0));
|
||||
json(res, 200, { ok: true });
|
||||
return true;
|
||||
}
|
||||
if (req.method === "GET" && url.pathname === "/api/cards/state") {
|
||||
json(res, 200, service.getState(session.player.id));
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -187,6 +187,10 @@ const MIGRATIONS = [
|
|||
ALTER TABLE shop_settings ADD COLUMN shop_pack_share INTEGER NOT NULL DEFAULT 50 CHECK (shop_pack_share BETWEEN 0 AND 100);
|
||||
INSERT OR IGNORE INTO collection_states(collection_id, active, updated_at, updated_by) VALUES ('stardust', 1, 0, NULL);
|
||||
INSERT OR IGNORE INTO drop_rates(collection_id, rarity_weights_json, updated_at, updated_by) VALUES ('stardust', '{"common":64,"rare":24,"epic":8,"legendary":3,"mythic":1}', 0, NULL);
|
||||
`,
|
||||
// Suppression de compte : la ligne du joueur reste, anonymisée, car les ouvertures, échanges et journaux y font référence.
|
||||
`
|
||||
ALTER TABLE players ADD COLUMN deleted_at INTEGER;
|
||||
`
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ const PLAYER_HISTORY_EVENTS = Object.freeze([
|
|||
"gift_created", "gift_joined", "gift_completed", "gift_cancelled"
|
||||
]);
|
||||
const DEV_STARDUST = 1000;
|
||||
const DELETED_PLAYER_NAME = "Joueur supprimé";
|
||||
|
||||
export class CardsService {
|
||||
constructor({ database, catalog, now = Date.now, random, devPerks = false } = {}) {
|
||||
|
|
@ -491,7 +492,7 @@ export class CardsService {
|
|||
(SELECT COALESCE(SUM(c.quantity), 0) FROM collection_cards c WHERE c.player_id = p.id) AS total_cards,
|
||||
(SELECT COUNT(*) FROM gift_packs g WHERE g.player_id = p.id AND g.opening_id IS NULL) AS gift_packs,
|
||||
(SELECT COUNT(*) FROM transfers t WHERE t.status = 'completed' AND (t.initiator_id = p.id OR t.recipient_id = p.id)) AS transfers_count
|
||||
FROM players p ORDER BY p.display_name COLLATE NOCASE`).all().map((row) => {
|
||||
FROM players p WHERE p.deleted_at IS NULL ORDER BY p.display_name COLLATE NOCASE`).all().map((row) => {
|
||||
const recharge = this.refreshRecharge(row.id);
|
||||
return {
|
||||
id: row.id,
|
||||
|
|
@ -516,7 +517,7 @@ export class CardsService {
|
|||
generatedAt: now,
|
||||
stats: {
|
||||
totalPlayers: players.length,
|
||||
activePlayers7d: this.db.prepare("SELECT COUNT(DISTINCT player_id) AS count FROM openings WHERE created_at >= ?").get(now - 7 * 24 * 3_600_000).count
|
||||
activePlayers7d: this.db.prepare("SELECT COUNT(DISTINCT o.player_id) AS count FROM openings o JOIN players p ON p.id = o.player_id WHERE o.created_at >= ? AND p.deleted_at IS NULL").get(now - 7 * 24 * 3_600_000).count
|
||||
},
|
||||
players,
|
||||
rechargeSetting: this.rechargeSetting,
|
||||
|
|
@ -663,7 +664,7 @@ export class CardsService {
|
|||
// Joueurs à qui donner ou proposer un échange : seuls leur identité publique et leurs doublons disponibles sont exposés, jamais leur collection.
|
||||
listTraders(playerId) {
|
||||
this.expireTransfers();
|
||||
const rows = this.db.prepare("SELECT id, display_name, avatar_url FROM players WHERE id != ? ORDER BY display_name COLLATE NOCASE").all(playerId);
|
||||
const rows = this.db.prepare("SELECT id, display_name, avatar_url FROM players WHERE id != ? AND deleted_at IS NULL ORDER BY display_name COLLATE NOCASE").all(playerId);
|
||||
return {
|
||||
traders: rows.map((row) => ({
|
||||
id: row.id,
|
||||
|
|
@ -682,7 +683,28 @@ export class CardsService {
|
|||
|
||||
requireRecipient(playerId, recipientId) {
|
||||
if (recipientId === playerId) fail(409, "SELF_TRANSFER", "Vous ne pouvez pas vous envoyer une carte.");
|
||||
if (!recipientId || !this.db.prepare("SELECT 1 FROM players WHERE id = ?").get(recipientId)) fail(404, "PLAYER_NOT_FOUND", "Ce joueur est introuvable.");
|
||||
if (!recipientId || !this.db.prepare("SELECT 1 FROM players WHERE id = ? AND deleted_at IS NULL").get(recipientId)) fail(404, "PLAYER_NOT_FOUND", "Ce joueur est introuvable.");
|
||||
}
|
||||
|
||||
// Efface l'identité Discord et les possessions du joueur. Sa ligne reste, anonymisée, pour que l'historique des autres joueurs garde son sens ;
|
||||
// une reconnexion avec le même compte Discord crée un compte neuf.
|
||||
deleteAccount(playerId) {
|
||||
this.database.transaction(() => {
|
||||
if (!this.db.prepare("SELECT 1 FROM players WHERE id = ? AND deleted_at IS NULL").get(playerId)) fail(404, "PLAYER_NOT_FOUND", "Profil introuvable.");
|
||||
for (const transfer of this.db.prepare("SELECT * FROM transfers WHERE status = 'open' AND (initiator_id = ?1 OR recipient_id = ?1)").all(playerId)) {
|
||||
this.db.prepare("UPDATE transfers SET status = 'cancelled' WHERE id = ?").run(transfer.id);
|
||||
const initiatorLeft = transfer.initiator_id === playerId;
|
||||
this.audit(initiatorLeft ? transfer.recipient_id : transfer.initiator_id, "trade_cancelled", transfer.id, initiatorLeft
|
||||
? { sent: transfer.requested_edition_id, received: transfer.offered_edition_id }
|
||||
: { sent: transfer.offered_edition_id, received: transfer.requested_edition_id });
|
||||
}
|
||||
this.db.prepare("UPDATE openings SET status = 'completed', completed_at = ? WHERE player_id = ? AND status = 'pending'").run(this.now(), playerId);
|
||||
for (const table of ["sessions", "collection_cards", "favorites", "idempotency"]) this.db.prepare(`DELETE FROM ${table} WHERE player_id = ?`).run(playerId);
|
||||
this.db.prepare("DELETE FROM gift_packs WHERE player_id = ? AND opening_id IS NULL").run(playerId);
|
||||
this.db.prepare(`UPDATE players SET discord_id = ?, display_name = ?, avatar_url = '', is_admin = 0, openings_balance = 0, recharge_anchor = NULL, stardust = 0, purchased_openings = 0, deleted_at = ? WHERE id = ?`)
|
||||
.run(`deleted:${randomUUID()}`, DELETED_PLAYER_NAME, this.now(), playerId);
|
||||
this.audit(playerId, "account_deleted", playerId, {});
|
||||
});
|
||||
}
|
||||
|
||||
// Un don arrive immédiatement. Un échange réserve le doublon proposé jusqu'à la réponse, l'annulation ou l'expiration.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue