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:
@@ -277,7 +277,7 @@ def init_db():
|
||||
defaults = {
|
||||
"site_name": "DevPlace",
|
||||
"site_description": "The Developer Social Network",
|
||||
"site_tagline": "Track industry shifts. Discover bold releases. Share what you are building in an open, uncensored environment.",
|
||||
"site_tagline": "Track industry shifts. Discover bold releases. Share what you are building in an open environment built by developers, for developers.",
|
||||
}
|
||||
for key, value in defaults.items():
|
||||
existing = db["site_settings"].find_one(key=key)
|
||||
@@ -558,6 +558,9 @@ def init_db():
|
||||
("slug", ""),
|
||||
("name", ""),
|
||||
("status", ""),
|
||||
("created_at", ""),
|
||||
("owner_uid", ""),
|
||||
("created_by", ""),
|
||||
("desired_state", ""),
|
||||
("container_id", ""),
|
||||
("ingress_slug", ""),
|
||||
@@ -1550,6 +1553,8 @@ def init_db():
|
||||
["user_uid", "created_at"],
|
||||
)
|
||||
|
||||
_ensure_moderation_tables()
|
||||
|
||||
for table in db.tables:
|
||||
_uid_index(db, table)
|
||||
|
||||
@@ -1688,6 +1693,19 @@ def init_db():
|
||||
"outbound_proxy_url": "",
|
||||
"devii_lessons_max_per_owner": "500",
|
||||
"devii_lessons_max_age_days": "90",
|
||||
"moderation_sla_hours": "24",
|
||||
"moderation_filter_mode": "review",
|
||||
"moderation_filter_review_score": "2",
|
||||
"moderation_minimum_age": "16",
|
||||
"moderation_mature_default_hidden": "1",
|
||||
"contact_email": "",
|
||||
"contact_phone": "",
|
||||
"contact_address": "",
|
||||
"terms_version": "1",
|
||||
"privacy_version": "1",
|
||||
"guidelines_version": "1",
|
||||
"ai_third_party_provider": "",
|
||||
"account_deletion_grace_hours": "24",
|
||||
}
|
||||
for key, value in operational_defaults.items():
|
||||
existing = db["site_settings"].find_one(key=key)
|
||||
@@ -1768,6 +1786,83 @@ def init_db():
|
||||
_refresh_query_planner_stats()
|
||||
|
||||
|
||||
MODERATION_COLUMNS: dict[str, tuple[tuple[str, object], ...]] = {
|
||||
"content_reports": (
|
||||
("uid", ""),
|
||||
("reporter_uid", ""),
|
||||
("target_type", ""),
|
||||
("target_uid", ""),
|
||||
("owner_uid", ""),
|
||||
("reason", ""),
|
||||
("detail", ""),
|
||||
("severity", "warn"),
|
||||
("status", "open"),
|
||||
("origin", "member"),
|
||||
("categories", ""),
|
||||
("resolved_by", ""),
|
||||
("resolved_at", ""),
|
||||
("created_at", ""),
|
||||
("updated_at", ""),
|
||||
),
|
||||
"moderation_actions": (
|
||||
("uid", ""),
|
||||
("report_uid", ""),
|
||||
("actor_uid", ""),
|
||||
("action", ""),
|
||||
("target_type", ""),
|
||||
("target_uid", ""),
|
||||
("subject_uid", ""),
|
||||
("reason", ""),
|
||||
("notes", ""),
|
||||
("expires_at", ""),
|
||||
("created_at", ""),
|
||||
),
|
||||
"content_maturity": (
|
||||
("uid", ""),
|
||||
("target_type", ""),
|
||||
("target_uid", ""),
|
||||
("level", "general"),
|
||||
("source", ""),
|
||||
("set_by", ""),
|
||||
("created_at", ""),
|
||||
("updated_at", ""),
|
||||
),
|
||||
"user_consents": (
|
||||
("uid", ""),
|
||||
("owner_kind", ""),
|
||||
("owner_id", ""),
|
||||
("kind", ""),
|
||||
("version", "1"),
|
||||
("state", ""),
|
||||
("granted_at", ""),
|
||||
("withdrawn_at", ""),
|
||||
("created_at", ""),
|
||||
),
|
||||
}
|
||||
|
||||
MODERATION_INDEXES: tuple[tuple[str, str, list[str]], ...] = (
|
||||
("content_reports", "idx_content_reports_queue", ["status", "created_at"]),
|
||||
("content_reports", "idx_content_reports_target", ["target_type", "target_uid"]),
|
||||
("content_reports", "idx_content_reports_reporter", ["reporter_uid"]),
|
||||
("content_reports", "idx_content_reports_owner", ["owner_uid"]),
|
||||
("moderation_actions", "idx_moderation_actions_report", ["report_uid"]),
|
||||
("moderation_actions", "idx_moderation_actions_subject", ["subject_uid"]),
|
||||
("moderation_actions", "idx_moderation_actions_created", ["created_at"]),
|
||||
("content_maturity", "idx_content_maturity_target", ["target_type", "target_uid"]),
|
||||
("user_consents", "idx_user_consents_owner", ["owner_kind", "owner_id", "kind"]),
|
||||
)
|
||||
|
||||
|
||||
def _ensure_moderation_tables() -> None:
|
||||
for table_name, columns in MODERATION_COLUMNS.items():
|
||||
table = get_table(table_name)
|
||||
for column, example in columns:
|
||||
if not table.has_column(column):
|
||||
table.create_column_by_example(column, example)
|
||||
for table_name, index_name, columns in MODERATION_INDEXES:
|
||||
_index(db, table_name, index_name, columns)
|
||||
|
||||
|
||||
def _refresh_query_planner_stats() -> None:
|
||||
try:
|
||||
has_stats = bool(
|
||||
@@ -1857,6 +1952,22 @@ def backfill_api_keys() -> int:
|
||||
users.create_column_by_example("last_award_slug", "")
|
||||
if not users.has_column("last_award_uid"):
|
||||
users.create_column_by_example("last_award_uid", "")
|
||||
if not users.has_column("terms_version"):
|
||||
users.create_column_by_example("terms_version", "")
|
||||
if not users.has_column("terms_accepted_at"):
|
||||
users.create_column_by_example("terms_accepted_at", "")
|
||||
if not users.has_column("age_band"):
|
||||
users.create_column_by_example("age_band", "")
|
||||
if not users.has_column("age_declared_at"):
|
||||
users.create_column_by_example("age_declared_at", "")
|
||||
if not users.has_column("mature_opt_in"):
|
||||
users.create_column_by_example("mature_opt_in", 0)
|
||||
if not users.has_column("suspended_until"):
|
||||
users.create_column_by_example("suspended_until", "")
|
||||
if not users.has_column("suspension_reason"):
|
||||
users.create_column_by_example("suspension_reason", "")
|
||||
if not users.has_column("deletion_requested_at"):
|
||||
users.create_column_by_example("deletion_requested_at", "")
|
||||
with db:
|
||||
db.query(
|
||||
"UPDATE users SET ai_modifier_enabled = 1 WHERE ai_modifier_enabled IS NULL"
|
||||
@@ -1871,6 +1982,7 @@ def backfill_api_keys() -> int:
|
||||
"UPDATE users SET interactions_enabled = -1 "
|
||||
"WHERE interactions_enabled IS NULL"
|
||||
)
|
||||
db.query("UPDATE users SET mature_opt_in = 0 WHERE mature_opt_in IS NULL")
|
||||
import uuid_utils
|
||||
|
||||
updated = 0
|
||||
|
||||
Reference in New Issue
Block a user