Rename 'gift' to 'guest' throughout: guest pill, Guests list wording, provision-guest route and send form (pure rename, no behaviour change)
This commit is contained in:
1 parent
7b8a3f5654
commit
a8674af611
2 files changed
+61
-61
No files matched your search
+46
-46
@@ -197,11 +197,11 @@ async def api_set_credits(request: Request):
|
||||
return JSONResponse({"error": e.detail}, status_code=e.status_code)
|
||||
|
||||
|
||||
@app.post("/api/provision-gift")
|
||||
async def api_provision_gift(request: Request):
|
||||
"""Provision a gift account via the portal's /admin/provision-gift.
|
||||
@app.post("/api/provision-guest")
|
||||
async def api_provision_guest(request: Request):
|
||||
"""Provision a guest account via the portal's /admin/provision-guest.
|
||||
|
||||
The portal enforces the abuse rules (one gift per inviter per 30 days,
|
||||
The portal enforces the abuse rules (one guest access per inviter per 30 days,
|
||||
one per recipient ever, active-member inviter) and returns a clear
|
||||
refusal — surfaced to the operator as-is.
|
||||
"""
|
||||
@@ -216,7 +216,7 @@ async def api_provision_gift(request: Request):
|
||||
if not inviter or "@" not in inviter:
|
||||
return JSONResponse({"error": "The inviting member's email is required"}, status_code=400)
|
||||
try:
|
||||
return await portal_post("/admin/provision-gift",
|
||||
return await portal_post("/admin/provision-guest",
|
||||
{"email": email, "name": name, "inviter": inviter})
|
||||
except HTTPException as e:
|
||||
return JSONResponse({"error": e.detail}, status_code=e.status_code)
|
||||
@@ -315,9 +315,9 @@ PAGE_HTML = """<!DOCTYPE html>
|
||||
.pill.manual { background: #f1e8da; color: #a97a4a; }
|
||||
.pill.org { background: #e7edf5; color: #4a6a8a; }
|
||||
.pill.grace { background: #fdf3e3; color: #a97a2a; }
|
||||
.pill.gift { background: #efe7f2; color: #7a5a92; }
|
||||
#gift-group input { padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; width: 170px; }
|
||||
#gift-group input#gift-name { width: 120px; }
|
||||
.pill.guest { background: #efe7f2; color: #7a5a92; }
|
||||
#guest-group input { padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; width: 170px; }
|
||||
#guest-group input#guest-name { width: 120px; }
|
||||
/* Trends tab (charts). Colours come from the same vars as the rest of the
|
||||
panel; the SVG is inline so there is no chart library and no CDN. */
|
||||
.trend-controls { display: flex; gap: 22px; flex-wrap: wrap; margin: 14px 0 0; }
|
||||
@@ -383,7 +383,7 @@ PAGE_HTML = """<!DOCTYPE html>
|
||||
|
||||
<div class="totals">
|
||||
<div class="tot"><div class="num" id="tot-members">—</div><div class="lbl">members</div></div>
|
||||
<div class="tot"><div class="num" id="tot-guests">—</div><div class="lbl">guests — gift accounts</div><div class="sub">excluded from member counts</div></div>
|
||||
<div class="tot"><div class="num" id="tot-guests">—</div><div class="lbl">guests — guest access</div><div class="sub">excluded from member counts</div></div>
|
||||
<div class="tot"><div class="num" id="tot-spend-cycle">—</div><div class="lbl">current balance used — members + co-op's own</div><div class="sub">co-op's own share: <span id="tot-spend-cycle-own">—</span></div></div>
|
||||
<div class="tot"><div class="num" id="tot-spend-all">—</div><div class="lbl">all-time spend — members + co-op's own</div><div class="sub">co-op's own share: <span id="tot-spend-all-own">—</span></div></div>
|
||||
</div>
|
||||
@@ -400,13 +400,13 @@ PAGE_HTML = """<!DOCTYPE html>
|
||||
<button class="range-btn active" id="mmode-balance" onclick="setMemberMode('balance')">Balance</button>
|
||||
<button class="range-btn" id="mmode-all" onclick="setMemberMode('all')">All time</button>
|
||||
</span>
|
||||
<span class="range-group" id="gift-group">
|
||||
<span class="range-label">Send gift</span>
|
||||
<input id="gift-email" type="email" placeholder="friend@example.com" list="member-email-list" autocomplete="off" />
|
||||
<input id="gift-name" type="text" placeholder="Their name" autocomplete="off" />
|
||||
<input id="gift-inviter" type="email" placeholder="Inviting member" list="member-email-list" autocomplete="off" />
|
||||
<span class="range-group" id="guest-group">
|
||||
<span class="range-label">Guest access</span>
|
||||
<input id="guest-email" type="email" placeholder="friend@example.com" list="member-email-list" autocomplete="off" />
|
||||
<input id="guest-name" type="text" placeholder="Their name" autocomplete="off" />
|
||||
<input id="guest-inviter" type="email" placeholder="Inviting member" list="member-email-list" autocomplete="off" />
|
||||
<datalist id="member-email-list"></datalist>
|
||||
<button class="range-btn" id="gift-send" onclick="sendGift()">Gift $5 access</button>
|
||||
<button class="range-btn" id="guest-send" onclick="sendGuestAccess()">Send guest access</button>
|
||||
</span>
|
||||
<span class="range-group" id="range-group" style="display:none;">
|
||||
<span class="range-label">Period</span>
|
||||
@@ -437,7 +437,7 @@ PAGE_HTML = """<!DOCTYPE html>
|
||||
|
||||
<div id="guests-section" style="display:none;">
|
||||
<h3 style="margin:20px 0 8px;">Guests</h3>
|
||||
<p style="color:var(--muted);font-size:12px;margin:0 0 8px;">Gift accounts — access an inviting member gave to someone outside the co-op. Not members — excluded from member counts; a gift lapses on its time box or when its credits are spent.</p>
|
||||
<p style="color:var(--muted);font-size:12px;margin:0 0 8px;">Guest accounts — access an inviting member gave to someone outside the co-op. Not members — excluded from member counts; guest access lapses on its time box or when its credits are spent.</p>
|
||||
<div class="table-scroll">
|
||||
<table id="table-guests">
|
||||
<thead>
|
||||
@@ -592,14 +592,14 @@ async function load() {
|
||||
// rather than left for the reader to guess.
|
||||
$('tot-spend-cycle-own').textContent = fmt(d.totals.operator_spend ?? 0);
|
||||
$('tot-spend-all-own').textContent = fmt(d.totals.operator_all_time_spend ?? 0);
|
||||
// Guests: gift accounts live in their own list and never count as members.
|
||||
// Guests: guest accounts live in their own list and never count as members.
|
||||
// The portal splits them out (guests[]); an older payload that still tags
|
||||
// rows account_type='gift' inside members[] is derived here, so the member
|
||||
// rows account_type='guest' inside members[] is derived here, so the member
|
||||
// count and the spend totals exclude guests in either payload shape.
|
||||
const allRows = d.members || [];
|
||||
const newShape = Array.isArray(d.guests);
|
||||
guestsData = newShape ? d.guests : allRows.filter(m => (m.account_type || 'member') === 'gift');
|
||||
membersData = newShape ? allRows : allRows.filter(m => (m.account_type || 'member') !== 'gift');
|
||||
guestsData = newShape ? d.guests : allRows.filter(m => (m.account_type || 'member') === 'guest');
|
||||
membersData = newShape ? allRows : allRows.filter(m => (m.account_type || 'member') !== 'guest');
|
||||
const gSpend = guestsData.reduce((s, m) => s + (Number(m.spend) || 0), 0);
|
||||
const gAll = guestsData.reduce((s, m) => s + (Number(m.all_time_spend) || 0), 0);
|
||||
const t = d.totals || {};
|
||||
@@ -1109,11 +1109,11 @@ function switchView(view) {
|
||||
$('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'));
|
||||
// Mode groups: Balance/All-time for members; Period for models; the gift
|
||||
// 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';
|
||||
$('member-mode-group').style.display = view === 'members' ? '' : 'none';
|
||||
$('gift-group').style.display = view === 'members' ? '' : 'none';
|
||||
$('guest-group').style.display = view === 'members' ? '' : 'none';
|
||||
// Trends renders on first visit only, so the panel's initial load stays fast.
|
||||
if (view === 'trends') loadMetrics();
|
||||
// Money renders on first visit only, same rule: one fetch, then the
|
||||
@@ -1168,7 +1168,7 @@ function render() {
|
||||
}
|
||||
|
||||
function renderMembers() {
|
||||
// Datalist for the gift form's recipient/inviter fields: member emails the
|
||||
// Datalist for the guest form's recipient/inviter fields: member emails the
|
||||
// operator can pick from (rebuilt per render; tiny).
|
||||
const dl = document.getElementById('member-email-list');
|
||||
if (dl) dl.innerHTML = membersData.map(m => '<option value="' + esc(m.email) + '"></option>').join('');
|
||||
@@ -1207,10 +1207,10 @@ function renderMembers() {
|
||||
const creditsCell = creditsShown > 0
|
||||
? fmt(creditsShown)
|
||||
: '<span style="color:var(--muted)">—</span>';
|
||||
const src = m.account_type === 'gift'
|
||||
? '<span class="pill gift" title="' + esc('Gift account — from ' + (m.gift_inviter || '?') +
|
||||
' · expires ' + (m.gift_expires_at ? String(m.gift_expires_at).slice(0, 10) : '?') +
|
||||
' · $5 credit, no OC membership, never swept for dues') + '">gift</span>'
|
||||
const src = m.account_type === 'guest'
|
||||
? '<span class="pill guest" title="' + esc('Guest account — from ' + (m.guest_inviter || '?') +
|
||||
' · expires ' + (m.guest_expires_at ? String(m.guest_expires_at).slice(0, 10) : '?') +
|
||||
' · $5 credit, no OC membership, never swept for dues') + '">guest</span>'
|
||||
: (m.manual
|
||||
? '<span class="pill manual" title="Manual member (no OC subscription; exempt from sweep)">manual</span>'
|
||||
: '<span class="pill active" title="Open Collective Membership subscription">OC</span>');
|
||||
@@ -1246,8 +1246,8 @@ function renderMembers() {
|
||||
}).join('');
|
||||
clearArrows('members', memberSort);
|
||||
|
||||
// Guests — gift accounts in their own list, never in the members table or
|
||||
// the member count. Inviter and expiry come from the portal gifts ledger.
|
||||
// Guests — guest accounts in their own list, never in the members table or
|
||||
// the member count. Inviter and expiry come from the portal guest ledger.
|
||||
const guestSection = document.getElementById('guests-section');
|
||||
if (guestsData.length) {
|
||||
guestSection.style.display = '';
|
||||
@@ -1255,13 +1255,13 @@ function renderMembers() {
|
||||
const top = g.username || g.email;
|
||||
const emailLine = g.username ? '<div style="color:var(--muted);font-size:11px">' + esc(g.email) + '</div>' : '';
|
||||
const credits = Number(g.credits_remaining ?? g.credit_balance ?? 0);
|
||||
const exp = g.gift_expires_at ? String(g.gift_expires_at).slice(0, 10) : '—';
|
||||
const st = String(g.gift_status || (g.active ? 'active' : 'inactive'));
|
||||
const exp = g.guest_expires_at ? String(g.guest_expires_at).slice(0, 10) : '—';
|
||||
const st = String(g.guest_status || (g.active ? 'active' : 'inactive'));
|
||||
const stClass = st === 'active' ? 'active' : (st === 'converted' ? 'org' : 'inactive');
|
||||
const stTitle = { active: 'Gift live', converted: 'Gift became a member', expired: 'Time box elapsed', depleted: 'Credits spent' }[st] || '';
|
||||
const stTitle = { active: 'Guest access live', converted: 'Guest became a member', expired: 'Time box elapsed', depleted: 'Credits spent' }[st] || '';
|
||||
return '<tr>' +
|
||||
'<td><strong>' + esc(top) + '</strong>' + emailLine + '</td>' +
|
||||
'<td>' + esc(g.gift_inviter || '—') + '</td>' +
|
||||
'<td>' + esc(g.guest_inviter || '—') + '</td>' +
|
||||
'<td class="num remaining-col">' + fmt(credits) + '</td>' +
|
||||
'<td>' + esc(exp) + '</td>' +
|
||||
'<td><span class="pill ' + stClass + '"' + (stTitle ? ' title="' + esc(stTitle) + '"' : '') + '>' + esc(st) + '</span></td>' +
|
||||
@@ -1361,31 +1361,31 @@ async function addBalance(email) {
|
||||
} catch (e) { flash(e.message, false); }
|
||||
}
|
||||
|
||||
// Gift action: provision a $5 guest account for a friend of a member. The
|
||||
// portal enforces the abuse rules (one gift per inviter per 30 days, one per
|
||||
// Guest action: provision a $5 guest account for a friend of a member. The
|
||||
// portal enforces the abuse rules (one guest access per inviter per 30 days, one per
|
||||
// recipient ever, inviter must be an active member) and reports a clear
|
||||
// refusal; the panel only collects the three fields.
|
||||
async function sendGift() {
|
||||
const email = ($('gift-email').value || '').trim();
|
||||
const name = ($('gift-name').value || '').trim();
|
||||
const inviter = ($('gift-inviter').value || '').trim();
|
||||
const btn = $('gift-send');
|
||||
async function sendGuestAccess() {
|
||||
const email = ($('guest-email').value || '').trim();
|
||||
const name = ($('guest-name').value || '').trim();
|
||||
const inviter = ($('guest-inviter').value || '').trim();
|
||||
const btn = $('guest-send');
|
||||
if (!email || email.indexOf('@') < 1) { flash("Enter the recipient's email", false); return; }
|
||||
if (!inviter || inviter.indexOf('@') < 1) { flash("Enter the inviting member's email", false); return; }
|
||||
btn.disabled = true; btn.textContent = "Sending…";
|
||||
try {
|
||||
const r = await fetch('/api/provision-gift', {
|
||||
const r = await fetch('/api/provision-guest', {
|
||||
method: 'POST', headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({ email, name, inviter })
|
||||
});
|
||||
const d = await r.json().catch(() => ({}));
|
||||
if (!r.ok || d.error) { flash(d.error || ('Gift failed (' + r.status + ')'), false); return; }
|
||||
flash('Gift sent — ' + email + ' has $5 of credits (expires in ' + (d.expires_in_days || 60) +
|
||||
if (!r.ok || d.error) { flash(d.error || ('Could not send guest access (' + r.status + ')'), false); return; }
|
||||
flash('Guest access sent — ' + email + ' has $5 of credits (expires in ' + (d.expires_in_days || 60) +
|
||||
' days). The welcome email is on its way.', true);
|
||||
$('gift-email').value = ''; $('gift-name').value = '';
|
||||
$('guest-email').value = ''; $('guest-name').value = '';
|
||||
load();
|
||||
} catch (e) { flash('Gift failed: ' + e.message, false); }
|
||||
finally { btn.disabled = false; btn.textContent = 'Gift $5 access'; }
|
||||
} catch (e) { flash('Guest access failed: ' + e.message, false); }
|
||||
finally { btn.disabled = false; btn.textContent = 'Send guest access'; }
|
||||
}
|
||||
|
||||
load();
|
||||
|
||||
Reference in new issue
Block a user