forked from retoor/devplacepy
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.
150 lines
5.4 KiB
Python
150 lines
5.4 KiB
Python
# retoor <retoor@molodetz.nl>
|
|
|
|
import time
|
|
import requests
|
|
from playwright.sync_api import expect
|
|
from tests.conftest import BASE_URL
|
|
from devplacepy.database import get_table
|
|
_counter_project_files = [0]
|
|
def _signup_project_files():
|
|
_counter_project_files[0] += 1
|
|
name = f"pf{int(time.time() * 1000)}{_counter_project_files[0]}"
|
|
session = requests.Session()
|
|
session.post(
|
|
f"{BASE_URL}/auth/signup",
|
|
data={
|
|
"username": name,
|
|
"email": f"{name}@t.dev",
|
|
"password": "secret123",
|
|
"confirm_password": "secret123",
|
|
"birth_date": "1990-01-01",
|
|
"accept_terms": "1",
|
|
},
|
|
allow_redirects=True,
|
|
)
|
|
key = get_table("users").find_one(username=name)["api_key"]
|
|
return name, key
|
|
def _h_project_files(key):
|
|
return {"X-API-KEY": key, "Accept": "application/json"}
|
|
def _create_project_project_files(key, title):
|
|
r = requests.post(
|
|
f"{BASE_URL}/projects/create",
|
|
headers=_h_project_files(key),
|
|
data={
|
|
"title": title,
|
|
"description": "filesystem test",
|
|
"project_type": "software",
|
|
"status": "In Development",
|
|
},
|
|
)
|
|
assert r.status_code == 200, r.text
|
|
return r.json()["data"]
|
|
def _write_project_files(key, slug, path, content):
|
|
return requests.post(
|
|
f"{BASE_URL}/projects/{slug}/files/write",
|
|
headers=_h_project_files(key),
|
|
data={"path": path, "content": content},
|
|
allow_redirects=False,
|
|
)
|
|
def _mkdir(key, slug, path):
|
|
return requests.post(
|
|
f"{BASE_URL}/projects/{slug}/files/mkdir",
|
|
headers=_h_project_files(key),
|
|
data={"path": path},
|
|
allow_redirects=False,
|
|
)
|
|
def _move(key, slug, from_path, to_path):
|
|
return requests.post(
|
|
f"{BASE_URL}/projects/{slug}/files/move",
|
|
headers=_h_project_files(key),
|
|
data={"from_path": from_path, "to_path": to_path},
|
|
allow_redirects=False,
|
|
)
|
|
def _delete(key, slug, path):
|
|
return requests.post(
|
|
f"{BASE_URL}/projects/{slug}/files/delete",
|
|
headers=_h_project_files(key),
|
|
data={"path": path},
|
|
allow_redirects=False,
|
|
)
|
|
def _list(slug, key=None):
|
|
return requests.get(
|
|
f"{BASE_URL}/projects/{slug}/files",
|
|
headers=_h_project_files(key) if key else {"Accept": "application/json"},
|
|
)
|
|
def _raw_project_files(slug, path, key=None):
|
|
return requests.get(
|
|
f"{BASE_URL}/projects/{slug}/files/raw",
|
|
params={"path": path},
|
|
headers=_h_project_files(key) if key else {"Accept": "application/json"},
|
|
)
|
|
def _paths(slug, key=None):
|
|
return sorted(f["path"] for f in _list(slug, key).json()["files"])
|
|
def _make_project_ui(page, title):
|
|
page.goto(f"{BASE_URL}/projects", wait_until="domcontentloaded")
|
|
page.locator("#create-project-btn").click()
|
|
page.fill("#title", title)
|
|
page.fill("#description", "Project for filesystem UI test")
|
|
page.click("button:has-text('Create Project')")
|
|
page.wait_for_url(f"{BASE_URL}/projects/*", wait_until="domcontentloaded")
|
|
return page.url
|
|
def _open_files(page, title):
|
|
proj_url = _make_project_ui(page, title)
|
|
slug = proj_url.rstrip("/").split("/")[-1]
|
|
page.goto(proj_url + "/files", wait_until="domcontentloaded")
|
|
return slug
|
|
def _dialog_fill(page, value):
|
|
page.locator(".dialog-overlay.visible .dialog-input").wait_for(state="visible")
|
|
page.fill(".dialog-overlay.visible .dialog-input", value)
|
|
page.click(".dialog-overlay.visible .dialog-confirm")
|
|
def _dialog_confirm(page):
|
|
page.locator(".dialog-overlay.visible .dialog-confirm").wait_for(state="visible")
|
|
page.click(".dialog-overlay.visible .dialog-confirm")
|
|
def _dialog_cancel(page):
|
|
page.locator(".dialog-overlay.visible .dialog-cancel").wait_for(state="visible")
|
|
page.click(".dialog-overlay.visible .dialog-cancel")
|
|
def _new_folder(page, name):
|
|
page.click("#pf-new-folder")
|
|
_dialog_fill(page, name)
|
|
page.wait_for_selector(f".pf-node-row:has-text('{name.split('/')[-1]}')")
|
|
def _new_file(page, name):
|
|
page.click("#pf-new-file")
|
|
_dialog_fill(page, name)
|
|
def _row(page, name):
|
|
return page.locator(f".pf-node-row:has-text('{name}')").first
|
|
def _alice_key():
|
|
return get_table("users").find_one(username="alice_test")["api_key"]
|
|
|
|
|
|
def test_upload_text_is_editable(app_server):
|
|
_, key = _signup_project_files()
|
|
slug = _create_project_project_files(key, "FS UploadText")["slug"]
|
|
r = requests.post(
|
|
f"{BASE_URL}/projects/{slug}/files/upload",
|
|
headers=_h_project_files(key),
|
|
files={"file": ("util.py", b"x = 1\n")},
|
|
data={"path": "src"},
|
|
)
|
|
assert r.status_code == 200
|
|
node = _raw_project_files(slug, "src/util.py", key).json()
|
|
assert node["is_binary"] is False and node["content"] == "x = 1\n"
|
|
|
|
|
|
def test_upload_binary_is_served(app_server):
|
|
_, key = _signup_project_files()
|
|
slug = _create_project_project_files(key, "FS UploadBinary")["slug"]
|
|
blob = bytes(range(256))
|
|
r = requests.post(
|
|
f"{BASE_URL}/projects/{slug}/files/upload",
|
|
headers=_h_project_files(key),
|
|
files={"file": ("logo.bin", blob)},
|
|
data={"path": "assets"},
|
|
)
|
|
assert r.status_code == 200
|
|
node = _raw_project_files(slug, "assets/logo.bin", key).json()
|
|
assert node["is_binary"] is True and node["url"].startswith(
|
|
"/static/uploads/project_files/"
|
|
)
|
|
served = requests.get(BASE_URL + node["url"])
|
|
assert served.status_code == 200 and served.content == blob
|