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,12 +10,13 @@ The three planned ways to authorize a charging session. Architecturally they all
|
||||
|
||||
## 1. RFID cards — ✅ verified live (2026-07-09)
|
||||
|
||||
First card tapped on the real charger: idTag `1000000000000393` → Authorize → StartTransaction on gun 2 → **actual charging session started** (tx 1, meter_start 3,513.857 kWh). Enrolled as "RFID card A". Second card captured the same session: `1000000000000395` → "RFID card B". The ids are sequential — the cards ship as a numbered batch. Remaining: tap any further cards, then set `learn_mode=false` to enforce.
|
||||
First card tapped on the real charger: idTag `1000000000000393` → Authorize → StartTransaction on gun 2 → **actual charging session started** (tx 1, meter_start 3,513.857 kWh). Enrolled as "RFID card A". Second card captured the same session: `1000000000000395` → "RFID card B". The ids are sequential — the cards ship as a numbered batch.
|
||||
|
||||
> [!warning] Session restarted after remote stop (❓ verify mechanism)
|
||||
> ~65 s after a RemoteStop on gun 2 (cable left plugged), a **new** transaction began with the same card id. Either the owner re-tapped, or the charger auto-restarts from its authorization cache (`AuthorizationCacheEnabled=true`). Matters for app UX: "stop" may not stick while the cable stays in. Test: remote-stop and touch nothing for 5 min.
|
||||
|
||||
Flow for each new card: tap once in learn mode → harvest its idTag from `seen_tags.json` / `GET /api/allowlist` → add to `authorized` with a name (`kind: "card"`).
|
||||
> [!warning] Superseded (2026-07-11): learn mode removed — replaced by the **pending-card review workflow**
|
||||
> An unknown card is now ALWAYS refused, but lands in `pending_cards`. The admin gets a notification (banner + badge in the [[frontend|panel]]) and decides: **approve** (name it, link it to a user, optionally restrict guns — one step) or **reject** (goes to `denied_cards`, silently refused, never re-pends; un-rejectable). New-card flow: tap once on the charger → review in the panel’s Cards page. ✅ smoke-verified: unknown tap → Invalid + pending; approved card authorizes on next tap; rejected card stays silent.
|
||||
|
||||
Since 2026-07-11 a card can be **linked to a user and restricted per gun**:
|
||||
|
||||
@@ -64,13 +65,18 @@ The [[backend]] now has real multi-user authorization on top of the three method
|
||||
| `charger:eu092025:1` | start/stop/unlock gun 1 |
|
||||
| `charger:eu092025:2` | same for gun 2 |
|
||||
| `relay:<name>` / `relay:*` | switch those relays (others are invisible to the user) |
|
||||
| `admin` | everything, incl. allowlist/user CRUD, learn-mode flip, setconfig, events |
|
||||
| `admin` | everything, incl. cards (pending review, allowlist), user CRUD, relay/charger registry, setconfig, events |
|
||||
|
||||
- **Bootstrap**: zero users = open API (startup warns loudly). First user: `venv\Scripts\python -m backend.users add <name> --scopes admin`.
|
||||
- ✅ Verified by the 45-check smoke test (login, wrong password, cookie + bearer, per-scope 403s, relay visibility filtering, user CRUD, session invalidation on delete). ⚠️ Not yet exercised from a real phone browser.
|
||||
- Admins grant permissions in the panel’s Users page as a **checkbox matrix** (per gun, per relay, admin) rendered from `GET /api/permissions` — nobody types raw scope strings.
|
||||
- ✅ Verified by the 54-check smoke test (login, wrong password, cookie + bearer, per-scope 403s, relay visibility filtering, user CRUD, session invalidation on delete). ⚠️ Not yet exercised from a real phone browser.
|
||||
|
||||
This resolves the ❓ "web app auth" open decision in [[overview]]: username+password with per-resource scopes, chosen over plain tokens by the owner.
|
||||
|
||||
## Audit: who charged, and how
|
||||
|
||||
Every session row records the **method**: `card` (physical RFID tap) or `app` (in-app button press), derived from the allowlist entry’s kind at StartTransaction, plus the resolved **who** (card owner / username). The panel’s History tab shows Who · Via · Gun · When · Duration · kWh. (2026-07-11, owner requirement.)
|
||||
|
||||
## Facts from the live probe that shape this design
|
||||
|
||||
Per [[2026-07-09-discovery-eu092025]]: `AuthorizeRemoteTxRequests=false`, so remote starts don't trigger a separate Authorize — the `decide()` gate fires when the charger sends `StartTransaction`. The on-charger offline allowlist (`LocalAuthList`) holds max **6 idTags** and is currently disabled; enough for a household if we ever want tap-to-charge to survive CSMS downtime.
|
||||
|
||||
Reference in New Issue
Block a user