Guest-invite form: keep a name field, optional and clearly labelled

Final operator preference: the standard form is the guest's email
(required) plus an OPTIONAL display name, labelled 'Their name
(optional)'. The name passes through to provisioning as the initial
display name (the Cloudron path fills only empty names and never
overwrites one the guest sets at setup); an empty name is never derived
from the email.
This commit is contained in:
inference-bot committed 2026-11-08 02:57:28 +00:00
1 parent d6d960324a
commit 575338a577
1 file changed
+21 -14
+21 -14
View File
@@ -201,22 +201,24 @@ async def api_set_credits(request: Request):
async def api_provision_guest(request: Request): async def api_provision_guest(request: Request):
"""Provision a guest account via the portal's /admin/provision-guest. """Provision a guest account via the portal's /admin/provision-guest.
The standard guest-invite form: ONE field (the guest's email). No name is The standard guest-invite form: the guest's email (required) plus an
collected and none is derived — the guest chooses their own display name OPTIONAL display name — passed through as the guest's initial display
and username during Cloudron account setup, and the invitation greets name; when empty, nothing is derived (the guest chooses their own name
neutrally. The portal records the co-op's ADMIN account as the inviter — at Cloudron setup and the invitation greets neutrally). The portal
admins are not bound by the member's one-per-30-days cap, and the records the co-op's ADMIN account as the inviter — admins are not bound
recipient-side guards (one guest per recipient ever, no existing portal by the member's one-per-30-days cap, and the recipient-side guards (one
row) still run there. A refusal is surfaced to the operator as-is. guest per recipient ever, no existing portal row) still run there. A
refusal is surfaced to the operator as-is.
""" """
if not is_admin(request): if not is_admin(request):
return JSONResponse({"error": "forbidden"}, status_code=403) return JSONResponse({"error": "forbidden"}, status_code=403)
body = await request.json() body = await request.json()
email = (body.get("email") or "").strip().lower() email = (body.get("email") or "").strip().lower()
name = (body.get("name") or "").strip()
if not email or "@" not in email: if not email or "@" not in email:
return JSONResponse({"error": "A valid recipient email is required"}, status_code=400) return JSONResponse({"error": "A valid recipient email is required"}, status_code=400)
try: try:
return await portal_post("/admin/provision-guest", {"email": email}) return await portal_post("/admin/provision-guest", {"email": email, "name": name})
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)
@@ -492,6 +494,8 @@ PAGE_HTML = """<!DOCTYPE html>
<form class="guest-invite-form" id="guest-invite-form" onsubmit="sendGuestAccess(event)"> <form class="guest-invite-form" id="guest-invite-form" onsubmit="sendGuestAccess(event)">
<label class="guest-invite-label" for="guest-email">Their email</label> <label class="guest-invite-label" for="guest-email">Their email</label>
<input id="guest-email" type="email" required placeholder="friend@example.com" autocomplete="off" inputmode="email" maxlength="254" /> <input id="guest-email" type="email" required placeholder="friend@example.com" autocomplete="off" inputmode="email" maxlength="254" />
<label class="guest-invite-label" for="guest-name">Their name (optional)</label>
<input id="guest-name" type="text" maxlength="80" autocomplete="off" placeholder="Only if you know it" />
<button type="submit" class="guest-invite-btn" id="guest-send">Send invite</button> <button type="submit" class="guest-invite-btn" id="guest-send">Send invite</button>
</form> </form>
</div> </div>
@@ -1475,26 +1479,29 @@ async function addBalance(email) {
} }
// Guest action: provision a $5 guest account — the standard guest-invite form // Guest action: provision a $5 guest account — the standard guest-invite form
// (ONE field: the guest's email). The inviter is always the co-op's ADMIN // (the guest's email, required, plus an OPTIONAL display name; if left empty
// account, recorded by the portal; admins have no monthly cap. The portal // the guest sets their own at Cloudron setup and the invitation greets
// enforces the recipient-side guards (one guest per recipient ever, no // neutrally). The inviter is always the co-op's ADMIN account, recorded by
// existing portal row) and reports a clear refusal. // the portal; admins have no monthly cap. The portal enforces the
// recipient-side guards (one guest per recipient ever, no existing portal
// row) and reports a clear refusal.
async function sendGuestAccess(ev) { async function sendGuestAccess(ev) {
if (ev) ev.preventDefault(); if (ev) ev.preventDefault();
const email = ($('guest-email').value || '').trim(); const email = ($('guest-email').value || '').trim();
const name = ($('guest-name').value || '').trim();
const btn = $('guest-send'); const btn = $('guest-send');
if (!email || email.indexOf('@') < 1) { flash("Enter the guest's email", false); return; } if (!email || email.indexOf('@') < 1) { flash("Enter the guest's email", false); return; }
btn.disabled = true; btn.textContent = "Sending…"; btn.disabled = true; btn.textContent = "Sending…";
try { try {
const r = await fetch('/api/provision-guest', { 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 }) body: JSON.stringify({ email, name })
}); });
const d = await r.json().catch(() => ({})); const d = await r.json().catch(() => ({}));
if (!r.ok || d.error) { flash(d.error || ('Could not send guest access (' + r.status + ')'), false); return; } if (!r.ok || d.error) { flash(d.error || ('Could not send guest access (' + r.status + ')'), false); return; }
flash('Invite sent — ' + email + ' has $5 of credits (expires in ' + (d.expires_in_days || 60) + flash('Invite 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);
$('guest-email').value = ''; $('guest-email').value = ''; $('guest-name').value = '';
load(); load();
} catch (e) { flash('Guest access failed: ' + e.message, false); } } catch (e) { flash('Guest access failed: ' + e.message, false); }
finally { btn.disabled = false; btn.textContent = 'Send invite'; } finally { btn.disabled = false; btn.textContent = 'Send invite'; }