feat(dashboard): unify secure staff administration

Provide a single /dashboard entry point for owner and staff tools, with Discord OAuth sign-in for approved owner accounts and active staff. Add owner-managed dashboard access grants, staff server health and update visibility, filtering, moderation improvements, item controls, and per-animal clothing restrictions.

Replace staff-triggered password and 2FA resets with email-verified account recovery. Persist validated recovery addresses, use short-lived hashed recovery tokens, expose recovery flows in registration and account pages, and keep mail delivery disabled until its webhook configuration is present.

Cover dashboard aliases, recovery restrictions, Discord access, monitoring, item locks, wear rules, and staff behavior with regression tests.
This commit is contained in:
Snipzil committed 2026-10-19 10:09:35 -04:00
1 parent 4997315239
commit 7dee29010a
27 files changed
+2303 -346

No files matched your search

+31 -12
View File
@@ -41,6 +41,7 @@ const SCHEMA = `
status INTEGER NOT NULL,
frame INTEGER NOT NULL,
reviewed_at INTEGER,
reviewed_by TEXT,
likes TEXT NOT NULL,
image BLOB NOT NULL
);
@@ -81,11 +82,16 @@ const uploadsPerHour = limits.limiter(30, 3600000);
const now = () => Math.floor(Date.now() / 1000);
const db = () => accounts.database();
const known = new Map(); // id -> {id, creator, createdAt, status, frame, likes: [account ids]}
const known = new Map(); // id -> {id, creator, createdAt, status, frame, reviewedAt, reviewedBy, likes: [account ids]}
const tokens = new Map(); // upload token -> {account id, expires (ms)}
const load = () => {
db().exec(SCHEMA);
// who approved it: a moderator's username, "admin", or null when nobody
// looked (review was off, or it was approved before this was kept).
if (!db().prepare("PRAGMA table_info(masterpieces)").all().some(column => column.name === "reviewed_by")) {
db().exec("ALTER TABLE masterpieces ADD COLUMN reviewed_by TEXT");
}
fs.mkdirSync(folder(), {recursive: true});
// pictures still in the table move out into files, once.
for (const row of db().prepare("SELECT id FROM masterpieces WHERE length(image) > 0").all()) {
@@ -93,8 +99,9 @@ const load = () => {
fs.writeFileSync(fileOf(row.id), Buffer.from(picture));
db().prepare("UPDATE masterpieces SET image = ? WHERE id = ?").run(NO_IMAGE, row.id);
}
for (const row of db().prepare("SELECT id, creator_id, created_at, status, frame, likes FROM masterpieces").all()) {
known.set(row.id, {id: row.id, creator: row.creator_id, createdAt: row.created_at, status: row.status, frame: row.frame, likes: JSON.parse(row.likes)});
for (const row of db().prepare("SELECT id, creator_id, created_at, status, frame, reviewed_at, reviewed_by, likes FROM masterpieces").all()) {
known.set(row.id, {id: row.id, creator: row.creator_id, createdAt: row.created_at, status: row.status, frame: row.frame,
reviewedAt: row.reviewed_at, reviewedBy: row.reviewed_by, likes: JSON.parse(row.likes)});
}
};
@@ -203,7 +210,7 @@ const upload = async (token, image) => {
forget(painting.id);
}
}
const painting = {id: crypto.randomUUID(), creator: entry.account, createdAt: now(), status: UPLOADED, frame: 0, likes: []};
const painting = {id: crypto.randomUUID(), creator: entry.account, createdAt: now(), status: UPLOADED, frame: 0, reviewedAt: null, reviewedBy: null, likes: []};
fs.writeFileSync(fileOf(painting.id), image);
db().prepare("INSERT INTO masterpieces (id, creator_id, created_at, status, frame, likes, image) VALUES (?, ?, ?, ?, ?, '[]', ?)")
.run(painting.id, painting.creator, painting.createdAt, painting.status, painting.frame, NO_IMAGE);
@@ -211,10 +218,13 @@ const upload = async (token, image) => {
return painting.id;
};
const setStatus = (painting, status) => {
// `by`: who approved it, when someone did.
const setStatus = (painting, status, by = null) => {
painting.status = status;
db().prepare("UPDATE masterpieces SET status = ?, frame = ?, reviewed_at = ? WHERE id = ?")
.run(status, painting.frame, status === APPROVED ? now() : null, painting.id);
painting.reviewedAt = status === APPROVED ? now() : null;
painting.reviewedBy = status === APPROVED ? by : null;
db().prepare("UPDATE masterpieces SET status = ?, frame = ?, reviewed_at = ?, reviewed_by = ? WHERE id = ?")
.run(status, painting.frame, painting.reviewedAt, painting.reviewedBy, painting.id);
};
// may this account make an item of that painting, in that frame? (Step 3,
@@ -268,12 +278,13 @@ const mayView = (id, address, addressOf) => {
return painting.status === APPROVED || Boolean(maker && addressOf(maker) && addressOf(maker) === address);
};
const approve = id => {
// `by`: the moderator's username, or "admin".
const approve = (id, by) => {
const painting = get(id);
if (!painting || painting.status !== PENDING) {
return false;
}
setStatus(painting, APPROVED);
setStatus(painting, APPROVED, by);
return true;
};
@@ -318,11 +329,14 @@ const gallery = () => {
return {pool: hung.slice(0, GALLERY_SPOTS), pluspool: hung.slice(GALLERY_SPOTS)};
};
// newest first: the waiting ones by when they were made, the approved ones
// by when they were approved, so that one let in by mistake is near the top.
const list = status => [...known.values()].filter(painting => painting.status === status)
.sort((one, other) => other.createdAt - one.createdAt)
.sort((one, other) => (other.reviewedAt || other.createdAt) - (one.reviewedAt || one.createdAt))
.map(painting => {
const maker = creatorOf(painting.id);
return {id: painting.id, creator: maker ? maker.username : "(deleted account)", createdAt: painting.createdAt, frame: painting.frame, likes: painting.likes.length};
return {id: painting.id, creator: maker ? maker.username : "(deleted account)", createdAt: painting.createdAt, frame: painting.frame, likes: painting.likes.length,
approvedAt: painting.reviewedAt, approvedBy: painting.reviewedBy};
});
// both lists for the panels, narrowed to makers whose names have
@@ -335,6 +349,11 @@ const listsFor = creator => {
return {waiting: narrowed(list(PENDING)), approved: narrowed(list(APPROVED))};
};
// the last `count` approved, the latest first, for the moderator panel to
// take one back from: only the ones `by` approved, when given.
const recentlyApproved = (count, by = "") => list(APPROVED)
.filter(painting => !by || String(painting.approvedBy || "").toLowerCase() === by.toLowerCase()).slice(0, count);
const madeBy = account => [...known.values()].filter(painting => painting.creator === account.id).map(painting => painting.id);
// generic lists: (mediaId, name string id) pairs, or null when `listId` is
@@ -343,7 +362,7 @@ const frameList = listId =>
([LIST_FRAMES_OFFERED, LIST_FRAMES_IN_ORDER].includes(Number(listId)) ? FRAMES.flat() : null);
module.exports = {
load, issueToken, upload, claimable, claim, get, image, mayView, approve, forget, itemApproved, itemFields, creatorOf, like, gallery, list, listsFor, frameList,
load, issueToken, upload, claimable, claim, get, image, mayView, approve, forget, itemApproved, itemFields, creatorOf, like, gallery, list, listsFor, recentlyApproved, frameList,
needsReview, setNeedsReview, madeBy,
PENDING, APPROVED, DEN_ITEM, TOKEN_DEN_ITEM, DIAMOND_DEF, MAX_IMAGE_BYTES,
};