Files
PiCloud/examples/cms-poc/scripts/comments/comment_on_approve.rhai
MechaCat02 813bc46640
Some checks failed
CI / Rust — fmt, clippy, test (push) Failing after 39m53s
CI / Dashboard — check (push) Successful in 10m15s
docs(examples): add the CMS proof-of-concept dogfooding artifact
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>
2026-07-19 20:15:29 +02:00

21 lines
861 B
Plaintext

// comment_on_approve — docs TRIGGER on `comments` (update). When a comment
// transitions INTO "approved", publish it to the public `comments-feed` topic
// so post pages can show it live over SSE. (Comments are public once approved.)
let ev = ctx.event.docs;
if ev == () { return; }
let data = ev.data;
if data == () { return; }
let was = if ev.prev_data == () { () } else { ev.prev_data.status };
let became_approved = data.status == "approved" && was != "approved";
if !became_approved { return; }
pubsub::publish_durable("comments-feed", #{
post_id: data.post_id,
post_slug: data.post_slug,
author_name: data.author_name, // already HTML-escaped at write time
body: data.body, // already HTML-escaped at write time
created_at: data.created_at,
});
log::info("published approved comment", #{ post: data.post_id });