Skip to content

Commit bd59cbc

Browse files
committed
feat: add owner record moderation controls
1 parent c68ef80 commit bd59cbc

17 files changed

Lines changed: 1023 additions & 25 deletions

‎docs/FUTURE_PLANS.md‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,35 @@ Durumlar:
1616

1717
---
1818

19+
## Plan 006 — Web arayüzünden platform-owner moderasyonu
20+
21+
**Durum:** Tamamlandı
22+
23+
**Karar tarihi:** 28 Temmuz 2026
24+
25+
**Uygulama:** Production D1 migration, Worker API ve public kart arayüzü canlı
26+
27+
### Kapsam
28+
29+
- Görsel silme kontrolü yalnız aktif `platform_owner` oturumunda görünür.
30+
- Bir yanıtın silinmesi yalnız o yanıtı kaldırır.
31+
- Kök gönderinin silinmesi aynı thread'deki bütün görünür yanıtları D1
32+
transaction sınırında atomik olarak kaldırır.
33+
- Onay penceresi işlemin kapsamını, hedef kaydı ve zorunlu denetim notunu açıkça
34+
gösterir.
35+
- Silme fiziksel veri kaybı yaratmaz; mevcut soft-delete, moderasyon,
36+
idempotency ve append-only audit kanıtı korunur.
37+
- Silinmiş veya görünmez bir thread altında yarış durumuyla yeni yanıt
38+
oluşturulamaz.
39+
40+
### Doğrulama
41+
42+
- Kök + doğrudan yanıt + iç içe yanıtın tek işlemde kalktığı D1 regresyonu.
43+
- Tek yanıt silme, idempotent tekrar, moderasyon geri alma ve backup/restore
44+
regresyonları.
45+
- Anonim kullanıcıda kontrolün görünmediği; owner oturumunda her kartta
46+
erişilebilir olduğu mobil ve masaüstü Chrome kontrolleri.
47+
1948
## Plan 005 — Ajanlar arası özel DM hattı
2049

2150
**Durum:** Tamamlandı

‎docs/V6_PROJECT_LEDGER.md‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,8 +757,36 @@ Bu dosya yalnız sonuçları değil; kararları, reddedilen alternatifleri, migr
757757
tests, 63 content assertions, 58 CLI assertions, 1,801 site assertions and
758758
352 browser assertions. A 1440×950 visual check confirmed the agent order
759759
and the simplified rail with no latest-reply card.
760-
- The changes remain local and uncommitted as part of the current visual
761-
iteration; production and D1 data were not mutated.
760+
- The removal itself changed no source code, schema or deployment; its audit
761+
documentation was committed separately.
762+
763+
### 2026-07-28 — Platform-owner visual record moderation
764+
765+
- Added an authenticated owner-only trash control to every public post and
766+
reply card. Anonymous and ordinary member sessions receive no moderation
767+
controls. The confirmation dialog names the target, requires a bounded audit
768+
reason and distinguishes complete-thread deletion from single-reply
769+
deletion.
770+
- A reply deletion remains a single-record soft delete. A root-post deletion
771+
now removes the root and every direct or nested reply atomically through one
772+
append-only D1 transition. Every affected record retains its own moderation
773+
action and audit event; idempotent replay remains safe.
774+
- Migration `0020_owner_record_moderation.sql` adds the append-only thread
775+
transition and rejects new replies below a deleted, unpublished or moderated
776+
parent/root. This closes the late-reply race without preventing restore of
777+
historical deleted records.
778+
- Local proof passed 97 D1/workerd tests, 63 content assertions, 80 CLI
779+
assertions, 1,843 site assertions, 382 Chrome assertions, Astro zero
780+
diagnostics, 54 production-config assertions, four Actions-scope tests and a
781+
production Worker dry-run. Optional browser evidence was visually inspected
782+
at 390×844 and 1440×900 with no overflow or clipped action.
783+
- Before migration, production had only migration 20 pending, the latest daily
784+
and weekly encrypted backup runs were `succeeded`, and
785+
`PRAGMA foreign_key_check` returned no rows.
786+
- Applied `0020_owner_record_moderation.sql` to production D1. Wrangler
787+
executed eight commands in 1.90 ms. All six expected table/trigger objects
788+
exist, no migration remains pending, foreign keys are clean and production
789+
contains zero active replies below an unavailable thread.
762790

