feat(backend): link cards to users; charger-qualified gun restrictions; config-driven gun labels
- Allowlist entries take "user": <username> — sessions started with that card attribute to the person, and the owner sees their card's history even without gun-wide permissions (ownership looked up live) - "guns": ["eu092025:2"] (fnmatch) replaces the charger-blind "connectors": [2] restriction — safe with multiple chargers - New "chargers" config section provides per-charger/per-gun display names; the panel no longer hardcodes the Anfu gun labels - Panel admin tab: owner dropdown + guns field on card entries - Smoke test: 42 checks, incl. retroactive history visibility after linking a card and rejection of links to unknown users
This commit is contained in:
+19
-12
@@ -143,22 +143,23 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<h2>Allowlist</h2>
|
||||
<h2>Cards & tags</h2>
|
||||
<div class="scroll"><table>
|
||||
<thead><tr><th>idTag</th><th>Name</th><th>Guns</th><th></th></tr></thead>
|
||||
<thead><tr><th>idTag</th><th>Name</th><th>User</th><th>Guns</th><th></th></tr></thead>
|
||||
<tbody id="allowlist"></tbody>
|
||||
</table></div>
|
||||
<div id="seen-tags"></div>
|
||||
<form onsubmit="return addAllowlist(event)" style="margin-top:10px">
|
||||
<div class="row"><input id="a-tag" placeholder="idTag" required></div>
|
||||
<div class="row">
|
||||
<input id="a-name" placeholder="Name (e.g. RFID card C)" required>
|
||||
<input id="a-name" placeholder="Name (e.g. Card blue)" required>
|
||||
<select id="a-kind" style="width:110px"><option>card</option><option>app</option><option>car</option></select>
|
||||
</div>
|
||||
<div class="row">
|
||||
<input id="a-conn" placeholder="Guns, e.g. 1,2 — empty = all">
|
||||
<button class="small">Add</button>
|
||||
<select id="a-user"><option value="">No user linked</option></select>
|
||||
<input id="a-guns" placeholder="Guns, e.g. eu092025:2 — empty = all">
|
||||
</div>
|
||||
<div class="row"><button class="small">Save card</button></div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="card">
|
||||
@@ -308,8 +309,10 @@ function renderGuns() {
|
||||
.sort((a, b) => a.conn - b.conn);
|
||||
if (!conns.length)
|
||||
html += `<div class="card"><div class="sub">${esc(cp)} connected — no gun status yet</div></div>`;
|
||||
const cpCfg = (status.chargers || {})[cp] || {};
|
||||
for (const { conn, st } of conns) {
|
||||
const gunName = conn === 1 ? "Gun 1 · EU (CCS)" : conn === 2 ? "Gun 2 · GB/T" : `Gun ${conn}`;
|
||||
let gunName = (cpCfg.guns || {})[conn] || `Gun ${conn}`;
|
||||
if (cps.length > 1) gunName = `${cpCfg.label || cp} · ${gunName}`;
|
||||
const active = txByGun[`${cp}/${conn}`];
|
||||
const may = scopeOk(`charger:${cp}:${conn}`);
|
||||
const canStart = may && !active && (st === "Preparing" || st === "Available");
|
||||
@@ -408,22 +411,24 @@ async function loadSessions() {
|
||||
// ---- admin tab ----
|
||||
async function loadAdmin() {
|
||||
try {
|
||||
const al = await api("/allowlist");
|
||||
const [al, users] = await Promise.all([api("/allowlist"), api("/users")]);
|
||||
$("mode-label").textContent = al.learn_mode ? "Learn mode" : "Enforcing allowlist";
|
||||
$("mode-btn").textContent = al.learn_mode ? "Enforce" : "Back to learn";
|
||||
$("mode-btn").dataset.learn = al.learn_mode;
|
||||
$("allowlist").innerHTML = Object.entries(al.authorized).map(([tag, e]) => `<tr>
|
||||
<td class="sub">${esc(tag)}</td><td>${esc(e.name)}</td>
|
||||
<td>${e.connectors ? e.connectors.join(",") : "all"}</td>
|
||||
<td>${e.user ? esc(e.user) : '<span class="sub">—</span>'}</td>
|
||||
<td class="sub">${e.guns ? esc(e.guns.join(", ")) : "all"}</td>
|
||||
<td><button class="danger small" onclick="delAllowlist('${esc(tag)}')">✕</button></td>
|
||||
</tr>`).join("");
|
||||
$("a-user").innerHTML = `<option value="">No user linked</option>` +
|
||||
users.map(u => `<option value="${esc(u.name)}">${esc(u.name)}</option>`).join("");
|
||||
const seen = Object.entries(al.seen || {}).filter(([tag]) => !(tag in al.authorized));
|
||||
$("seen-tags").innerHTML = seen.length
|
||||
? `<div class="sub" style="margin-top:8px">Seen but not enrolled:</div>` + seen.map(([tag, s]) =>
|
||||
`<div class="row" style="padding:4px 0"><div class="grow sub">${esc(tag)} (×${s.count})</div>
|
||||
<button class="small secondary" onclick="$('a-tag').value='${esc(tag)}';$('a-name').focus()">Enroll</button></div>`).join("")
|
||||
: "";
|
||||
const users = await api("/users");
|
||||
$("users").innerHTML = users.map(u => `<tr>
|
||||
<td>${esc(u.name)}</td><td class="sub">${esc(u.scopes.join(" "))}</td>
|
||||
<td><button class="danger small" onclick="delUser('${esc(u.name)}')">✕</button></td>
|
||||
@@ -441,12 +446,14 @@ async function toggleMode() {
|
||||
async function addAllowlist(ev) {
|
||||
ev.preventDefault();
|
||||
const body = { name: $("a-name").value.trim(), kind: $("a-kind").value };
|
||||
const conns = $("a-conn").value.trim();
|
||||
if (conns) body.connectors = conns.split(",").map(s => +s.trim()).filter(Boolean);
|
||||
if ($("a-user").value) body.user = $("a-user").value;
|
||||
const guns = $("a-guns").value.trim();
|
||||
if (guns) body.guns = guns.split(",").map(s => s.trim()).filter(Boolean);
|
||||
try {
|
||||
await api(`/allowlist/${encodeURIComponent($("a-tag").value.trim())}`,
|
||||
{ method: "PUT", body: JSON.stringify(body) });
|
||||
$("a-tag").value = $("a-name").value = $("a-conn").value = "";
|
||||
$("a-tag").value = $("a-name").value = $("a-guns").value = "";
|
||||
$("a-user").value = "";
|
||||
loadAdmin();
|
||||
} catch (e) { toast(e.message); }
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user