dashboard: explain a lapsed membership instead of flashing an error
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/push/woodpecker Pipeline was successful
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.
This commit is contained in:
1 parent
38b8d25d74
commit
5a3df91587
1 file changed
+35
+35
@@ -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 =
|
||||
'<div class="ended">' +
|
||||
'<h3>Your membership is not active right now</h3>' +
|
||||
'<p class="hint">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.</p>' +
|
||||
(evidence ? '<p class="hint">Last check: ' + escapeHtml(decision || 'no decision recorded') + ' — ' + escapeHtml(evidence) + '</p>' : '') +
|
||||
'<a class="buy-btn" href="' + escapeHtml(url) + '" target="_blank" rel="noopener">Contribute</a>' +
|
||||
'</div>';
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
Reference in new issue
Block a user