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:
+28
-11
@@ -27,8 +27,8 @@ from ocpp.v16.enums import (
|
||||
)
|
||||
|
||||
from . import store
|
||||
from .config import CONFIG, HERE
|
||||
from .journal import now, record_event, record_seen
|
||||
from .config import CONFIG, HERE, save
|
||||
from .journal import now, record_event
|
||||
|
||||
log = logging.getLogger("csms")
|
||||
|
||||
@@ -47,6 +47,16 @@ TRIGGERABLE = {
|
||||
}
|
||||
|
||||
|
||||
def _record_pending(id_tag: str, cp: Optional[str], connector: Optional[int]) -> None:
|
||||
"""An unknown card was tapped: queue it for the admin to approve or reject."""
|
||||
entry = CONFIG["pending_cards"].get(
|
||||
id_tag, {"first_seen": now(), "count": 0}
|
||||
)
|
||||
entry.update(last_seen=now(), count=entry["count"] + 1, cp=cp, connector=connector)
|
||||
CONFIG["pending_cards"][id_tag] = entry
|
||||
save()
|
||||
|
||||
|
||||
def decide(id_tag: str, context: str, connector: Optional[int] = None,
|
||||
cp: Optional[str] = None) -> AuthorizationStatus:
|
||||
"""The one gate every auth method flows through: is this idTag allowed?
|
||||
@@ -57,6 +67,9 @@ def decide(id_tag: str, context: str, connector: Optional[int] = None,
|
||||
fires there; a plain Authorize (card tap) still accepts a known card —
|
||||
which matches this charger, since AuthorizeRemoteTxRequests=false means
|
||||
StartTransaction is the decisive call anyway.
|
||||
|
||||
Unknown idTags are always refused: silently if the admin already rejected
|
||||
the card, otherwise they land in pending_cards for the admin to decide.
|
||||
"""
|
||||
entry = CONFIG["authorized"].get(id_tag)
|
||||
known = entry is not None
|
||||
@@ -70,13 +83,13 @@ def decide(id_tag: str, context: str, connector: Optional[int] = None,
|
||||
name = entry.get("name", "?")
|
||||
log.info("[OK] AUTHORIZED idTag=%r (%s) via %s", id_tag, name, context)
|
||||
status = AuthorizationStatus.accepted
|
||||
elif CONFIG.get("learn_mode"):
|
||||
log.warning("[LEARN] NEW idTag=%r via %s -> accepting & recording.", id_tag, context)
|
||||
record_seen(id_tag, context)
|
||||
status = AuthorizationStatus.accepted
|
||||
elif id_tag in CONFIG["denied_cards"]:
|
||||
log.warning("[NO] DENIED idTag=%r (admin-rejected card) via %s", id_tag, context)
|
||||
status = AuthorizationStatus.invalid
|
||||
else:
|
||||
log.warning("[NO] REJECTED unknown idTag=%r via %s", id_tag, context)
|
||||
record_seen(id_tag, context)
|
||||
log.warning("[??] UNKNOWN idTag=%r via %s -> refused, queued for admin approval",
|
||||
id_tag, context)
|
||||
_record_pending(id_tag, cp, connector)
|
||||
status = AuthorizationStatus.invalid
|
||||
AUTH_EVENTS.append(
|
||||
{"time": now(), "id_tag": id_tag, "context": context,
|
||||
@@ -126,7 +139,7 @@ class ChargePoint(OcppChargePoint):
|
||||
|
||||
@on(Action.authorize)
|
||||
async def on_authorize(self, id_tag, **kwargs):
|
||||
status = decide(id_tag, "Authorize (card/app)")
|
||||
status = decide(id_tag, "Authorize (card/app)", cp=self.id)
|
||||
record_event("Authorize", self.id, id_tag=id_tag, result=status.value)
|
||||
return call_result.Authorize(id_tag_info={"status": status})
|
||||
|
||||
@@ -138,12 +151,16 @@ class ChargePoint(OcppChargePoint):
|
||||
_tx_counter["n"] += 1
|
||||
tx = _tx_counter["n"]
|
||||
who = resolve_who(id_tag)
|
||||
# audit: HOW was this session authorized? kind of the allowlist
|
||||
# entry -> "card" (physical tap) or "app" (in-app button press)
|
||||
method = CONFIG["authorized"].get(id_tag, {}).get("kind", "unknown")
|
||||
ACTIVE_TX[tx] = {
|
||||
"cp": self.id, "connector": connector_id, "id_tag": id_tag,
|
||||
"who": who, "meter_start": meter_start, "started": now(),
|
||||
"who": who, "method": method,
|
||||
"meter_start": meter_start, "started": now(),
|
||||
}
|
||||
store.start_session(tx, self.id, connector_id, id_tag, who,
|
||||
timestamp, meter_start)
|
||||
timestamp, meter_start, method=method)
|
||||
log.info("Transaction %s STARTED on connector %s by %s (meter_start=%s)",
|
||||
tx, connector_id, who, meter_start)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user