diff --git a/app/main.py b/app/main.py index 68c350d..ba00bbc 100644 --- a/app/main.py +++ b/app/main.py @@ -200,16 +200,13 @@ async def api_set_credits(request: Request): def guest_duplicate_refusal(gq: dict, email: str) -> str | None: """Server-side duplicate-guest guard (pure — testable without FastAPI). - Decided from the portal's guest queues BEFORE any provisioning call, so a - double submit from ANY client (the panel form, a retry, a script) cannot - create a second account for the same recipient. Refuses when: - * an ACTIVE guest account for the email already exists (guests ledger - row with status 'active' — an expired/depleted row is not a live - account, so it falls through to the portal's authoritative - one-guest-per-recipient-ever refusal), or - * a PENDING member request for that email awaits the operator's - decision — the invitation "awaits activation"; approving that request - in the Guest requests tab, not a second send, is the way forward. + Decided from the portal's guests ledger BEFORE any provisioning call, so + a double submit from ANY client (the panel form, a retry, a script) + cannot create a second account for the same recipient. Refuses when an + ACTIVE guest account for the email already exists (guests ledger row with + status 'active' — an expired/depleted row is not a live account, so it + falls through to the portal's authoritative one-guest-per-recipient-ever + refusal). Returns the refusal message, or None when the request may proceed. The portal's own recipient-side guard (one guest per recipient ever, no @@ -223,11 +220,6 @@ def guest_duplicate_refusal(gq: dict, email: str) -> str | None: and (row.get("status") or "").strip().lower() == "active"): return (f"A guest account for {recipient} already exists — " "no second account was created") - for row in (gq.get("pending") or []): - if (row.get("recipient") or "").strip().lower() == recipient: - return (f"A guest invitation for {recipient} already awaits activation — " - "approve or reject it in the Guest requests tab instead of " - "sending a second invite") return None @@ -245,8 +237,8 @@ async def api_provision_guest(request: Request): refusal is surfaced to the operator as-is. A server-side duplicate guard runs HERE, before the portal call: an - active guest or a pending request for the same email is refused with a - specific message instead of a second account being created (the form's + active guest for the same email is refused with a specific message + instead of a second account being created (the form's disable-while-sending only guards this one page; this guard holds for any client). """ @@ -258,9 +250,9 @@ async def api_provision_guest(request: Request): if not email or "@" not in email: return JSONResponse({"error": "A valid recipient email is required"}, status_code=400) try: - gq = await portal_get("/admin/guest-requests") + gq = await portal_get("/admin/guest-ledger") except HTTPException: - gq = {} # queues unreadable — fall through; the portal's own guard still runs + gq = {} # ledger unreadable — fall through; the portal's own guard still runs refusal = guest_duplicate_refusal(gq, email) if refusal: return JSONResponse({"error": refusal}, status_code=409) @@ -270,49 +262,19 @@ async def api_provision_guest(request: Request): return JSONResponse({"error": e.detail}, status_code=e.status_code) -@app.get("/api/guest-requests") -async def api_guest_requests(request: Request): - """The member guest-request queue + the guests ledger (portal /admin/guest-requests). +@app.get("/api/guest-ledger") +async def api_guest_ledger(request: Request): + """The guests ledger (portal /admin/guest-ledger). - The member self-serve path's trial gate: PENDING requests wait here for - the operator's approve/reject; the ledger shows every sent guest and what - became of it — pending vs approved visible in one view. + Every guest access sent and what became of it — the feed behind the + duplicate-send guard. (The member guest-request queue is GONE with the + approval gate, removed 2026-11-08: member invitations provision + immediately, so there is nothing to approve.) """ if not is_admin(request): return JSONResponse({"error": "forbidden"}, status_code=403) try: - return await portal_get("/admin/guest-requests") - except HTTPException as e: - return JSONResponse({"error": e.detail}, status_code=e.status_code) - - -@app.post("/api/guest-requests/{request_id}/approve") -async def api_guest_request_approve(request_id: int, request: Request): - """Approve a pending guest request — fires the full guest provisioning. - - One hop to the portal's /admin/guest-requests/{id}/approve, which runs - the same pipeline as the operator's own guest action and re-checks every - guard (state may have moved since the member made the request). - """ - if not is_admin(request): - return JSONResponse({"error": "forbidden"}, status_code=403) - try: - return await portal_post(f"/admin/guest-requests/{request_id}/approve", {}) - except HTTPException as e: - return JSONResponse({"error": e.detail}, status_code=e.status_code) - - -@app.post("/api/guest-requests/{request_id}/reject") -async def api_guest_request_reject(request_id: int, request: Request): - """Reject a pending guest request. Nothing has gone to the recipient; - the inviting member sees 'not approved' in their own dashboard trail.""" - if not is_admin(request): - return JSONResponse({"error": "forbidden"}, status_code=403) - body = await request.json() if (request.headers.get("content-length") or "0") != "0" else {} - note = (body.get("note") or "").strip() - try: - return await portal_post(f"/admin/guest-requests/{request_id}/reject", - {"note": note} if note else {}) + return await portal_get("/admin/guest-ledger") except HTTPException as e: return JSONResponse({"error": e.detail}, status_code=e.status_code) @@ -508,7 +470,6 @@ PAGE_HTML = """ - @@ -622,56 +583,6 @@ PAGE_HTML = """ - -