From 8e9d3fad98e6deff36e44cab8c9569ee48d60b8a Mon Sep 17 00:00:00 2001 From: retoor Date: Sun, 9 Aug 2026 00:18:20 +0200 Subject: [PATCH] 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. --- CLAUDE.md | 19 +- README.md | 19 +- applechanges.md | 230 +++++++ applecomp.md | 435 +++++++++++++ appleimpl.md | 583 ++++++++++++++++++ devplacepy/cli/__init__.py | 3 + devplacepy/cli/accounts.py | 46 ++ devplacepy/cli/main.py | 2 + devplacepy/content.py | 74 +++ devplacepy/database/CLAUDE.md | 26 + devplacepy/database/__init__.py | 71 +++ devplacepy/database/content.py | 38 ++ devplacepy/database/moderation.py | 328 ++++++++++ devplacepy/database/notifications.py | 1 + devplacepy/database/schema.py | 114 +++- devplacepy/database/soft_delete.py | 4 + devplacepy/docs_api/groups/__init__.py | 2 + devplacepy/docs_api/groups/auth.py | 7 + devplacepy/docs_api/groups/moderation.py | 489 +++++++++++++++ devplacepy/main.py | 70 ++- devplacepy/models.py | 155 +++++ devplacepy/routers/CLAUDE.md | 12 +- devplacepy/routers/admin/__init__.py | 2 + devplacepy/routers/admin/_shared.py | 39 ++ devplacepy/routers/admin/moderation.py | 323 ++++++++++ devplacepy/routers/admin/users.py | 152 ++++- devplacepy/routers/auth/__init__.py | 2 + devplacepy/routers/auth/signup.py | 4 +- devplacepy/routers/auth/terms.py | 82 +++ devplacepy/routers/devrant/CLAUDE.md | 2 +- devplacepy/routers/devrant/_shared.py | 11 +- devplacepy/routers/devrant/auth.py | 31 +- devplacepy/routers/devrant/comments.py | 11 +- devplacepy/routers/devrant/notifs.py | 7 +- devplacepy/routers/devrant/rants.py | 21 +- devplacepy/routers/docs/CLAUDE.md | 2 + devplacepy/routers/docs/pages.py | 47 +- devplacepy/routers/docs/views.py | 1 + devplacepy/routers/messages.py | 10 + devplacepy/routers/news.py | 2 + devplacepy/routers/profile/__init__.py | 4 + devplacepy/routers/profile/consent.py | 127 ++++ devplacepy/routers/profile/delete.py | 150 +++++ devplacepy/routers/profile/index.py | 47 ++ devplacepy/routers/reports.py | 143 +++++ devplacepy/routers/seo.py | 2 + devplacepy/routers/workspaces.py | 116 ++++ devplacepy/schemas/__init__.py | 17 + devplacepy/schemas/listings.py | 6 + devplacepy/schemas/moderation.py | 136 ++++ devplacepy/schemas/profile.py | 9 + devplacepy/schemas/quiz.py | 1 + devplacepy/seo.py | 25 + devplacepy/services/CLAUDE.md | 6 + devplacepy/services/audit/categories.py | 6 + devplacepy/services/bot/auth.py | 6 + devplacepy/services/containers/CLAUDE.md | 2 + devplacepy/services/containers/api.py | 17 +- .../devii/actions/catalog/__init__.py | 2 + .../services/devii/actions/catalog/_shared.py | 12 +- .../devii/actions/catalog/moderation.py | 242 ++++++++ .../services/devii/actions/dispatcher.py | 30 + devplacepy/services/messaging/persist.py | 15 + devplacepy/services/moderation/CLAUDE.md | 126 ++++ devplacepy/services/moderation/__init__.py | 21 + devplacepy/services/moderation/deletion.py | 211 +++++++ devplacepy/services/moderation/enforcement.py | 139 +++++ devplacepy/services/moderation/filter.py | 127 ++++ devplacepy/services/moderation/queue.py | 358 +++++++++++ devplacepy/services/moderation/rules.py | 178 ++++++ devplacepy/services/moderation/screening.py | 142 +++++ devplacepy/services/moderation/service.py | 78 +++ devplacepy/services/moderation/sla.py | 80 +++ devplacepy/services/openai_gateway/CLAUDE.md | 11 + devplacepy/services/openai_gateway/service.py | 51 ++ devplacepy/services/presence.py | 8 + devplacepy/static/css/auth.css | 30 + devplacepy/static/css/awards.css | 34 +- devplacepy/static/css/base.css | 48 ++ devplacepy/static/css/chat.css | 29 + devplacepy/static/css/landing.css | 11 + devplacepy/static/css/media.css | 10 +- devplacepy/static/css/moderation.css | 179 ++++++ devplacepy/static/css/profile.css | 26 + devplacepy/static/css/workspace.css | 4 +- devplacepy/static/js/Application.js | 2 + devplacepy/static/js/CLAUDE.md | 4 + devplacepy/static/js/ReportDialog.js | 74 +++ devplacepy/static/js/WorkspaceManager.js | 8 +- devplacepy/templates/CLAUDE.md | 3 + devplacepy/templates/_awards_gallery.html | 1 + devplacepy/templates/_comment.html | 1 + devplacepy/templates/_footer_links.html | 5 + devplacepy/templates/_maturity_gate.html | 13 + devplacepy/templates/_media_gallery.html | 1 + devplacepy/templates/_post_card.html | 5 + devplacepy/templates/_report_button.html | 11 + devplacepy/templates/_report_dialog.html | 22 + devplacepy/templates/accept_terms.html | 26 + devplacepy/templates/account_delete.html | 48 ++ devplacepy/templates/admin_base.html | 3 + devplacepy/templates/admin_moderation.html | 61 ++ devplacepy/templates/admin_report.html | 101 +++ devplacepy/templates/admin_settings.html | 85 ++- devplacepy/templates/base.html | 10 +- devplacepy/templates/containers_instance.html | 1 + .../templates/docs/community-guidelines.html | 105 ++++ devplacepy/templates/docs/contact.html | 35 ++ .../templates/docs/content-moderation.html | 104 ++++ devplacepy/templates/docs/devii-tools.html | 6 +- devplacepy/templates/docs/index.html | 6 + .../templates/docs/intellectual-property.html | 59 ++ .../templates/docs/moderation-operations.html | 103 ++++ devplacepy/templates/docs/privacy.html | 103 ++++ .../templates/docs/production-nginx.html | 18 + devplacepy/templates/docs/terms.html | 115 ++++ devplacepy/templates/gist_detail.html | 5 + devplacepy/templates/issue_detail.html | 4 + devplacepy/templates/landing.html | 5 +- devplacepy/templates/messages.html | 1 + devplacepy/templates/news_detail.html | 5 + devplacepy/templates/post.html | 5 + devplacepy/templates/profile.html | 66 ++ devplacepy/templates/project_detail.html | 5 + devplacepy/templates/project_files.html | 1 + devplacepy/templates/quiz.html | 5 + devplacepy/templates/report_reasons.html | 18 + devplacepy/templates/reports_mine.html | 39 ++ devplacepy/templates/signup.html | 13 + devplacepy/templates/workspace.html | 6 +- devplacepy/templates/workspace_index.html | 44 ++ devplacepy/templating.py | 45 ++ devplacepy/utils/CLAUDE.md | 2 + devplacepy/utils/accounts.py | 61 +- devplacepy/utils/guards.py | 40 ++ events.md | 43 +- locustfile.py | 114 +++- nginx/nginx.conf.template | 1 + tests/CLAUDE.md | 4 + tests/api/admin/aiquota/resetguests.py | 2 + tests/api/admin/analytics.py | 2 + tests/api/admin/auditlog.py | 2 + tests/api/admin/backups/download.py | 2 + tests/api/admin/backups/schedules.py | 2 + tests/api/admin/containers/manage.py | 2 + tests/api/admin/containers/projects/search.py | 2 + tests/api/admin/deviitasks.py | 2 + tests/api/admin/gateway/index.py | 2 + tests/api/admin/media/index.py | 2 + tests/api/admin/media/purge.py | 2 + tests/api/admin/moderation.py | 241 ++++++++ tests/api/admin/news/publish.py | 2 + tests/api/admin/services/config.py | 2 + tests/api/admin/services/start.py | 2 + tests/api/admin/settings.py | 2 + tests/api/admin/trash/index.py | 2 + tests/api/admin/trash/purge.py | 2 + tests/api/admin/trash/restore.py | 2 + tests/api/admin/users/index.py | 2 + tests/api/admin/users/password.py | 2 + tests/api/admin/users/role.py | 2 + tests/api/admin/users/seniority.py | 2 + tests/api/admin/users/toggle.py | 2 + tests/api/api/auth.py | 2 + tests/api/api/users/me/notiffeed.py | 2 + tests/api/audit/log.py | 2 + tests/api/auth/login.py | 2 + tests/api/auth/logout.py | 4 + tests/api/auth/matrix.py | 2 + tests/api/auth/signup.py | 4 + tests/api/auth/terms.py | 154 +++++ tests/api/auth/token.py | 2 + tests/api/awards/index.py | 1 + tests/api/block/index.py | 2 + tests/api/block/unblock.py | 2 + tests/api/block/visibility.py | 2 + tests/api/bookmarks/index.py | 4 + tests/api/bookmarks/saved.py | 2 + tests/api/comments/create.py | 6 + tests/api/comments/edit.py | 2 + tests/api/components/title.py | 1 + tests/api/content/negotiation.py | 2 + tests/api/content/permissions.py | 2 + tests/api/dbapi/conftest.py | 2 + tests/api/devrant/auth.py | 12 +- tests/api/docs/index.py | 4 + tests/api/feed.py | 9 + tests/api/follow/index.py | 6 + tests/api/follow/unfollow.py | 2 + tests/api/game/index.py | 2 + tests/api/game/mutations.py | 2 + tests/api/gists/create.py | 8 + tests/api/gists/index.py | 1 + tests/api/issues/attachments.py | 1 + tests/api/issues/create.py | 3 + tests/api/issues/giteaflow.py | 2 + tests/api/issues/status.py | 2 + tests/api/manifestjson.py | 2 + tests/api/media/delete.py | 2 + tests/api/media/index.py | 2 + tests/api/media/restore.py | 2 + tests/api/messages/conversations.py | 2 + tests/api/messages/index.py | 6 + tests/api/messages/search.py | 2 + tests/api/messages/send.py | 2 + tests/api/messages/ws.py | 2 + tests/api/messages/wsticket.py | 2 + tests/api/mute/index.py | 2 + tests/api/mute/unmute.py | 2 + tests/api/news/index.py | 1 + tests/api/notifications.py | 2 + tests/api/polls.py | 2 + tests/api/posts/create.py | 13 + tests/api/posts/delete.py | 2 + tests/api/posts/edit.py | 4 + tests/api/posts/index.py | 2 + tests/api/profile/aicorrection.py | 2 + tests/api/profile/aimodifier.py | 2 + tests/api/profile/award.py | 2 + tests/api/profile/consent.py | 210 +++++++ tests/api/profile/delete.py | 162 +++++ tests/api/profile/index.py | 123 ++++ tests/api/profile/interactions.py | 2 + tests/api/profile/regenerateapikey.py | 2 + tests/api/profile/regenerateavatar.py | 2 + tests/api/profile/search.py | 9 + tests/api/profile/telegram.py | 2 + tests/api/profile/update.py | 4 + tests/api/project/files.py | 2 + tests/api/project/visibility.py | 2 + tests/api/projects/containers/data.py | 2 + tests/api/projects/containers/manage.py | 2 + tests/api/projects/create.py | 2 + tests/api/projects/delete.py | 4 + tests/api/projects/devlog.py | 2 + tests/api/projects/edit.py | 2 + tests/api/projects/files/lineops.py | 2 + tests/api/projects/files/lines.py | 2 + tests/api/projects/files/raw.py | 2 + tests/api/projects/files/replacelines.py | 4 + tests/api/projects/files/upload.py | 2 + tests/api/projects/files/write.py | 2 + tests/api/projects/files/zip.py | 2 + tests/api/projects/index.py | 5 + tests/api/projects/workspace.py | 2 + tests/api/projects/zip.py | 2 + tests/api/pushjson.py | 2 + tests/api/quizzes/_helpers.py | 2 + tests/api/reactions.py | 4 + tests/api/reports/__init__.py | 0 tests/api/reports/index.py | 227 +++++++ tests/api/robotstxt.py | 13 + tests/api/serviceworkerjs.py | 2 + tests/api/sitemapxml.py | 29 + tests/api/streaks.py | 1 + tests/api/tools/deepsearch/control.py | 2 + tests/api/tools/isslop.py | 2 + tests/api/tools/seometa.py | 2 + tests/api/uploads/manage.py | 2 + tests/api/uploads/upload.py | 4 + tests/api/uploads/uploadurl.py | 2 + tests/api/votes.py | 4 + tests/api/workspaces/__init__.py | 1 + tests/api/workspaces/index.py | 152 +++++ tests/api/xmlrpc/index.py | 2 + tests/api/zips/download.py | 2 + tests/api/zips/index.py | 2 + tests/conftest.py | 4 + tests/e2e/admin/aiquota/resetall.py | 1 + tests/e2e/admin/aiusage/data.py | 2 + tests/e2e/admin/aiusage/index.py | 2 + tests/e2e/admin/analytics.py | 2 + tests/e2e/admin/auditlog.py | 4 + tests/e2e/admin/backups/index.py | 2 + tests/e2e/admin/containers/manage.py | 2 + tests/e2e/admin/index.py | 2 + tests/e2e/admin/media.py | 2 + tests/e2e/admin/news.py | 2 + tests/e2e/admin/settings.py | 2 + tests/e2e/admin/users/aiusage.py | 1 + tests/e2e/admin/users/index.py | 8 + tests/e2e/ai/usage/profile.py | 1 + tests/e2e/auth/login.py | 1 + tests/e2e/auth/logout.py | 8 + tests/e2e/auth/resetpassword.py | 1 + tests/e2e/auth/signup.py | 31 + tests/e2e/bookmarks/saved.py | 2 + tests/e2e/devii/quota.py | 1 + tests/e2e/docs.py | 2 + tests/e2e/feed.py | 6 + tests/e2e/gists.py | 5 + tests/e2e/media/delete.py | 2 + tests/e2e/messages.py | 1 + tests/e2e/news.py | 2 + tests/e2e/notifications/index.py | 5 +- tests/e2e/openai/v1/chat/completions.py | 18 + tests/e2e/openai/v1/embeddings.py | 8 + tests/e2e/posts/create.py | 3 + tests/e2e/posts/index.py | 6 + tests/e2e/profile/block.py | 1 + tests/e2e/profile/index.py | 151 ++--- tests/e2e/profile/search.py | 9 + tests/e2e/project/files.py | 2 + tests/e2e/projects/devlog.py | 1 + tests/e2e/projects/files.py | 4 + tests/e2e/projects/index.py | 11 + tests/e2e/quizzes/index.py | 2 + tests/e2e/quizzes/play.py | 2 + tests/e2e/reports/__init__.py | 0 tests/e2e/reports/ui.py | 170 +++++ tests/e2e/root.py | 3 +- tests/unit/cli.py | 2 + tests/unit/content.py | 5 + tests/unit/database.py | 4 + tests/unit/database/awards.py | 1 + tests/unit/database/moderation.py | 131 ++++ tests/unit/database/users.py | 4 + tests/unit/project_files.py | 4 + tests/unit/push.py | 2 + tests/unit/routers/admin/users.py | 26 +- tests/unit/routers/workspaces.py | 108 ++++ tests/unit/schemas.py | 43 ++ tests/unit/services/audit.py | 1 + tests/unit/services/containers.py | 69 +++ tests/unit/services/dbapi/conftest.py | 1 + tests/unit/services/devii/config.py | 1 + .../services/devii/container/controller.py | 1 + tests/unit/services/devii/session.py | 2 + tests/unit/services/devii/tasks/context.py | 1 + tests/unit/services/devii/tasks/guards.py | 1 + tests/unit/services/devii/tasks/limits.py | 1 + tests/unit/services/devii/tasks/scheduler.py | 1 + tests/unit/services/devii/tasks/store.py | 1 + tests/unit/services/game/store.py | 1 + tests/unit/services/gitea.py | 1 + tests/unit/services/jobs/award_service.py | 1 + tests/unit/services/messaging/tickets.py | 1 + tests/unit/services/moderation/__init__.py | 0 tests/unit/services/moderation/filter.py | 131 ++++ .../unit/services/openai_gateway/analytics.py | 1 + tests/unit/services/openai_gateway/gateway.py | 1 + tests/unit/services/presence.py | 33 +- tests/unit/services/quiz/documents.py | 1 + tests/unit/services/quiz/scoreboard.py | 1 + tests/unit/services/quiz/store.py | 1 + tests/unit/test_access_tokens.py | 1 + tests/unit/test_devrant_token_auth.py | 1 + tests/unit/utils.py | 2 + 348 files changed, 10633 insertions(+), 238 deletions(-) create mode 100644 applechanges.md create mode 100644 applecomp.md create mode 100644 appleimpl.md create mode 100644 devplacepy/cli/accounts.py create mode 100644 devplacepy/database/moderation.py create mode 100644 devplacepy/docs_api/groups/moderation.py create mode 100644 devplacepy/routers/admin/moderation.py create mode 100644 devplacepy/routers/auth/terms.py create mode 100644 devplacepy/routers/profile/consent.py create mode 100644 devplacepy/routers/profile/delete.py create mode 100644 devplacepy/routers/reports.py create mode 100644 devplacepy/routers/workspaces.py create mode 100644 devplacepy/schemas/moderation.py create mode 100644 devplacepy/services/devii/actions/catalog/moderation.py create mode 100644 devplacepy/services/moderation/CLAUDE.md create mode 100644 devplacepy/services/moderation/__init__.py create mode 100644 devplacepy/services/moderation/deletion.py create mode 100644 devplacepy/services/moderation/enforcement.py create mode 100644 devplacepy/services/moderation/filter.py create mode 100644 devplacepy/services/moderation/queue.py create mode 100644 devplacepy/services/moderation/rules.py create mode 100644 devplacepy/services/moderation/screening.py create mode 100644 devplacepy/services/moderation/service.py create mode 100644 devplacepy/services/moderation/sla.py create mode 100644 devplacepy/static/css/moderation.css create mode 100644 devplacepy/static/js/ReportDialog.js create mode 100644 devplacepy/templates/_maturity_gate.html create mode 100644 devplacepy/templates/_report_button.html create mode 100644 devplacepy/templates/_report_dialog.html create mode 100644 devplacepy/templates/accept_terms.html create mode 100644 devplacepy/templates/account_delete.html create mode 100644 devplacepy/templates/admin_moderation.html create mode 100644 devplacepy/templates/admin_report.html create mode 100644 devplacepy/templates/docs/community-guidelines.html create mode 100644 devplacepy/templates/docs/contact.html create mode 100644 devplacepy/templates/docs/content-moderation.html create mode 100644 devplacepy/templates/docs/intellectual-property.html create mode 100644 devplacepy/templates/docs/moderation-operations.html create mode 100644 devplacepy/templates/docs/privacy.html create mode 100644 devplacepy/templates/docs/terms.html create mode 100644 devplacepy/templates/report_reasons.html create mode 100644 devplacepy/templates/reports_mine.html create mode 100644 devplacepy/templates/workspace_index.html create mode 100644 tests/api/admin/moderation.py create mode 100644 tests/api/auth/terms.py create mode 100644 tests/api/profile/consent.py create mode 100644 tests/api/profile/delete.py create mode 100644 tests/api/reports/__init__.py create mode 100644 tests/api/reports/index.py create mode 100644 tests/api/workspaces/__init__.py create mode 100644 tests/api/workspaces/index.py create mode 100644 tests/e2e/reports/__init__.py create mode 100644 tests/e2e/reports/ui.py create mode 100644 tests/unit/database/moderation.py create mode 100644 tests/unit/routers/workspaces.py create mode 100644 tests/unit/services/moderation/__init__.py create mode 100644 tests/unit/services/moderation/filter.py diff --git a/CLAUDE.md b/CLAUDE.md index 51d53e08..869093d5 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -86,6 +86,8 @@ devplace game steals prune # delete Code Farm raid records older than the raid- devplace game era status # show the current Code Farm Era devplace game era start [--days N] # start a Code Farm Era (default 28 days) devplace game era end # end the running Code Farm Era (ranks, awards Stars, records results) +devplace accounts pending # list deleted accounts awaiting their purge +devplace accounts prune # permanently purge accounts past the deletion grace window (--dry-run to preview) devplace backups list # list recorded backups devplace backups run # enqueue a backup (processed by the running server) devplace backups prune # remove backup records whose archive file is missing @@ -138,6 +140,7 @@ Nested `CLAUDE.md` files (loaded automatically by Claude Code only when a file i | `devplacepy/services/devii/CLAUDE.md` | Devii assistant: sessions/channels, scheduler, virtual tools, self-configured behavior, client browser tools | | `devplacepy/services/openai_gateway/CLAUDE.md` | AI gateway: `/openai/v1/*`, usage ledger, provider/model routing | | `devplacepy/services/jobs/CLAUDE.md` | Async job services: zip, fork, SEO diagnostics, SEO metadata, DeepSearch, AI Usage Analyzer | +| `devplacepy/services/moderation/CLAUDE.md` | Trust and safety: the reportable-target registry, the content filter and its five choke points, the report queue and its atomic resolution, enforcement, consent, maturity, account deletion | | `devplacepy/services/audit/CLAUDE.md` | Audit log: recorders, categories, retention | | `devplacepy/services/backup/CLAUDE.md` | Backup service: targets, worker, schedules, primary-admin-only download | | `devplacepy/services/telegram/CLAUDE.md` | Telegram bot bridge | @@ -195,6 +198,7 @@ Routers in `devplacepy/routers/` are organised as a **directory tree that mirror | `/api` | devrant/ package - see `routers/devrant/CLAUDE.md` | | `/dbapi` | dbapi/ package, **primary-administrator-only, strictly READ-ONLY** - see `services/dbapi/CLAUDE.md` | | `/game` | game/ package - see `services/game/CLAUDE.md` | +| `/reports`, `/admin/moderation`, `/workspaces` | reports.py, admin/moderation.py, workspaces.py - see `services/moderation/CLAUDE.md` | | `/quizzes` | quizzes/ package - see `services/quiz/CLAUDE.md` | | (none) | push.py (web push/PWA), docs.py (see `routers/docs/CLAUDE.md`) | | `/pubsub` | pubsub.py - see `services/pubsub/CLAUDE.md` | @@ -272,11 +276,17 @@ Devii is also reachable over **Telegram** (one supervised long-poller subprocess - **All dates shown to users are DD/MM/YYYY** (European), rendered in the viewer's own timezone client-side. Timestamps are stored/emitted as UTC ISO. Use the `local_dt(iso, mode)`/`dt_ago(iso)` Jinja globals for any user-facing instant - they emit `