A WordPress-inspired CMS whose entire backend is PiCloud Rhai scripts deployed with pic apply, plus a SvelteKit frontend. Built to dogfood the project tool, CLI, and SDK; exercises docs/kv/files/users, docs+queue+cron +pubsub triggers, the transactional-outbox notification chain, a docs before-interceptor, set_if CAS, SSE, per-app CORS, env overlays, and a durable Workflow (validate -> enrich || seo -> publish -> finalize) started with workflow::start and polled with workflow::run_status, visualized live with Svelte Flow. FINDINGS.md / SECURITY.md capture every gap, surprise, and security issue found (each tagged [PiCloud] vs [CMS]); the platform fixes for the actionable ones ship in the preceding commit. Also folds in the read-only `pic` allowlist entries added to .claude/settings.json during the session (fewer-permission-prompts). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
42 lines
1.4 KiB
Plaintext
42 lines
1.4 KiB
Plaintext
// Admin comment moderation, dispatched by method:
|
|
// GET /cms/admin/comments?status=pending -> list (admin)
|
|
// PUT /cms/admin/comments/:id { status } -> approve/spam (admin)
|
|
// DELETE /cms/admin/comments/:id -> delete (admin)
|
|
import "auth" as auth;
|
|
import "util" as util;
|
|
let g = auth::guard(ctx, ["admin"]);
|
|
if !g.ok { return g.response; }
|
|
|
|
let comments = docs::collection("comments");
|
|
let m = ctx.request.method;
|
|
|
|
if m == "GET" {
|
|
let status = ctx.request.query.status;
|
|
let filter = #{ "$sort": #{ created_at: -1 }, "$limit": 200 };
|
|
if status != () { filter.status = status; }
|
|
let rows = comments.find(filter);
|
|
let out = [];
|
|
for r in rows { out.push(util::shape_doc(r)); }
|
|
return #{ statusCode: 200, body: #{ comments: out } };
|
|
}
|
|
|
|
let id = ctx.request.params.id;
|
|
let doc = comments.get(id);
|
|
if doc == () { return #{ statusCode: 404, body: #{ error: "not found" } }; }
|
|
|
|
if m == "DELETE" {
|
|
comments.delete(id);
|
|
return #{ statusCode: 200, body: #{ ok: true } };
|
|
}
|
|
|
|
if m == "PUT" {
|
|
let b = ctx.request.body;
|
|
let cur = doc.data;
|
|
let valid = ["pending", "approved", "spam"];
|
|
if b.status != () && valid.contains(b.status) { cur.status = b.status; }
|
|
comments.update(id, cur); // status->approved fires comment_on_approve (SSE)
|
|
return #{ statusCode: 200, body: #{ id: id, status: cur.status } };
|
|
}
|
|
|
|
#{ statusCode: 405, body: #{ error: "method not allowed" } }
|