From 5a3df9158770c78c94cbb0230c13041b998110ec Mon Sep 17 00:00:00 2001 From: Inferencebot Date: Tue, 17 Nov 2026 05:01:36 +0000 Subject: [PATCH] dashboard: explain a lapsed membership instead of flashing an error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On a 403 from usage, the page already asked the portal whether this was an ended guest. It now also asks /api/membership-status, and renders state, the last allowance decision with its evidence, the OC minimum, and a contribute link — reusing the ended-state panel styles. --- app/main.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/app/main.py b/app/main.py index b63de2e..7cc71a8 100644 --- a/app/main.py +++ b/app/main.py @@ -244,6 +244,22 @@ async def api_revoke_key(name: str, request: Request): return JSONResponse({"error": e.detail}, status_code=e.status_code) +@app.get("/api/membership-status") +async def api_membership_status(request: Request): + """Why the dashboard is empty: state, reason, minimum, next step. + + Answers in ANY membership state via the portal's read-only route, so a lapsed + member sees an explanation instead of an error flash. + """ + try: + identity = get_user_identity(request) + return await broker_get(identity, "/broker/membership-status") + except HTTPException as exc: + raise exc + except Exception: + raise HTTPException(502, "membership status unavailable") + + @app.get("/api/matrix-mxid") async def api_get_matrix_mxid(request: Request): identity = get_user_identity(request) @@ -1060,6 +1076,21 @@ const GUEST_STATUS_LABELS = { 'cancelled by recipient': ['ended — they cancelled', 'done'], }; +function renderMemberLapsed(ms) { + const min = Number(ms.minimum_contribution || 0); + const decision = (ms.last_decision && ms.last_decision.decision) ? ms.last_decision.decision : ''; + const evidence = (ms.last_decision && ms.last_decision.evidence) ? ms.last_decision.evidence : ''; + const url = ms.contribute_url || 'https://opencollective.com/inference-cooperative/contribute'; + $('usage-header').style.display = 'none'; + $('usage').innerHTML = + '
' + + '

Your membership is not active right now

' + + '

Your account, data and API keys are kept. Access resumes with a contribution of at least $' + min + ' a month; the minimum is set by Open Collective.

' + + (evidence ? '

Last check: ' + escapeHtml(decision || 'no decision recorded') + ' — ' + escapeHtml(evidence) + '

' : '') + + 'Contribute' + + '
'; +} + function guestStatusPill(status, kind) { const [label, cls] = GUEST_STATUS_LABELS[status] || [(status || 'sent').replace(/^./, c => c.toUpperCase()), 'done']; @@ -1182,6 +1213,10 @@ async function load() { const gs = await fetch('/api/guest-status'); const g = await gs.json(); if (g && g.guest && g.ended) { renderGuestEnded(g); return; } + try { + const ms = await (await fetch('/api/membership-status')).json(); + if (ms && ms.active === false) { renderMemberLapsed(ms); return; } + } catch (e2) { /* fall through to the error flash */ } } catch (e) { /* fall through to the error flash */ } } flash(d.error, false);