diff --git a/app/main.py b/app/main.py
index 0e8699a..10b6daa 100644
--- a/app/main.py
+++ b/app/main.py
@@ -222,6 +222,53 @@ 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).
+
+ 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.
+ """
+ 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 {})
+ except HTTPException as e:
+ return JSONResponse({"error": e.detail}, status_code=e.status_code)
+
+
# ---------------------------------------------------------------------------
# OIDC routes — authorization-code flow against Cloudron's OIDC provider.
# Active only when the `oidc` addon is configured (CLOUDRON_OIDC_* present).
@@ -396,6 +443,7 @@ PAGE_HTML = """
+
@@ -502,6 +550,56 @@ PAGE_HTML = """
+
+
Pending guest requests
+
Member-initiated guest invitations waiting for a decision. Approve runs the full guest pipeline ($5 credit, 60-day box, invitation email naming the inviting member); nothing has gone to the recipient before approval. Reject tells the inviting member 'not approved' in their own dashboard trail.
+
+
+
+
+
Requested
+
Inviting member
+
Recipient
+
Name
+
Decision
+
+
+
Loading…
+
+
+
Recent decisions
+
+
+
+
+
Requested
+
Inviting member
+
Recipient
+
Decided
+
Status
+
Note
+
+
+
+
+
+
Guests ledger
+
Every guest access sent, and what became of it. Members' requests appear above before they enter this ledger — pending vs approved in one view.
+
+
+
+
+
Sent
+
Inviting member
+
Recipient
+
Status
+
+
+
+
+
+
+
Agents
Bot and sandbox accounts. Not members — excluded from member counts; their usage is a collective expense.
@@ -1104,11 +1202,13 @@ function switchView(view) {
$('agents-section').style.display = view === 'members' ? '' : 'none';
$('trends-section').style.display = view === 'trends' ? '' : 'none';
$('money-section').style.display = view === 'money' ? '' : 'none';
+ $('guestrequests-section').style.display = view === 'guestrequests' ? '' : 'none';
$('tab-members').className = 'tab-btn' + (view === 'members' ? ' active' : '');
$('tab-models').className = 'tab-btn' + (view === 'models' ? ' active' : '');
$('tab-trends').className = 'tab-btn' + (view === 'trends' ? ' active' : '');
$('tab-money').className = 'tab-btn' + (view === 'money' ? ' active' : '');
- $('view-title').textContent = view === 'members' ? 'Members' : (view === 'models' ? 'Model usage' : (view === 'trends' ? 'Trends' : 'Money'));
+ $('tab-guestrequests').className = 'tab-btn' + (view === 'guestrequests' ? ' active' : '');
+ $('view-title').textContent = view === 'members' ? 'Members' : (view === 'models' ? 'Model usage' : (view === 'trends' ? 'Trends' : (view === 'money' ? 'Money' : 'Guest requests')));
// Mode groups: Balance/All-time for members; Period for models; the guest
// action belongs to the members view too.
$('range-group').style.display = view === 'models' ? '' : 'none';
@@ -1119,6 +1219,9 @@ function switchView(view) {
// Money renders on first visit only, same rule: one fetch, then the
// period/spend toggles re-render client-side.
if (view === 'money') loadMoney();
+ // The guest-request queue refetches on EVERY visit and after every
+ // decision — a queue the operator acts on must never show stale rows.
+ if (view === 'guestrequests') loadGuestRequests();
render();
}
@@ -1388,8 +1491,114 @@ async function sendGuestAccess() {
finally { btn.disabled = false; btn.textContent = 'Send guest access'; }
}
+// ---- Guest requests: the member self-serve trial gate ----------------------
+// The queue refetches on every tab visit and after every decision, so a row
+// the operator is about to act on is never stale. The ledger surfaces every
+// sent guest — pending vs approved (and every later state) in one view.
+
+function grDay(s) {
+ if (!s) return '—';
+ const d = new Date(String(s).replace(' ', 'T') + (String(s).includes('Z') ? '' : 'Z'));
+ return isNaN(d) ? String(s).slice(0, 10) : d.toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' });
+}
+
+function grPill(status) {
+ const map = {
+ pending: ['pending', 'grace', 'Waiting for the operator'],
+ approved: ['approved', 'active', 'Provisioned — the guest pipeline ran'],
+ rejected: ['rejected', 'inactive', 'Declined — the inviting member sees this in their trail'],
+ active: ['active', 'guest', 'Guest account live'],
+ converted:['converted', 'manual', 'The guest became a member'],
+ expired: ['expired', 'inactive', 'Time box ran out'],
+ depleted: ['depleted', 'inactive', 'The $5 credit was spent'],
+ 'cancelled by recipient': ['cancelled', 'inactive', 'Ended at the recipient\u2019s own request'],
+ };
+ const [label, cls, title] = map[status] || [status || '—', 'grace', ''];
+ return '' + esc(label) + '';
+}
+
+function setGuestReqBadge(n) {
+ const b = $('guestreq-badge');
+ if (!b) return;
+ b.style.display = n > 0 ? '' : 'none';
+ b.textContent = n > 0 ? ' (' + n + ')' : '';
+}
+
+async function loadGuestRequests() {
+ try {
+ const r = await fetch('/api/guest-requests');
+ const d = await r.json().catch(() => ({}));
+ if (!r.ok || d.error) {
+ flash('Could not load guest requests: ' + (d.error || r.status), false);
+ return;
+ }
+ setGuestReqBadge((d.pending || []).length);
+ const rows = d.pending || [];
+ $('guestrequest-rows').innerHTML = rows.length ? rows.map(q =>
+ '