Fuehre die Pflicht-Suite gegen eine Wegwerfdatenbank und lege Nutzer als Betreiber an.
Deploy Development / deploy (push) Failing after 40s
Deploy Development / deploy (push) Failing after 40s
Testdaten entstehen nur dort und werden danach entfernt, damit Dev und Produktion sie nicht behalten. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
528fc191e8
commit
4420790707
24 files changed
+1264
-26
No files matched your search
@@ -34,7 +34,9 @@ from app.access.policy import (
|
||||
from app.api.deps import Principal, get_conn, get_principal, get_session
|
||||
from app.api.schemas import (
|
||||
AcceptInviteIn,
|
||||
AccountIn,
|
||||
AnnotationIn,
|
||||
BootstrapIn,
|
||||
AssigneeIn,
|
||||
BindingIn,
|
||||
CaseIn,
|
||||
@@ -72,7 +74,7 @@ from app.auth.security import (
|
||||
verify_password,
|
||||
)
|
||||
from app.core.errors import Problem, forbidden, not_found, too_many, unprocessable
|
||||
from app.core.timeutil import utcnow
|
||||
from app.core.timeutil import dump_dt, utcnow
|
||||
from app.media.storage import content_disposition, read_bytes
|
||||
from app.media.storage import asset_path
|
||||
from app.ops import (
|
||||
@@ -140,7 +142,7 @@ def _ctx_model(value) -> Ctx | None:
|
||||
|
||||
def _session_body(conn, account_id: UUID, scope_kind: str, scope_id: UUID, csrf: str, epoch: int) -> dict:
|
||||
account = conn.execute(
|
||||
"SELECT id, email, display_name FROM auth_accounts WHERE id = %s",
|
||||
"SELECT id, email, display_name, is_superadmin FROM auth_accounts WHERE id = %s",
|
||||
(account_id,),
|
||||
).fetchone()
|
||||
room = conn.execute("SELECT id, kind, name FROM data_rooms WHERE id = %s", (scope_id,)).fetchone()
|
||||
@@ -149,6 +151,7 @@ def _session_body(conn, account_id: UUID, scope_kind: str, scope_id: UUID, csrf:
|
||||
"id": str(account["id"]),
|
||||
"email": account["email"],
|
||||
"display_name": account["display_name"],
|
||||
"is_superadmin": account["is_superadmin"],
|
||||
},
|
||||
"scope": {"kind": scope_kind, "id": str(room["id"]), "name": room["name"]},
|
||||
"rooms": list_rooms(conn, account_id),
|
||||
@@ -232,6 +235,81 @@ def demo(request: Request):
|
||||
return demo_public(request.app.state.settings)
|
||||
|
||||
|
||||
def _superadmin_exists(conn: Connection) -> bool:
|
||||
return conn.execute("SELECT 1 FROM auth_accounts WHERE is_superadmin LIMIT 1").fetchone() is not None
|
||||
|
||||
|
||||
@router.get("/api/v1/auth/bootstrap")
|
||||
def bootstrap_available(conn: Connection = Depends(get_conn)):
|
||||
if _superadmin_exists(conn):
|
||||
raise not_found()
|
||||
return {"available": True}
|
||||
|
||||
|
||||
@router.post("/api/v1/auth/bootstrap")
|
||||
def bootstrap(body: BootstrapIn, request: Request, conn: Connection = Depends(get_conn)):
|
||||
conn.execute("LOCK TABLE auth_accounts IN EXCLUSIVE MODE")
|
||||
if _superadmin_exists(conn):
|
||||
raise not_found()
|
||||
account = create_account(conn, body.email, body.display_name, body.password, is_superadmin=True)
|
||||
settings = request.app.state.settings
|
||||
token, csrf = start_session(conn, settings, account["id"])
|
||||
payload = _session_body(conn, account["id"], "personal", account["id"], csrf, 1)
|
||||
response = JSONResponse(status_code=201, content=payload)
|
||||
set_session_cookie(response, request, settings, token)
|
||||
return response
|
||||
|
||||
|
||||
def _require_superadmin(conn: Connection, principal: Principal) -> None:
|
||||
row = conn.execute(
|
||||
"SELECT is_superadmin FROM auth_accounts WHERE id = %s",
|
||||
(principal.account_id,),
|
||||
).fetchone()
|
||||
if row is None or not row["is_superadmin"]:
|
||||
raise forbidden("Nur der Betreiber kann Nutzer anlegen.")
|
||||
|
||||
|
||||
@router.get("/api/v1/accounts")
|
||||
def accounts(principal: Principal = Depends(get_principal), conn: Connection = Depends(get_conn)):
|
||||
_require_superadmin(conn, principal)
|
||||
rows = conn.execute(
|
||||
"""
|
||||
SELECT id, email, display_name, is_superadmin, created_at
|
||||
FROM auth_accounts
|
||||
WHERE origin = 'operator' AND status = 'active'
|
||||
ORDER BY display_name, email
|
||||
"""
|
||||
).fetchall()
|
||||
return {
|
||||
"items": [
|
||||
{
|
||||
"id": str(row["id"]),
|
||||
"email": row["email"],
|
||||
"display_name": row["display_name"],
|
||||
"is_superadmin": row["is_superadmin"],
|
||||
"created_at": dump_dt(row["created_at"]),
|
||||
}
|
||||
for row in rows
|
||||
],
|
||||
"next_cursor": None,
|
||||
}
|
||||
|
||||
|
||||
@router.post("/api/v1/accounts")
|
||||
def post_account(body: AccountIn, principal: Principal = Depends(get_principal), conn: Connection = Depends(get_conn)):
|
||||
_require_superadmin(conn, principal)
|
||||
account = create_account(conn, body.email, body.display_name, body.password)
|
||||
return _created(
|
||||
f"/api/v1/accounts/{account['id']}",
|
||||
{
|
||||
"id": str(account["id"]),
|
||||
"email": account["email"],
|
||||
"display_name": account["display_name"],
|
||||
"is_superadmin": account["is_superadmin"],
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@router.post("/api/v1/invitations")
|
||||
def invite(
|
||||
body: InvitationIn,
|
||||
|
||||
Reference in new issue
Block a user