Rename 'gift' to 'guest' throughout: guest-status/cancel-guest routes, cancel-link wording, ended-state lines (pure rename, no behaviour change)

This commit is contained in:
inference-bot committed 2026-11-08 02:35:52 +00:00
1 parent 19361e27e4
commit 7430811ddc
1 file changed
+34 -34
+34 -34
View File
@@ -218,12 +218,12 @@ async def api_set_matrix_mxid(request: Request):
return JSONResponse({"error": e.detail}, status_code=e.status_code) return JSONResponse({"error": e.detail}, status_code=e.status_code)
@app.get("/api/gift-status") @app.get("/api/guest-status")
async def api_gift_status(request: Request): async def api_guest_status(request: Request):
"""What became of the caller's gift account (guest view). """What became of the caller's guest account (guest view).
Loaded when the usage view refuses a GUEST (access ended): the portal Loaded when the usage view refuses a GUEST (access ended): the portal
answers for ended gift accounts so the dashboard can say plainly that answers for ended guest accounts so the dashboard can say plainly that
access ended, the data is kept, and a membership is still available. access ended, the data is kept, and a membership is still available.
Members get guest: false — the caller falls back to the usage error. Members get guest: false — the caller falls back to the usage error.
""" """
@@ -231,25 +231,25 @@ async def api_gift_status(request: Request):
if not identity: if not identity:
return JSONResponse({"error": "unauthenticated"}, status_code=401) return JSONResponse({"error": "unauthenticated"}, status_code=401)
try: try:
return await broker_get(identity, "/broker/gift-status") return await broker_get(identity, "/broker/guest-status")
except HTTPException as e: except HTTPException as e:
return JSONResponse({"error": e.detail}, status_code=e.status_code) return JSONResponse({"error": e.detail}, status_code=e.status_code)
@app.post("/api/cancel-gift") @app.post("/api/cancel-guest")
async def api_cancel_gift(request: Request): async def api_cancel_guest(request: Request):
"""End the caller's own gift account (self-service cancel, guest view). """End the caller's own guest account (self-service cancel, guest view).
One hop to the portal broker, which holds the actual semantics: access One hop to the portal broker, which holds the actual semantics: access
ends immediately, unspent credit returns to the co-op, the ledger keeps ends immediately, unspent credit returns to the co-op, the ledger keeps
the trail, and a repeat call is a no-op. Gift accounts only — the portal the trail, and a repeat call is a no-op. Guest accounts only — the portal
refuses a paying member with 403. refuses a paying member with 403.
""" """
identity = get_user_identity(request) identity = get_user_identity(request)
if not identity: if not identity:
return JSONResponse({"error": "unauthenticated"}, status_code=401) return JSONResponse({"error": "unauthenticated"}, status_code=401)
try: try:
return await broker_post(identity, "/broker/cancel-gift") return await broker_post(identity, "/broker/cancel-guest")
except HTTPException as e: except HTTPException as e:
return JSONResponse({"error": e.detail}, status_code=e.status_code) return JSONResponse({"error": e.detail}, status_code=e.status_code)
@@ -435,7 +435,7 @@ PAGE_HTML = """<!DOCTYPE html>
.oc-note a { color: var(--green-deep); font-weight: 600; text-decoration: none; } .oc-note a { color: var(--green-deep); font-weight: 600; text-decoration: none; }
.oc-note a:hover { text-decoration: underline; } .oc-note a:hover { text-decoration: underline; }
/* Guest self-service cancel: a quiet link that reveals the confirm step, /* Guest self-service cancel: a quiet link that reveals the confirm step,
then ends the gift. Sits under the Become-a-member row. */ then ends the access. Sits under the Become-a-member row. */
.cancel-row { margin-top: 14px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; } .cancel-row { margin-top: 14px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.cancel-link { .cancel-link {
font-family: inherit; cursor: pointer; background: none; border: none; font-family: inherit; cursor: pointer; background: none; border: none;
@@ -673,11 +673,11 @@ PAGE_HTML = """<!DOCTYPE html>
<a href="@@BECOME_MEMBER_URL@@" target="_blank" rel="noopener">Manage your payment on Open Collective →</a> <a href="@@BECOME_MEMBER_URL@@" target="_blank" rel="noopener">Manage your payment on Open Collective →</a>
</p> </p>
<div class="cancel-row" id="cancel-row" style="display:none"> <div class="cancel-row" id="cancel-row" style="display:none">
<button class="cancel-link" id="cancel-reveal" onclick="revealCancelGift()">Cancel gift access</button> <button class="cancel-link" id="cancel-reveal" onclick="revealCancelGuest()">Cancel guest access</button>
<span id="cancel-confirm" style="display:none;"> <span id="cancel-confirm" style="display:none;">
<span class="cancel-confirm-note">This ends your access now. Unspent gift credit returns to the co-op; your account and data are kept.</span> <span class="cancel-confirm-note">This ends your access now. Unspent guest credit returns to the co-op; your account and data are kept.</span>
<button class="cancel-go" id="cancel-go" onclick="doCancelGift()">Confirm — end my access</button> <button class="cancel-go" id="cancel-go" onclick="doCancelGuest()">Confirm — end my access</button>
<button class="cancel-keep" onclick="hideCancelGift()">Keep it</button> <button class="cancel-keep" onclick="hideCancelGuest()">Keep it</button>
</span> </span>
</div> </div>
<div class="models" id="models"></div> <div class="models" id="models"></div>
@@ -782,22 +782,22 @@ function fmtMoney(n) { const v = Math.abs(Number(n)) < 0.005 ? 0 : (Number(n) ||
// --- Guest self-service cancel (reveal → confirm → ended state) ----------- // --- Guest self-service cancel (reveal → confirm → ended state) -----------
function revealCancelGift() { function revealCancelGuest() {
$('cancel-reveal').style.display = 'none'; $('cancel-reveal').style.display = 'none';
$('cancel-confirm').style.display = ''; $('cancel-confirm').style.display = '';
} }
function hideCancelGift() { function hideCancelGuest() {
$('cancel-confirm').style.display = 'none'; $('cancel-confirm').style.display = 'none';
$('cancel-reveal').style.display = ''; $('cancel-reveal').style.display = '';
} }
async function doCancelGift() { async function doCancelGuest() {
const btn = $('cancel-go'); const btn = $('cancel-go');
btn.disabled = true; btn.disabled = true;
btn.textContent = 'Ending…'; btn.textContent = 'Ending…';
try { try {
const r = await fetch('/api/cancel-gift', { method: 'POST' }); const r = await fetch('/api/cancel-guest', { method: 'POST' });
const d = await r.json().catch(() => ({})); const d = await r.json().catch(() => ({}));
if (!r.ok || d.error) { if (!r.ok || d.error) {
flash(d.error || 'Cancelling failed — try again', false); flash(d.error || 'Cancelling failed — try again', false);
@@ -805,8 +805,8 @@ async function doCancelGift() {
btn.textContent = 'Confirm — end my access'; btn.textContent = 'Confirm — end my access';
return; return;
} }
renderGiftEnded({ renderGuestEnded({
gift_status: d.gift_status || 'cancelled by recipient', guest_status: d.guest_status || 'cancelled by recipient',
credits_returned: d.credits_returned || 0 credits_returned: d.credits_returned || 0
}); });
} catch (e) { } catch (e) {
@@ -818,27 +818,27 @@ async function doCancelGift() {
// The ended state: access over, account and data kept, membership one // The ended state: access over, account and data kept, membership one
// contribution away. Replaces the usage card content. // contribution away. Replaces the usage card content.
function renderGiftEnded(g) { function renderGuestEnded(g) {
const st = String(g.gift_status || ''); const st = String(g.guest_status || '');
let line; let line;
if (st === 'cancelled by recipient') { if (st === 'cancelled by recipient') {
line = 'You cancelled your gift access.'; line = 'You cancelled your guest access.';
if (Number(g.credits_returned) > 0) { if (Number(g.credits_returned) > 0) {
line += ' Unspent credit of ' + fmtMoney(g.credits_returned) + ' was returned to the co-op.'; line += ' Unspent credit of ' + fmtMoney(g.credits_returned) + ' was returned to the co-op.';
} }
} else if (st === 'expired') { } else if (st === 'expired') {
line = 'The gift ran out of time.'; line = 'Guest access ran out of time.';
} else if (st === 'depleted') { } else if (st === 'depleted') {
line = 'The gift credit was spent.'; line = 'The guest credit was spent.';
} else { } else {
line = 'Your gift access has ended.'; line = 'Your guest access has ended.';
} }
$('usage-header').style.display = 'none'; $('usage-header').style.display = 'none';
$('view-coop').style.display = 'none'; $('view-coop').style.display = 'none';
$('cancel-row').style.display = 'none'; $('cancel-row').style.display = 'none';
$('view-mine').innerHTML = $('view-mine').innerHTML =
'<div class="ended">' + '<div class="ended">' +
'<h3>Your gift access has ended</h3>' + '<h3>Your guest access has ended</h3>' +
'<p class="hint">' + line + '</p>' + '<p class="hint">' + line + '</p>' +
'<p class="hint">Your account and data are kept. Become a member anytime with the same login — your account resumes as a full membership, and a member can re-invite you.</p>' + '<p class="hint">Your account and data are kept. Become a member anytime with the same login — your account resumes as a full membership, and a member can re-invite you.</p>' +
'<a class="buy-btn" href="@@BECOME_MEMBER_URL@@" target="_blank" rel="noopener">Become a member</a>' + '<a class="buy-btn" href="@@BECOME_MEMBER_URL@@" target="_blank" rel="noopener">Become a member</a>' +
@@ -854,20 +854,20 @@ async function load() {
const d = await r.json(); const d = await r.json();
if (d.error) { if (d.error) {
// A 403 can be an ENDED GUEST (cancelled, expired or spent out): the // A 403 can be an ENDED GUEST (cancelled, expired or spent out): the
// portal answers /api/gift-status for those, so the dashboard says // portal answers /api/guest-status for those, so the dashboard says
// plainly that access ended instead of flashing an error. // plainly that access ended instead of flashing an error.
if (r.status === 403) { if (r.status === 403) {
try { try {
const gs = await fetch('/api/gift-status'); const gs = await fetch('/api/guest-status');
const g = await gs.json(); const g = await gs.json();
if (g && g.guest && g.ended) { renderGiftEnded(g); return; } if (g && g.guest && g.ended) { renderGuestEnded(g); return; }
} catch (e) { /* fall through to the error flash */ } } catch (e) { /* fall through to the error flash */ }
} }
flash(d.error, false); flash(d.error, false);
return; return;
} }
// Gift accounts (portal flag): no Matrix section — the card is hidden in // Guest accounts (portal flag): no Matrix section — the card is hidden in
// the markup and only shown to members — and a Become-a-member button in // the markup and only shown to members — and a Become-a-member button in
// place of the credit-pack buy path. Everything else stays. // place of the credit-pack buy path. Everything else stays.
const isGuest = !!d.guest; const isGuest = !!d.guest;
@@ -877,8 +877,8 @@ async function load() {
const b = $('buy-btn'); const b = $('buy-btn');
b.href = '@@BECOME_MEMBER_URL@@'; b.href = '@@BECOME_MEMBER_URL@@';
b.textContent = 'Become a member'; b.textContent = 'Become a member';
$('buy-credits').textContent = 'Your gift credit never expires · members get a monthly allowance'; $('buy-credits').textContent = 'Your guest credit never expires · members get a monthly allowance';
$('meta').textContent = 'A gift from a member — $5 of AI usage across chat and the API.'; $('meta').textContent = 'Guest access from a member — $5 of AI usage across chat and the API.';
$('cancel-row').style.display = ''; $('cancel-row').style.display = '';
} }