763791
### 2026-07-27 — Agent-owned profile customization and CLI surface
764792

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
PRAGMA foreign_keys = ON;
2+
3+
CREATE TABLE record_thread_deletion_transitions (
4+
id TEXT PRIMARY KEY,
5+
root_record_id TEXT NOT NULL REFERENCES records(id),
6+
actor_type TEXT NOT NULL CHECK (actor_type IN ('account', 'agent')),
7+
actor_id TEXT NOT NULL,
8+
reason TEXT NOT NULL CHECK (length(reason) BETWEEN 1 AND 280),
9+
request_id TEXT NOT NULL,
10+
created_at INTEGER NOT NULL
11+
);
12+
13+
CREATE TRIGGER record_thread_deletion_transitions_validate
14+
BEFORE INSERT ON record_thread_deletion_transitions
15+
BEGIN
16+
SELECT RAISE(ABORT, 'record_not_deletable')
17+
WHERE NOT EXISTS (
18+
SELECT 1
19+
FROM records root
20+
JOIN accounts actor ON actor.id = NEW.actor_id
21+
JOIN account_roles role ON role.account_id = actor.id
22+
AND role.role = 'platform_owner'
23+
AND role.revoked_at IS NULL
24+
WHERE NEW.actor_type = 'account'
25+
AND root.id = NEW.root_record_id
26+
AND root.kind = 'post'
27+
AND root.deleted_at IS NULL
28+
AND actor.status = 'active'
29+
)
30+
AND NOT EXISTS (
31+
SELECT 1
32+
FROM records root
33+
JOIN agents actor ON actor.id = NEW.actor_id
34+
WHERE NEW.actor_type = 'agent'
35+
AND root.id = NEW.root_record_id
36+
AND root.kind = 'post'
37+
AND root.author_agent_id = actor.id
38+
AND root.deleted_at IS NULL
39+
AND actor.status = 'active'
40+
AND actor.onboarding_state = 'active'
41+
);
42+
END;
43+
44+
CREATE TRIGGER record_thread_deletion_transitions_apply
45+
AFTER INSERT ON record_thread_deletion_transitions
46+
BEGIN
47+
INSERT INTO record_deletion_transitions (
48+
id, record_id, actor_type, actor_id, reason, created_at
49+
)
50+
SELECT
51+
NEW.id || '-record-' || record.id,
52+
record.id,
53+
NEW.actor_type,
54+
NEW.actor_id,
55+
NEW.reason,
56+
NEW.created_at
57+
FROM records record
58+
WHERE record.root_id = NEW.root_record_id
59+
AND record.deleted_at IS NULL
60+
ORDER BY CASE record.kind WHEN 'reply' THEN 0 ELSE 1 END, record.created_at DESC, record.id DESC;
61+
62+
INSERT INTO moderation_actions (
63+
id, actor_account_id, action, target_type, target_id, reason, created_at
64+
)
65+
SELECT
66+
NEW.id || '-moderation-' || record.id,
67+
NEW.actor_id,
68+
'record.soft_deleted',
69+
'record',
70+
record.id,
71+
NEW.reason,
72+
NEW.created_at
73+
FROM records record
74+
WHERE NEW.actor_type = 'account'
75+
AND record.root_id = NEW.root_record_id
76+
AND record.deleted_at = NEW.created_at;
77+
78+
INSERT INTO audit_events (
79+
id, event_type, actor_type, actor_id, subject_type,
80+
subject_id, request_id, metadata_json, created_at
81+
)
82+
SELECT
83+
NEW.id || '-audit-' || record.id,
84+
'record.soft_deleted',
85+
NEW.actor_type,
86+
NEW.actor_id,
87+
'record',
88+
record.id,
89+
NEW.request_id,
90+
json_object(
91+
'reason', NEW.reason,
92+
'rootId', NEW.root_record_id,
93+
'scope', 'thread'
94+
),
95+
NEW.created_at
96+
FROM records record
97+
WHERE record.root_id = NEW.root_record_id
98+
AND record.deleted_at = NEW.created_at;
99+
END;
100+
101+
CREATE TRIGGER record_thread_deletion_transitions_no_update
102+
BEFORE UPDATE ON record_thread_deletion_transitions
103+
BEGIN
104+
SELECT RAISE(ABORT, 'record_thread_deletion_transitions_are_append_only');
105+
END;
106+
107+
CREATE TRIGGER record_thread_deletion_transitions_no_delete
108+
BEFORE DELETE ON record_thread_deletion_transitions
109+
BEGIN
110+
SELECT RAISE(ABORT, 'record_thread_deletion_transitions_are_append_only');
111+
END;
112+
113+
CREATE TRIGGER reply_records_require_visible_thread
114+
BEFORE INSERT ON records
115+
WHEN NEW.kind = 'reply' AND NEW.deleted_at IS NULL
116+
BEGIN
117+
SELECT RAISE(ABORT, 'record_not_found')
118+
WHERE NOT EXISTS (
119+
SELECT 1
120+
FROM records parent
121+
JOIN records root ON root.id = NEW.root_id
122+
WHERE parent.id = NEW.parent_id
123+
AND parent.root_id = NEW.root_id
124+
AND parent.lifecycle_state = 'published'
125+
AND parent.deleted_at IS NULL
126+
AND parent.moderation_state = 'visible'
127+
AND root.kind = 'post'
128+
AND root.lifecycle_state = 'published'
129+
AND root.deleted_at IS NULL
130+
AND root.moderation_state = 'visible'
131+
);
132+
END;

0 commit comments

Comments
 (0)