Member erase: their username leaves the messages that stay (another member's chat to them, a notice to their sponsor about them), whole words, 5+ characters; names option for a second pass after the account is gone; residue sweep also finds a long username inside text (REGEXP whole word)
Found on the LS-1021 erase: two kept messages still said "rajumiddha". qa/erase.mysql.test.cjs 3 pass (disposable mysql:8 on core), qa/erase.test.cjs 6 pass. NOT deployed (one InstantAdPay deploy today for this lane); ships with the next one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -76,9 +76,10 @@ async function residue(E, exact) {
|
||||
const cols = await db.q("SELECT table_name t, column_name c FROM information_schema.columns WHERE table_schema = DATABASE() AND data_type IN ('char','varchar','text','mediumtext','longtext','json') AND table_name NOT IN ('docs','docs_writer')");
|
||||
const out = [];
|
||||
for (const r of cols) {
|
||||
const t = r.t || r.TABLE_NAME, c = r.c || r.COLUMN_NAME; const ex = exact.filter(Boolean);
|
||||
const where = '`' + c + '` LIKE ?' + ex.map(() => ' OR `' + c + '` = ?').join('');
|
||||
try { const [x] = await db.q('SELECT COUNT(*) n FROM `' + t + '` WHERE ' + where, [like(E)].concat(ex)); if (Number(x.n)) out.push({ table: t, column: c, n: Number(x.n) }); } catch (e) {}
|
||||
const t = r.t || r.TABLE_NAME, c = r.c || r.COLUMN_NAME; const ex = exact.filter(Boolean); const words = ex.filter(x => x.length >= 5); // a long username inside text too
|
||||
const where = '`' + c + '` LIKE ?' + ex.map(() => ' OR `' + c + '` = ?').join('') + words.map(() => ' OR `' + c + '` REGEXP ?').join('');
|
||||
const wordRe = w => '(^|[^a-z0-9_])' + w.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '([^a-z0-9_]|$)'; // the whole word, not a longer name
|
||||
try { const [x] = await db.q('SELECT COUNT(*) n FROM `' + t + '` WHERE ' + where, [like(E)].concat(ex, words.map(wordRe))); if (Number(x.n)) out.push({ table: t, column: c, n: Number(x.n) }); } catch (e) {}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -128,7 +129,9 @@ async function erase(email, opts) {
|
||||
const o = Object.assign({ dryRun: true, force: false, by: 'admin', sweep: true }, opts || {});
|
||||
const E = norm(email); if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(E)) return { error: 'A valid email is required.' };
|
||||
const h = hashOf(E); const acct = await R.accounts.byEmail(E);
|
||||
const exact = acct ? [acct.username, acct.code].filter(Boolean).map(norm) : [];
|
||||
// names: usernames of an account already erased (a second pass after the code learned something new), e.g. ['oldname']
|
||||
const names = (Array.isArray(o.names) ? o.names : []).map(norm).filter(x => /^[a-z0-9_.-]{5,30}$/.test(x));
|
||||
const exact = (acct ? [acct.username, acct.code].filter(Boolean).map(norm) : []).concat(names);
|
||||
const needles = { emails: [E], exact };
|
||||
const blockers = acct ? await blockersOf(acct, E) : [];
|
||||
const res = { dryRun: !!o.dryRun, emailHash: h, found: !!acct, blockers, forced: !!o.force && blockers.length > 0, sql: {}, docs: {} };
|
||||
@@ -153,6 +156,18 @@ async function erase(email, opts) {
|
||||
const mutes = await db.q('SELECT email, chat_mutes FROM accounts WHERE chat_mutes LIKE ?', [like(E)]);
|
||||
let mu = 0; for (const m of mutes) { let list = []; try { list = JSON.parse(m.chat_mutes || '[]'); } catch (e) {} const keep = list.filter(x => norm(x) !== E); if (keep.length !== list.length) { mu++; if (!o.dryRun) await db.q('UPDATE accounts SET chat_mutes=? WHERE email=?', [JSON.stringify(keep), m.email]); } }
|
||||
if (mu) res.sql['accounts.chat_mutes (others, scrubbed)'] = mu;
|
||||
// their username inside messages that stay (another member's chat to them, a notice to their sponsor about them): the name
|
||||
// goes, the message stays. Whole words only, usernames of 5+ characters (a short one could be an ordinary word).
|
||||
let rd = 0;
|
||||
for (const u of exact.filter(x => x.length >= 5 && ((acct && norm(acct.username) === x) || names.includes(x)))) {
|
||||
const re = new RegExp('(^|[^a-z0-9_])@?' + u.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '(?![a-z0-9_])', 'gi');
|
||||
for (const m of await db.q('SELECT id, subject, body FROM sponsor_messages WHERE subject LIKE ? OR body LIKE ?', [like(u), like(u)])) {
|
||||
const sub = String(m.subject || '').replace(re, '$1[erased member]'), body = m.body == null ? null : String(m.body).replace(re, '$1[erased member]');
|
||||
if (sub === m.subject && body === m.body) continue;
|
||||
rd++; if (!o.dryRun) await db.q('UPDATE sponsor_messages SET subject=?, body=? WHERE id=?', [sub, body, m.id]);
|
||||
}
|
||||
}
|
||||
if (rd) res.sql['sponsor_messages (others, name removed)'] = rd;
|
||||
} else if (acct && !o.dryRun) { const r = await R.accounts.removeAccount(E); res.sql.accounts = r && r.ok ? 1 : 0; }
|
||||
else if (acct) res.sql.accounts = 1;
|
||||
res.docs = docs(needles, o.dryRun);
|
||||
|
||||
Reference in New Issue
Block a user