feat: React control panel; pending-card review workflow; auth-method audit
Frontend rewrite (frontend/, replacing backend/static/): - Vite + TypeScript + React 19, React Router 7, zustand, TanStack Query 5 - dev: vite proxy /api -> :9000; prod: npm run build -> dist/, served by the backend with SPA fallback - pages: Control (gun bays w/ scope+readiness-gated start/stop, relays), History (who/via/gun/when/duration/kWh audit), Cards (pending review, enrolled, rejected), Users (permission checkbox matrix) - self-contained: fonts bundled, no CDN; light/dark; reduced-motion safe Backend: - learn mode removed: unknown cards are always refused and queued in pending_cards; admin approves (name + owner + gun restrictions in one step) or rejects (denied_cards, silent, un-rejectable); pending count rides /api/status as the notification signal - sessions record the auth method (card tap vs in-app button) for audit - GET /api/permissions: grantable-permission catalog driving the UI matrix - SPA static serving with path-traversal guard; 503 hint when not built Smoke test: 54 checks incl. approve/reject round-trips over a fake charge point and method audit assertions.
This commit is contained in:
+10
-2
@@ -7,13 +7,19 @@ semantics. A legacy config.json (pre-2026-07-11 layout) is imported into the
|
||||
database once on startup and renamed to config.json.migrated.
|
||||
|
||||
Sections:
|
||||
learn_mode accept-and-record unknown idTags vs enforce the allowlist
|
||||
users name -> {"password": pbkdf2 hash, "scopes": [...], "id_tag"}
|
||||
authorized idTag -> {"name", "kind": "card|app|car",
|
||||
optional "user": owner, "guns": ["eu092025:2"]}
|
||||
pending_cards unknown idTags tapped on a charger, awaiting the admin's
|
||||
approve (-> authorized, linked to a user) or reject decision;
|
||||
idTag -> {"first_seen", "last_seen", "count", "cp", "connector"}
|
||||
denied_cards rejected idTags; silently refused, never re-pend
|
||||
relays name -> {"id", "key", "ip", "version", "switch", "label"}
|
||||
chargers cp_id -> {"label", "guns": {"1": "display name"}} (UI only)
|
||||
session_secret signs login sessions; auto-generated once
|
||||
|
||||
There is no learn mode anymore: an unknown card is ALWAYS refused, but lands
|
||||
in pending_cards for the admin to approve or reject from the panel.
|
||||
"""
|
||||
|
||||
import json
|
||||
@@ -29,9 +35,10 @@ LEGACY_CONFIG = HERE / "config.json"
|
||||
log = logging.getLogger("config")
|
||||
|
||||
DEFAULTS = {
|
||||
"learn_mode": True,
|
||||
"users": {},
|
||||
"authorized": {},
|
||||
"pending_cards": {},
|
||||
"denied_cards": {},
|
||||
"relays": {},
|
||||
"chargers": {},
|
||||
}
|
||||
@@ -46,6 +53,7 @@ def _load() -> dict:
|
||||
"config.json.migrated)", store.DB_PATH.name)
|
||||
for key, default in DEFAULTS.items():
|
||||
cfg.setdefault(key, default if not isinstance(default, dict) else dict(default))
|
||||
cfg.pop("learn_mode", None) # superseded by the pending-cards workflow
|
||||
if not cfg.get("session_secret"):
|
||||
cfg["session_secret"] = secrets.token_hex(32)
|
||||
return cfg
|
||||
|
||||
Reference in New Issue
Block a user