From ec5a6299d68e9bd25b9d9e4eaf00e100fe4971c3 Mon Sep 17 00:00:00 2001 From: Grant Date: Tue, 9 Jul 2024 17:40:39 -0600 Subject: [PATCH 1/3] add CANVAS_SIZE --- packages/server/prisma/schema.prisma | 1 + packages/server/src/api/admin.ts | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/server/prisma/schema.prisma b/packages/server/prisma/schema.prisma index 154ed7d..fecde88 100644 --- a/packages/server/prisma/schema.prisma +++ b/packages/server/prisma/schema.prisma @@ -152,6 +152,7 @@ enum AuditLogAction { BAN_CREATE BAN_UPDATE BAN_DELETE + CANVAS_SIZE } model AuditLog { diff --git a/packages/server/src/api/admin.ts b/packages/server/src/api/admin.ts index 72812a3..151ed44 100644 --- a/packages/server/src/api/admin.ts +++ b/packages/server/src/api/admin.ts @@ -62,6 +62,13 @@ app.get("/canvas/size", async (req, res) => { }); }); +/** + * Update canvas size + * + * @header X-Audit + * @body width number + * @body height number + */ app.post("/canvas/size", async (req, res) => { const width = parseInt(req.body.width || "-1"); const height = parseInt(req.body.height || "-1"); @@ -79,8 +86,14 @@ app.post("/canvas/size", async (req, res) => { } await Canvas.setSize(width, height); + const user = (await User.fromAuthSession(req.session.user!))!; + const auditLog = AuditLog.Factory(user.sub) + .doing("CANVAS_SIZE") + .reason(req.header("X-Audit") || null) + .withComment(`Changed canvas size to ${width}x${height}`) + .create(); - res.send({ success: true }); + res.send({ success: true, auditLog }); }); app.put("/canvas/heatmap", async (req, res) => { -- GitLab From bedbfeb95b552c857a7528054d41521776a275d5 Mon Sep 17 00:00:00 2001 From: Grant Date: Tue, 9 Jul 2024 18:39:51 -0600 Subject: [PATCH 2/3] add CANVAS_FILL --- packages/server/prisma/dbml/schema.dbml | 2 ++ packages/server/prisma/schema.prisma | 1 + packages/server/src/api/admin.ts | 18 +++++++++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/server/prisma/dbml/schema.dbml b/packages/server/prisma/dbml/schema.dbml index 092e054..d9987aa 100644 --- a/packages/server/prisma/dbml/schema.dbml +++ b/packages/server/prisma/dbml/schema.dbml @@ -134,6 +134,8 @@ Enum AuditLogAction { BAN_CREATE BAN_UPDATE BAN_DELETE + CANVAS_SIZE + CANVAS_FILL } Ref: Pixel.userId > User.sub diff --git a/packages/server/prisma/schema.prisma b/packages/server/prisma/schema.prisma index fecde88..308691f 100644 --- a/packages/server/prisma/schema.prisma +++ b/packages/server/prisma/schema.prisma @@ -153,6 +153,7 @@ enum AuditLogAction { BAN_UPDATE BAN_DELETE CANVAS_SIZE + CANVAS_FILL } model AuditLog { diff --git a/packages/server/src/api/admin.ts b/packages/server/src/api/admin.ts index 151ed44..8fde6de 100644 --- a/packages/server/src/api/admin.ts +++ b/packages/server/src/api/admin.ts @@ -151,6 +151,13 @@ app.post("/canvas/stress", async (req, res) => { /** * Fill an area + * + * @header X-Audit + * @body start.x number + * @body start.y number + * @body end.x number + * @body end.y number + * @body color number Palette color index */ app.put("/canvas/fill", async (req, res) => { if ( @@ -217,7 +224,16 @@ app.put("/canvas/fill", async (req, res) => { palette.id ); - res.json({ success: true }); + const user = (await User.fromAuthSession(req.session.user!))!; + const auditLog = await AuditLog.Factory(user.sub) + .doing("CANVAS_FILL") + .reason(req.header("X-Audit") || null) + .withComment( + `Filled (${start_position.join(",")}) -> (${end_position.join(",")}) with ${palette.hex}` + ) + .create(); + + res.json({ success: true, auditLog }); }); /** -- GitLab From a915c3b7f37e87dea2cd113c596e361e59830b81 Mon Sep 17 00:00:00 2001 From: Grant Date: Tue, 9 Jul 2024 18:42:29 -0600 Subject: [PATCH 3/3] consistant naming --- packages/server/src/api/admin.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/server/src/api/admin.ts b/packages/server/src/api/admin.ts index 8fde6de..58503b8 100644 --- a/packages/server/src/api/admin.ts +++ b/packages/server/src/api/admin.ts @@ -337,7 +337,7 @@ app.put("/user/:sub/ban", async (req, res) => { user.updateStanding(); const adminUser = (await User.fromAuthSession(req.session.user!))!; - const audit = await AuditLog.Factory(adminUser.sub) + const auditLog = await AuditLog.Factory(adminUser.sub) .doing(existingBan ? "BAN_UPDATE" : "BAN_CREATE") .reason(req.header("X-Audit") || null) .withComment( @@ -348,7 +348,7 @@ app.put("/user/:sub/ban", async (req, res) => { .withBan(ban) .create(); - res.json({ success: true, audit }); + res.json({ success: true, auditLog }); }); /** @@ -400,13 +400,13 @@ app.delete("/user/:sub/ban", async (req, res) => { user.updateStanding(); const adminUser = (await User.fromAuthSession(req.session.user!))!; - const audit = await AuditLog.Factory(adminUser.sub) + const auditLog = await AuditLog.Factory(adminUser.sub) .doing("BAN_DELETE") .reason(req.header("X-Audit") || null) .withComment(`Deleted ban for ${user.sub}`) .create(); - res.json({ success: true, audit }); + res.json({ success: true, auditLog }); }); app.get("/instance/:domain/ban", async (req, res) => { @@ -520,7 +520,7 @@ app.put("/instance/:domain/ban", async (req, res) => { const user = (await User.fromAuthSession(req.session.user!))!; const ban = await instance.ban(expires, publicNote, privateNote); - const audit = await AuditLog.Factory(user.sub) + const auditLog = await AuditLog.Factory(user.sub) .doing(hasExistingBan ? "BAN_UPDATE" : "BAN_CREATE") .reason(req.header("X-Audit") || null) .withComment( @@ -534,7 +534,7 @@ app.put("/instance/:domain/ban", async (req, res) => { res.json({ success: true, ban, - audit, + auditLog, }); }); @@ -579,13 +579,13 @@ app.delete("/instance/:domain/ban", async (req, res) => { } const user = (await User.fromAuthSession(req.session.user!))!; - const audit = await AuditLog.Factory(user.sub) + const auditLog = await AuditLog.Factory(user.sub) .doing("BAN_DELETE") .reason(req.header("X-Audit") || null) .withComment(`Deleted ban for ${instance.hostname}`) .create(); - res.json({ success: true, audit }); + res.json({ success: true, auditLog }); }); /** -- GitLab