2026-06-16 07:08:58 +02:00
|
|
|
# retoor <retoor@molodetz.nl>
|
|
|
|
|
|
|
|
|
|
import time
|
|
|
|
|
import requests
|
|
|
|
|
from tests.conftest import BASE_URL
|
|
|
|
|
|
|
|
|
|
JSON_trash = {"Accept": "application/json"}
|
|
|
|
|
_counter_trash = [0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _unique_trash(prefix="tr"):
|
|
|
|
|
_counter_trash[0] += 1
|
|
|
|
|
return f"{prefix}{int(time.time() * 1000)}{_counter_trash[0]}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _member_trash():
|
|
|
|
|
name = _unique_trash("trmem")
|
|
|
|
|
s = requests.Session()
|
|
|
|
|
s.post(
|
|
|
|
|
f"{BASE_URL}/auth/signup",
|
|
|
|
|
data={
|
|
|
|
|
"username": name,
|
|
|
|
|
"email": f"{name}@t.dev",
|
|
|
|
|
"password": "secret123",
|
|
|
|
|
"confirm_password": "secret123",
|
Add the trust and safety subsystem and the App Store compliance work
Implements the moderation and consent obligations a social platform carries,
so the web version and any client that speaks to it enforce the same rules.
Moderation core (services/moderation/, database/moderation.py): a reportable
target registry, the content filter and its choke points, the report queue with
atomic resolution, enforcement actions, consent tracking, maturity gating, and
account deletion with a grace window.
Surfaces: POST /reports plus the member report list, /admin/moderation and the
per-report admin view, /workspaces, terms acceptance at /auth/terms, consent and
account deletion under /profile, the report button and dialog partials, the
maturity gate, and the moderation stylesheet and ReportDialog client.
Every user-generated surface stays reportable by construction: new content tables
are registered in REPORTABLE_TARGETS or listed in UNREPORTABLE_TABLES with a
reason, and the registry test fails the suite on anything left unclassified.
Docs: community guidelines, content moderation, intellectual property, privacy,
terms, contact, and the admin-only moderation operations page, plus the
moderation API group and the Devii moderation actions.
Compliance record: applecomp.md is the requirement register, applechanges.md the
gap analysis against this codebase, and appleimpl.md the implementation design
they resolve to.
Tests cover the report flow, admin moderation, consent, account deletion, terms
acceptance, workspaces, and the registry invariant across the unit, api, and e2e
tiers.
2026-08-09 00:18:20 +02:00
|
|
|
"birth_date": "1990-01-01",
|
|
|
|
|
"accept_terms": "1",
|
2026-06-16 07:08:58 +02:00
|
|
|
},
|
|
|
|
|
allow_redirects=True,
|
|
|
|
|
)
|
|
|
|
|
return s, name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _admin_trash(seeded_db):
|
|
|
|
|
s = requests.Session()
|
|
|
|
|
creds = seeded_db["alice"]
|
|
|
|
|
s.post(
|
|
|
|
|
f"{BASE_URL}/auth/login",
|
|
|
|
|
data={"email": creds["email"], "password": creds["password"]},
|
|
|
|
|
allow_redirects=True,
|
|
|
|
|
)
|
|
|
|
|
return s
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _create_post_trash(session):
|
|
|
|
|
return session.post(
|
|
|
|
|
f"{BASE_URL}/posts/create",
|
|
|
|
|
headers=JSON_trash,
|
|
|
|
|
data={"title": _unique_trash("trp"), "content": "trash post body text", "topic": "devlog"},
|
|
|
|
|
).json()["data"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _soft_delete_post_trash(session, slug):
|
|
|
|
|
return session.post(
|
|
|
|
|
f"{BASE_URL}/posts/delete/{slug}", headers=JSON_trash, allow_redirects=False
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_trash_requires_admin(seeded_db):
|
|
|
|
|
member, _ = _member_trash()
|
|
|
|
|
r = member.get(f"{BASE_URL}/admin/trash", allow_redirects=False)
|
|
|
|
|
assert r.status_code in (302, 303)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_trash_lists_soft_deleted_post(seeded_db):
|
|
|
|
|
member, _ = _member_trash()
|
|
|
|
|
post = _create_post_trash(member)
|
|
|
|
|
_soft_delete_post_trash(member, post["slug"])
|
|
|
|
|
admin = _admin_trash(seeded_db)
|
|
|
|
|
body = admin.get(
|
|
|
|
|
f"{BASE_URL}/admin/trash", headers=JSON_trash, params={"table": "posts"}
|
|
|
|
|
).json()
|
|
|
|
|
assert body["table"] == "posts"
|
|
|
|
|
assert body["admin_section"] == "trash"
|
|
|
|
|
assert any(item["uid"] == post["uid"] for item in body["items"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_trash_unknown_table_falls_back_to_posts(seeded_db):
|
|
|
|
|
admin = _admin_trash(seeded_db)
|
|
|
|
|
body = admin.get(
|
|
|
|
|
f"{BASE_URL}/admin/trash", headers=JSON_trash, params={"table": "bogus"}
|
|
|
|
|
).json()
|
|
|
|
|
assert body["table"] == "posts"
|