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
@@ -1,9 +1,9 @@
|
|||||||
// Harness for the admin panel's GUESTS list (gift accounts), run through the
|
// Harness for the admin panel's GUESTS list (guest accounts), run through the
|
||||||
// skill's checker alongside the chart harness:
|
// skill's checker alongside the chart harness:
|
||||||
// ~/.hermes/skills/research/inference-cooperative/scripts/check-page-js.sh \
|
// ~/.hermes/skills/research/inference-cooperative/scripts/check-page-js.sh \
|
||||||
// app/main.py admin-panel-guests-harness.js
|
// app/main.py admin-panel-guests-harness.js
|
||||||
// Exercises load() against both payload shapes — the portal's split payload
|
// Exercises load() against both payload shapes — the portal's split payload
|
||||||
// (guests[]) and an older payload that still tags rows account_type='gift'
|
// (guests[]) and an older payload that still tags rows account_type='guest'
|
||||||
// inside members[] — and asserts the invariants that matter:
|
// inside members[] — and asserts the invariants that matter:
|
||||||
// * guests NEVER count as members, in either shape;
|
// * guests NEVER count as members, in either shape;
|
||||||
// * guests never render in the members table;
|
// * guests never render in the members table;
|
||||||
@@ -36,9 +36,9 @@ await runLoad({
|
|||||||
members: [memberRow("alice@example.com", 2), memberRow("bob@example.com", 1)],
|
members: [memberRow("alice@example.com", 2), memberRow("bob@example.com", 1)],
|
||||||
guests: [{
|
guests: [{
|
||||||
email: "friend@example.com", username: "friend", active: true,
|
email: "friend@example.com", username: "friend", active: true,
|
||||||
account_type: "gift", gift_inviter: "alice@example.com",
|
account_type: "guest", guest_inviter: "alice@example.com",
|
||||||
credit_balance: 5, credits_remaining: 3.5,
|
credit_balance: 5, credits_remaining: 3.5,
|
||||||
gift_expires_at: "2027-01-07T02:00:00", gift_status: "active",
|
guest_expires_at: "2027-01-07T02:00:00", guest_status: "active",
|
||||||
spend: 1.5, all_time_spend: 1.5,
|
spend: 1.5, all_time_spend: 1.5,
|
||||||
}],
|
}],
|
||||||
totals: { members: 2, total_spend: 4.5, total_all_time_spend: 45,
|
totals: { members: 2, total_spend: 4.5, total_all_time_spend: 45,
|
||||||
@@ -71,21 +71,21 @@ switchView("members");
|
|||||||
assert(document.getElementById("guests-section").style.display === "",
|
assert(document.getElementById("guests-section").style.display === "",
|
||||||
"guests section returns on the Members view");
|
"guests section returns on the Members view");
|
||||||
|
|
||||||
// ---- Shape 2: older payload — gifts tagged inside members[] ----
|
// ---- Shape 2: older payload — guests tagged inside members[] ----
|
||||||
await runLoad({
|
await runLoad({
|
||||||
members: [
|
members: [
|
||||||
memberRow("alice@example.com", 2),
|
memberRow("alice@example.com", 2),
|
||||||
memberRow("bob@example.com", 1),
|
memberRow("bob@example.com", 1),
|
||||||
{ email: "friend@example.com", username: "friend", active: true,
|
{ email: "friend@example.com", username: "friend", active: true,
|
||||||
account_type: "gift", gift_inviter: "alice@example.com",
|
account_type: "guest", guest_inviter: "alice@example.com",
|
||||||
credit_balance: 5, credits_remaining: 3.5, gift_expires_at: "2027-01-07T02:00:00",
|
credit_balance: 5, credits_remaining: 3.5, guest_expires_at: "2027-01-07T02:00:00",
|
||||||
gift_status: "active", spend: 0.5, all_time_spend: 5 },
|
guest_status: "active", spend: 0.5, all_time_spend: 5 },
|
||||||
],
|
],
|
||||||
totals: { members: 3, total_spend: 3.5, total_all_time_spend: 35,
|
totals: { members: 3, total_spend: 3.5, total_all_time_spend: 35,
|
||||||
operator_spend: 0, operator_all_time_spend: 0 },
|
operator_spend: 0, operator_all_time_spend: 0 },
|
||||||
});
|
});
|
||||||
assert(txt("tot-members") === "2",
|
assert(txt("tot-members") === "2",
|
||||||
"old payload: gift row subtracted from the member count (got " + txt("tot-members") + ")");
|
"old payload: guest row subtracted from the member count (got " + txt("tot-members") + ")");
|
||||||
assert(txt("tot-guests") === "1", "old payload: guest derived and counted");
|
assert(txt("tot-guests") === "1", "old payload: guest derived and counted");
|
||||||
assert(txt("tot-spend-cycle") === "$3.00",
|
assert(txt("tot-spend-cycle") === "$3.00",
|
||||||
"old payload: guest spend excluded from the spend total (3.5 - 0.5)");
|
"old payload: guest spend excluded from the spend total (3.5 - 0.5)");
|
||||||
@@ -98,12 +98,12 @@ assert(document.getElementById("guest-rows").innerHTML.indexOf("friend@example.c
|
|||||||
await runLoad({
|
await runLoad({
|
||||||
members: [memberRow("alice@example.com", 2)],
|
members: [memberRow("alice@example.com", 2)],
|
||||||
guests: [
|
guests: [
|
||||||
{ email: "lapsed@example.com", username: null, active: false, account_type: "gift",
|
{ email: "lapsed@example.com", username: null, active: false, account_type: "guest",
|
||||||
gift_inviter: "alice@example.com", credit_balance: 2, credits_remaining: 2,
|
guest_inviter: "alice@example.com", credit_balance: 2, credits_remaining: 2,
|
||||||
gift_expires_at: "2026-12-01T00:00:00", gift_status: "expired", spend: 3, all_time_spend: 3 },
|
guest_expires_at: "2026-12-01T00:00:00", guest_status: "expired", spend: 3, all_time_spend: 3 },
|
||||||
{ email: "joined@example.com", username: "joined", active: true, account_type: "gift",
|
{ email: "joined@example.com", username: "joined", active: true, account_type: "guest",
|
||||||
gift_inviter: "alice@example.com", credit_balance: 1, credits_remaining: 1,
|
guest_inviter: "alice@example.com", credit_balance: 1, credits_remaining: 1,
|
||||||
gift_expires_at: null, gift_status: "converted", spend: 4, all_time_spend: 4 },
|
guest_expires_at: null, guest_status: "converted", spend: 4, all_time_spend: 4 },
|
||||||
],
|
],
|
||||||
totals: { members: 1, total_spend: 2, total_all_time_spend: 20,
|
totals: { members: 1, total_spend: 2, total_all_time_spend: 20,
|
||||||
operator_spend: 0, operator_all_time_spend: 0 },
|
operator_spend: 0, operator_all_time_spend: 0 },
|
||||||
|
|||||||
+46
-46
@@ -197,11 +197,11 @@ async def api_set_credits(request: Request):
|
|||||||
return JSONResponse({"error": e.detail}, status_code=e.status_code)
|
return JSONResponse({"error": e.detail}, status_code=e.status_code)
|
||||||
|
|
||||||
|
|
||||||
@app.post("/api/provision-gift")
|
@app.post("/api/provision-guest")
|
||||||
async def api_provision_gift(request: Request):
|
async def api_provision_guest(request: Request):
|
||||||
"""Provision a gift account via the portal's /admin/provision-gift.
|
"""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
|
one per recipient ever, active-member inviter) and returns a clear
|
||||||
refusal — surfaced to the operator as-is.
|
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:
|
if not inviter or "@" not in inviter:
|
||||||
return JSONResponse({"error": "The inviting member's email is required"}, status_code=400)
|
return JSONResponse({"error": "The inviting member's email is required"}, status_code=400)
|
||||||
try:
|
try:
|
||||||
return await portal_post("/admin/provision-gift",
|
return await portal_post("/admin/provision-guest",
|
||||||
{"email": email, "name": name, "inviter": inviter})
|
{"email": email, "name": name, "inviter": inviter})
|
||||||
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)
|
||||||
@@ -315,9 +315,9 @@ PAGE_HTML = """<!DOCTYPE html>
|
|||||||
.pill.manual { background: #f1e8da; color: #a97a4a; }
|
.pill.manual { background: #f1e8da; color: #a97a4a; }
|
||||||
.pill.org { background: #e7edf5; color: #4a6a8a; }
|
.pill.org { background: #e7edf5; color: #4a6a8a; }
|
||||||
.pill.grace { background: #fdf3e3; color: #a97a2a; }
|
.pill.grace { background: #fdf3e3; color: #a97a2a; }
|
||||||
.pill.gift { background: #efe7f2; color: #7a5a92; }
|
.pill.guest { background: #efe7f2; color: #7a5a92; }
|
||||||
#gift-group input { padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; width: 170px; }
|
#guest-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; }
|
#guest-group input#guest-name { width: 120px; }
|
||||||
/* Trends tab (charts). Colours come from the same vars as the rest of the
|
/* 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. */
|
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; }
|
.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="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-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-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 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>
|
</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 active" id="mmode-balance" onclick="setMemberMode('balance')">Balance</button>
|
||||||
<button class="range-btn" id="mmode-all" onclick="setMemberMode('all')">All time</button>
|
<button class="range-btn" id="mmode-all" onclick="setMemberMode('all')">All time</button>
|
||||||
</span>
|
</span>
|
||||||
<span class="range-group" id="gift-group">
|
<span class="range-group" id="guest-group">
|
||||||
<span class="range-label">Send gift</span>
|
<span class="range-label">Guest access</span>
|
||||||
<input id="gift-email" type="email" placeholder="friend@example.com" list="member-email-list" autocomplete="off" />
|
<input id="guest-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="guest-name" type="text" placeholder="Their name" autocomplete="off" />
|
||||||
<input id="gift-inviter" type="email" placeholder="Inviting member" list="member-email-list" autocomplete="off" />
|
<input id="guest-inviter" type="email" placeholder="Inviting member" list="member-email-list" autocomplete="off" />
|
||||||
<datalist id="member-email-list"></datalist>
|
<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>
|
||||||
<span class="range-group" id="range-group" style="display:none;">
|
<span class="range-group" id="range-group" style="display:none;">
|
||||||
<span class="range-label">Period</span>
|
<span class="range-label">Period</span>
|
||||||
@@ -437,7 +437,7 @@ PAGE_HTML = """<!DOCTYPE html>
|
|||||||
|
|
||||||
<div id="guests-section" style="display:none;">
|
<div id="guests-section" style="display:none;">
|
||||||
<h3 style="margin:20px 0 8px;">Guests</h3>
|
<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">
|
<div class="table-scroll">
|
||||||
<table id="table-guests">
|
<table id="table-guests">
|
||||||
<thead>
|
<thead>
|
||||||
@@ -592,14 +592,14 @@ async function load() {
|
|||||||
// rather than left for the reader to guess.
|
// rather than left for the reader to guess.
|
||||||
$('tot-spend-cycle-own').textContent = fmt(d.totals.operator_spend ?? 0);
|
$('tot-spend-cycle-own').textContent = fmt(d.totals.operator_spend ?? 0);
|
||||||
$('tot-spend-all-own').textContent = fmt(d.totals.operator_all_time_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
|
// 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.
|
// count and the spend totals exclude guests in either payload shape.
|
||||||
const allRows = d.members || [];
|
const allRows = d.members || [];
|
||||||
const newShape = Array.isArray(d.guests);
|
const newShape = Array.isArray(d.guests);
|
||||||
guestsData = newShape ? d.guests : 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') !== 'gift');
|
membersData = newShape ? allRows : allRows.filter(m => (m.account_type || 'member') !== 'guest');
|
||||||
const gSpend = guestsData.reduce((s, m) => s + (Number(m.spend) || 0), 0);
|
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 gAll = guestsData.reduce((s, m) => s + (Number(m.all_time_spend) || 0), 0);
|
||||||
const t = d.totals || {};
|
const t = d.totals || {};
|
||||||
@@ -1109,11 +1109,11 @@ function switchView(view) {
|
|||||||
$('tab-trends').className = 'tab-btn' + (view === 'trends' ? ' active' : '');
|
$('tab-trends').className = 'tab-btn' + (view === 'trends' ? ' active' : '');
|
||||||
$('tab-money').className = 'tab-btn' + (view === 'money' ? ' active' : '');
|
$('tab-money').className = 'tab-btn' + (view === 'money' ? ' active' : '');
|
||||||
$('view-title').textContent = view === 'members' ? 'Members' : (view === 'models' ? 'Model usage' : (view === 'trends' ? 'Trends' : 'Money'));
|
$('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.
|
// action belongs to the members view too.
|
||||||
$('range-group').style.display = view === 'models' ? '' : 'none';
|
$('range-group').style.display = view === 'models' ? '' : 'none';
|
||||||
$('member-mode-group').style.display = view === 'members' ? '' : '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.
|
// Trends renders on first visit only, so the panel's initial load stays fast.
|
||||||
if (view === 'trends') loadMetrics();
|
if (view === 'trends') loadMetrics();
|
||||||
// Money renders on first visit only, same rule: one fetch, then the
|
// Money renders on first visit only, same rule: one fetch, then the
|
||||||
@@ -1168,7 +1168,7 @@ function render() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function renderMembers() {
|
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).
|
// operator can pick from (rebuilt per render; tiny).
|
||||||
const dl = document.getElementById('member-email-list');
|
const dl = document.getElementById('member-email-list');
|
||||||
if (dl) dl.innerHTML = membersData.map(m => '<option value="' + esc(m.email) + '"></option>').join('');
|
if (dl) dl.innerHTML = membersData.map(m => '<option value="' + esc(m.email) + '"></option>').join('');
|
||||||
@@ -1207,10 +1207,10 @@ function renderMembers() {
|
|||||||
const creditsCell = creditsShown > 0
|
const creditsCell = creditsShown > 0
|
||||||
? fmt(creditsShown)
|
? fmt(creditsShown)
|
||||||
: '<span style="color:var(--muted)">—</span>';
|
: '<span style="color:var(--muted)">—</span>';
|
||||||
const src = m.account_type === 'gift'
|
const src = m.account_type === 'guest'
|
||||||
? '<span class="pill gift" title="' + esc('Gift account — from ' + (m.gift_inviter || '?') +
|
? '<span class="pill guest" title="' + esc('Guest account — from ' + (m.guest_inviter || '?') +
|
||||||
' · expires ' + (m.gift_expires_at ? String(m.gift_expires_at).slice(0, 10) : '?') +
|
' · expires ' + (m.guest_expires_at ? String(m.guest_expires_at).slice(0, 10) : '?') +
|
||||||
' · $5 credit, no OC membership, never swept for dues') + '">gift</span>'
|
' · $5 credit, no OC membership, never swept for dues') + '">guest</span>'
|
||||||
: (m.manual
|
: (m.manual
|
||||||
? '<span class="pill manual" title="Manual member (no OC subscription; exempt from sweep)">manual</span>'
|
? '<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>');
|
: '<span class="pill active" title="Open Collective Membership subscription">OC</span>');
|
||||||
@@ -1246,8 +1246,8 @@ function renderMembers() {
|
|||||||
}).join('');
|
}).join('');
|
||||||
clearArrows('members', memberSort);
|
clearArrows('members', memberSort);
|
||||||
|
|
||||||
// Guests — gift accounts in their own list, never in the members table or
|
// Guests — guest accounts in their own list, never in the members table or
|
||||||
// the member count. Inviter and expiry come from the portal gifts ledger.
|
// the member count. Inviter and expiry come from the portal guest ledger.
|
||||||
const guestSection = document.getElementById('guests-section');
|
const guestSection = document.getElementById('guests-section');
|
||||||
if (guestsData.length) {
|
if (guestsData.length) {
|
||||||
guestSection.style.display = '';
|
guestSection.style.display = '';
|
||||||
@@ -1255,13 +1255,13 @@ function renderMembers() {
|
|||||||
const top = g.username || g.email;
|
const top = g.username || g.email;
|
||||||
const emailLine = g.username ? '<div style="color:var(--muted);font-size:11px">' + esc(g.email) + '</div>' : '';
|
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 credits = Number(g.credits_remaining ?? g.credit_balance ?? 0);
|
||||||
const exp = g.gift_expires_at ? String(g.gift_expires_at).slice(0, 10) : '—';
|
const exp = g.guest_expires_at ? String(g.guest_expires_at).slice(0, 10) : '—';
|
||||||
const st = String(g.gift_status || (g.active ? 'active' : 'inactive'));
|
const st = String(g.guest_status || (g.active ? 'active' : 'inactive'));
|
||||||
const stClass = st === 'active' ? 'active' : (st === 'converted' ? 'org' : '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>' +
|
return '<tr>' +
|
||||||
'<td><strong>' + esc(top) + '</strong>' + emailLine + '</td>' +
|
'<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 class="num remaining-col">' + fmt(credits) + '</td>' +
|
||||||
'<td>' + esc(exp) + '</td>' +
|
'<td>' + esc(exp) + '</td>' +
|
||||||
'<td><span class="pill ' + stClass + '"' + (stTitle ? ' title="' + esc(stTitle) + '"' : '') + '>' + esc(st) + '</span></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); }
|
} catch (e) { flash(e.message, false); }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gift action: provision a $5 guest account for a friend of a member. The
|
// Guest 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
|
// 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
|
// recipient ever, inviter must be an active member) and reports a clear
|
||||||
// refusal; the panel only collects the three fields.
|
// refusal; the panel only collects the three fields.
|
||||||
async function sendGift() {
|
async function sendGuestAccess() {
|
||||||
const email = ($('gift-email').value || '').trim();
|
const email = ($('guest-email').value || '').trim();
|
||||||
const name = ($('gift-name').value || '').trim();
|
const name = ($('guest-name').value || '').trim();
|
||||||
const inviter = ($('gift-inviter').value || '').trim();
|
const inviter = ($('guest-inviter').value || '').trim();
|
||||||
const btn = $('gift-send');
|
const btn = $('guest-send');
|
||||||
if (!email || email.indexOf('@') < 1) { flash("Enter the recipient's email", false); return; }
|
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; }
|
if (!inviter || inviter.indexOf('@') < 1) { flash("Enter the inviting member's email", false); return; }
|
||||||
btn.disabled = true; btn.textContent = "Sending…";
|
btn.disabled = true; btn.textContent = "Sending…";
|
||||||
try {
|
try {
|
||||||
const r = await fetch('/api/provision-gift', {
|
const r = await fetch('/api/provision-guest', {
|
||||||
method: 'POST', headers: {'Content-Type': 'application/json'},
|
method: 'POST', headers: {'Content-Type': 'application/json'},
|
||||||
body: JSON.stringify({ email, name, inviter })
|
body: JSON.stringify({ email, name, inviter })
|
||||||
});
|
});
|
||||||
const d = await r.json().catch(() => ({}));
|
const d = await r.json().catch(() => ({}));
|
||||||
if (!r.ok || d.error) { flash(d.error || ('Gift failed (' + r.status + ')'), false); return; }
|
if (!r.ok || d.error) { flash(d.error || ('Could not send guest access (' + r.status + ')'), false); return; }
|
||||||
flash('Gift sent — ' + email + ' has $5 of credits (expires in ' + (d.expires_in_days || 60) +
|
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);
|
' days). The welcome email is on its way.', true);
|
||||||
$('gift-email').value = ''; $('gift-name').value = '';
|
$('guest-email').value = ''; $('guest-name').value = '';
|
||||||
load();
|
load();
|
||||||
} catch (e) { flash('Gift failed: ' + e.message, false); }
|
} catch (e) { flash('Guest access failed: ' + e.message, false); }
|
||||||
finally { btn.disabled = false; btn.textContent = 'Gift $5 access'; }
|
finally { btn.disabled = false; btn.textContent = 'Send guest access'; }
|
||||||
}
|
}
|
||||||
|
|
||||||
load();
|
load();
|
||||||
|
|||||||
Reference in new issue
Block a user