forked from retoor/devplacepy
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.
This commit is contained in:
+111
-3
@@ -50,10 +50,20 @@ DOCS_SLUGS = [
|
||||
"components",
|
||||
"dashboard",
|
||||
"claude",
|
||||
"terms",
|
||||
"community-guidelines",
|
||||
"privacy",
|
||||
"content-moderation",
|
||||
"intellectual-property",
|
||||
"contact",
|
||||
]
|
||||
ADMIN_DOCS_SLUGS = ["moderation-operations"]
|
||||
UPLOAD_FILE = ("load_test.txt", b"locust upload payload", "text/plain")
|
||||
UUID_RE = r"[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}"
|
||||
PASSWORD = "testpass123"
|
||||
BIRTH_DATE = "01/01/1990"
|
||||
ACCEPT_TERMS = "on"
|
||||
REPORT_STATUSES = ["open", "acknowledged", "actioned", "dismissed"]
|
||||
|
||||
# ── Deliberately NOT load tested (kept out by design) ───────────────
|
||||
# /openai/v1/*, /devii/clippy/ai/chat - real upstream AI spend / billing.
|
||||
@@ -76,6 +86,19 @@ PASSWORD = "testpass123"
|
||||
# /admin/trash/.../purge, /admin/media/{uid}/purge of seeded content
|
||||
# - hard GC of real content (only the
|
||||
# dedicated disposable media is purged).
|
||||
# POST /reports/{target_type}/{target_uid}
|
||||
# - floods the real moderation queue
|
||||
# with junk reports. Exactly one
|
||||
# disposable report is seeded below so
|
||||
# the queue read tasks have a live uid.
|
||||
# /admin/moderation/{uid}/decide|status, /admin/users/{uid}/suspend|lift|ban
|
||||
# - real enforcement against real
|
||||
# accounts. The read surface (queue +
|
||||
# report detail) IS covered below.
|
||||
# /profile/{username}/delete - destroys accounts (GET and POST).
|
||||
# /profile/{username}/consent, /mature-content
|
||||
# - flips real consent state.
|
||||
# /auth/accept-terms - mutates real acceptance records.
|
||||
# WebSockets (/devii/ws, exec ws) - HttpUser cannot drive them.
|
||||
|
||||
|
||||
@@ -103,6 +126,8 @@ def do_signup(client, username, email):
|
||||
"email": email,
|
||||
"password": PASSWORD,
|
||||
"confirm_password": PASSWORD,
|
||||
"birth_date": BIRTH_DATE,
|
||||
"accept_terms": ACCEPT_TERMS,
|
||||
},
|
||||
catch_response=True,
|
||||
name="signup",
|
||||
@@ -153,6 +178,8 @@ def seed_data(environment, **kwargs):
|
||||
"email": email,
|
||||
"password": PASSWORD,
|
||||
"confirm_password": PASSWORD,
|
||||
"birth_date": BIRTH_DATE,
|
||||
"accept_terms": ACCEPT_TERMS,
|
||||
}
|
||||
).encode()
|
||||
req = urllib.request.Request(
|
||||
@@ -354,12 +381,18 @@ def seed_data(environment, **kwargs):
|
||||
logger.warning(f"Harvest SEO job uids failed: {e}")
|
||||
|
||||
# ── Seed an admin user (direct DB insert) ───────────────────
|
||||
# terms_version/terms_accepted_at are mandatory: the terms-acceptance
|
||||
# middleware redirects every mutating request of a user whose version
|
||||
# is stale to /auth/accept-terms, which would silently gut every
|
||||
# admin write task. age_band keeps the maturity gates open.
|
||||
try:
|
||||
from datetime import datetime, timezone
|
||||
from devplacepy.database import get_table, init_db
|
||||
from devplacepy.database import get_setting, get_table, init_db
|
||||
from devplacepy.utils import hash_password, generate_uid
|
||||
|
||||
init_db()
|
||||
now = datetime.now(timezone.utc).isoformat()
|
||||
terms_version = get_setting("terms_version", "1") or "1"
|
||||
username = f"lu_admin_{uuid.uuid4().hex[:6]}"
|
||||
email = f"{username}@locust.devplace"
|
||||
get_table("users").insert(
|
||||
@@ -377,7 +410,11 @@ def seed_data(environment, **kwargs):
|
||||
"level": 1,
|
||||
"xp": 0,
|
||||
"stars": 0,
|
||||
"created_at": datetime.now(timezone.utc).isoformat(),
|
||||
"terms_version": terms_version,
|
||||
"terms_accepted_at": now,
|
||||
"age_band": "adult",
|
||||
"suspended_until": "",
|
||||
"created_at": now,
|
||||
}
|
||||
)
|
||||
ADMIN_USER["username"] = username
|
||||
@@ -401,7 +438,11 @@ def seed_data(environment, **kwargs):
|
||||
"level": 1,
|
||||
"xp": 0,
|
||||
"stars": 0,
|
||||
"created_at": datetime.now(timezone.utc).isoformat(),
|
||||
"terms_version": terms_version,
|
||||
"terms_accepted_at": now,
|
||||
"age_band": "adult",
|
||||
"suspended_until": "",
|
||||
"created_at": now,
|
||||
}
|
||||
)
|
||||
ADMIN_TARGETS["disposable_uid"] = disposable_uid
|
||||
@@ -409,6 +450,29 @@ def seed_data(environment, **kwargs):
|
||||
except Exception as e:
|
||||
logger.warning(f"Seed admin user failed: {e}")
|
||||
|
||||
# ── Seed one disposable moderation report ───────────────────
|
||||
# Filing reports under load is excluded (it would flood the real
|
||||
# queue), so exactly one row is raised here, by the disposable user
|
||||
# against a seed post, to keep the admin queue/detail read tasks on
|
||||
# a live uid instead of an empty pool.
|
||||
try:
|
||||
from devplacepy.services.moderation import queue as report_queue
|
||||
|
||||
reporter_uid = ADMIN_TARGETS.get("disposable_uid")
|
||||
if reporter_uid and POST_UIDS:
|
||||
report = report_queue.raise_report(
|
||||
target_type="post",
|
||||
target_uid=POST_UIDS[0],
|
||||
reporter_uid=reporter_uid,
|
||||
reason="spam",
|
||||
detail="Disposable report for the moderation queue read tasks.",
|
||||
)
|
||||
if report:
|
||||
ADMIN_TARGETS["report_uid"] = report["uid"]
|
||||
logger.info(f"Seeded moderation report {report['uid']}")
|
||||
except Exception as e:
|
||||
logger.warning(f"Seed moderation report failed: {e}")
|
||||
|
||||
# ── Harvest UIDs from HTML responses ──────────────────────
|
||||
# projects sidebar: /projects?user_uid={uuid}
|
||||
# project cards: /votes/project/{uuid}
|
||||
@@ -676,6 +740,21 @@ class DevPlaceUser(HttpUser):
|
||||
def view_saved(self):
|
||||
self.client.get("/bookmarks/saved", name="bookmarks/saved")
|
||||
|
||||
@task(1)
|
||||
def view_report_reasons(self):
|
||||
self.client.get("/reports/reasons", name="reports/reasons")
|
||||
|
||||
@task(1)
|
||||
def view_my_reports(self):
|
||||
params = {}
|
||||
if random.random() < 0.5:
|
||||
params["status"] = random.choice(REPORT_STATUSES)
|
||||
self.client.get("/reports/mine", params=params, name="reports/mine")
|
||||
|
||||
@task(2)
|
||||
def view_workspace_index(self):
|
||||
self.client.get("/workspaces/index", name="workspaces/index")
|
||||
|
||||
# ── auth flows ──────────────────────────────────────────────
|
||||
|
||||
@task(1)
|
||||
@@ -1568,6 +1647,33 @@ class AdminUser(HttpUser):
|
||||
f"/admin/audit-log/{m.group(1)}", name="admin/audit-log/[uid]"
|
||||
)
|
||||
|
||||
@task(3)
|
||||
def view_moderation_queue(self):
|
||||
resp = self.client.get(
|
||||
"/admin/moderation",
|
||||
params={"status": random.choice(REPORT_STATUSES)},
|
||||
name="admin/moderation",
|
||||
)
|
||||
m = re.search(rf"/admin/moderation/({UUID_RE})", resp.text)
|
||||
uid = m.group(1) if m else ADMIN_TARGETS.get("report_uid")
|
||||
if not uid:
|
||||
return
|
||||
with self.client.get(
|
||||
f"/admin/moderation/{uid}",
|
||||
catch_response=True,
|
||||
name="admin/moderation/[uid]",
|
||||
) as report:
|
||||
if report.status_code == 200:
|
||||
report.success()
|
||||
else:
|
||||
report.failure(f"report detail: status={report.status_code}")
|
||||
|
||||
@task(1)
|
||||
def view_admin_docs(self):
|
||||
self.client.get(
|
||||
f"/docs/{random.choice(ADMIN_DOCS_SLUGS)}.html", name="docs/[slug]"
|
||||
)
|
||||
|
||||
@task(1)
|
||||
def view_admin_media(self):
|
||||
self.client.get("/admin/media", name="admin/media")
|
||||
@@ -1711,6 +1817,8 @@ class AnonymousUser(HttpUser):
|
||||
"/gists",
|
||||
"/projects",
|
||||
"/leaderboard",
|
||||
"/reports/reasons",
|
||||
"/workspaces/index",
|
||||
]
|
||||
)
|
||||
self.client.get(path, name="public/[page]")
|
||||
|
||||
Reference in New Issue
Block a user