feat(relay): add reopen/cancel admin endpoints and activeAction report DTO

The moderation console needs to reopen a terminally-resolved report, cancel a
failed enforcement action, and read the enforcement that ran against a target.
The prior surface exposed none of these: resolve returned an ad-hoc
`{status, actionId}`, report detail carried no action provenance, and feedback
from purged communities was silently dropped by an inner join.

- POST /reports/{id}/reopen returns a terminal report to `open` and records a
  durable `reopen` audit row; idempotent on request_id, 409 if not terminal.
- POST /reports/{id}/cancel cancels a pre-mutation `failed` action (the only
  recovery path — no composed client-side retry) and embeds the cancelled
  action DTO as the last look at a record a later detail read serves as null.
- GET /reports/{id} and /resolve now carry `activeAction`, derived via a LEFT
  JOIN LATERAL matching the report's active action or its succeeded enforcement
  (`ORDER BY created_at DESC, id DESC`), so a dismissed-after-reopen report
  still surfaces the enforcement that actually executed. reopen audit rows are
  excluded (`action IN ('delete','kick','ban','timeout')`).
- Feedback list/detail switch to LEFT JOIN communities with nullable
  communityId/communityHost so rows survive a tenant purge that severs
  provenance (product_feedback.community_id SET NULL); the attachment path
  fails closed to 404 on a severed row.

No migration added — activeAction is derived from existing indexes.

Co-authored-by: Will Pfleger <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
This commit is contained in:
Duncan
2026-08-13 02:43:28 -04:00
parent f865efb337
commit 3339cf9e24
5 changed files with 1318 additions and 20 deletions

View File

@@ -326,6 +326,24 @@ Feedback search and filters run over the bounded browser result set; the
Body: `{"action": "delete|kick|ban|timeout|dismiss|escalate", "expirationSecs": <number>, "reason": "<string>", "requestId": "<uuid>"}`
`expirationSecs` required for `timeout`, rejected for all others.
Target/channel are always derived from server-owned report provenance.
Response: `{"status": "<terminal>", "activeAction": <action | null>}`. Enforcement
actions return the governing action record; `dismiss`/`escalate` return `null`.
- `POST /api/admin/v1/reports/:id/reopen`
Body: `{"requestId": "<uuid>", "reason": "<string>"}`
Returns a terminal report (`resolved`, `dismissed`, or `escalated`) to `open` and
records a durable `reopen` audit row. Idempotent on `requestId`: a retry after the
report has been reopened (and possibly re-resolved) returns the same `200` without
re-reopening. Returns `{"status": "open"}` on success, `409` if the report is not
in a terminal state, `404` if it does not exist.
- `POST /api/admin/v1/reports/:id/cancel`
Body: `{"actionId": "<uuid>"}`
Cancels a pre-mutation `failed` enforcement action, returning the report to `open`.
Cancel is the only recovery path for a failed action. `actionId` fences the cancel
to exactly the action the client observed. Returns `{"status": "open", "activeAction":
<cancelled action>}` — the embedded record is the last look at that action, since a
subsequent detail read (report back to `open`) serves `activeAction: null`. Returns
`409` if the action is not cancellable (already cancelled, superseded, or past the
mutation point) — treat as "refresh detail".
- `PATCH /api/admin/v1/feedback/:id`
Body: `{"status": "new|reviewed|archived"}`
@@ -358,6 +376,13 @@ sidecar before accessing the shared content-addressed blob. Unknown feedback,
unreferenced hashes, malformed paths, and cross-community substitutions all
collapse to `404`.
Product feedback is deployment-global operator evidence: when its source community
is purged, the row's `community_id` is severed to `NULL` (the row survives, its
provenance does not). List and detail reads still return such rows with
`communityId` and `communityHost` as `null`. Their attachments, however, were
purged with the tenant, so the attachment route fails closed to `404` for any
severed feedback — there is no tenant to bind and no tenant-scoped media to serve.
Only `GET` and `HEAD` are routed. Community `/media/*` reads always require
Blossom authorization and relay membership; the browser receives no reusable
signed URL. Responses are uncached, `nosniff`,