2026-06-13 16:32:33 +02:00
|
|
|
# retoor <retoor@molodetz.nl>
|
|
|
|
|
|
|
|
|
|
from datetime import datetime, timezone
|
|
|
|
|
from types import SimpleNamespace
|
|
|
|
|
from tests.conftest import BASE_URL
|
|
|
|
|
from devplacepy.database import get_table, set_setting
|
|
|
|
|
from devplacepy.utils import generate_uid
|
|
|
|
|
from devplacepy.services.devii.config import (
|
|
|
|
|
effective_daily_limit,
|
|
|
|
|
FIELD_USER_DAILY_USD,
|
|
|
|
|
FIELD_GUEST_DAILY_USD,
|
|
|
|
|
FIELD_ADMIN_DAILY_USD,
|
|
|
|
|
)
|
|
|
|
|
from devplacepy.services.devii.store import UsageLedger
|
|
|
|
|
LEDGER = "devii_usage_ledger"
|
|
|
|
|
def _now_iso_devii_quota():
|
|
|
|
|
return datetime.now(timezone.utc).isoformat()
|
|
|
|
|
def _seed_ledger(owner_kind, owner_id, cost, n=1):
|
|
|
|
|
table = get_table(LEDGER)
|
|
|
|
|
for _ in range(n):
|
|
|
|
|
table.insert(
|
|
|
|
|
{
|
|
|
|
|
"owner_kind": owner_kind,
|
|
|
|
|
"owner_id": owner_id,
|
|
|
|
|
"created_at": _now_iso_devii_quota(),
|
|
|
|
|
"cost_usd": cost,
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
def _ensure_devii():
|
|
|
|
|
from devplacepy.services.manager import service_manager
|
|
|
|
|
from devplacepy.services.devii import DeviiService
|
|
|
|
|
|
|
|
|
|
if service_manager.get_service("devii") is None:
|
|
|
|
|
service_manager.register(DeviiService())
|
|
|
|
|
return service_manager.get_service("devii")
|
|
|
|
|
def _make_user_devii_quota(role="Member"):
|
|
|
|
|
uid = generate_uid()
|
|
|
|
|
username = f"quota_{uid[-12:]}"
|
|
|
|
|
get_table("users").insert(
|
|
|
|
|
{
|
|
|
|
|
"uid": uid,
|
|
|
|
|
"username": username,
|
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
|
|
|
"terms_version": "1",
|
2026-06-13 16:32:33 +02:00
|
|
|
"email": f"{username}@t.dev",
|
|
|
|
|
"api_key": generate_uid(),
|
|
|
|
|
"role": role,
|
|
|
|
|
"is_active": True,
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
return uid, username
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_admin_reset_user_quota_endpoint(alice):
|
|
|
|
|
page, _ = alice
|
|
|
|
|
bob = get_table("users").find_one(username="bob_test")
|
|
|
|
|
get_table(LEDGER).insert(
|
|
|
|
|
{
|
|
|
|
|
"owner_kind": "user",
|
|
|
|
|
"owner_id": bob["uid"],
|
|
|
|
|
"created_at": _now_iso_devii_quota(),
|
|
|
|
|
"cost_usd": 0.5,
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
resp = page.request.post(f"{BASE_URL}/admin/users/{bob['uid']}/reset-ai-quota")
|
|
|
|
|
assert resp.ok
|
|
|
|
|
assert get_table(LEDGER).count(owner_kind="user", owner_id=bob["uid"]) == 0
|