feat: private session history, own-permissions view, plug-gated start button

- non-admins now see ONLY their own sessions in /api/sessions (own app
  starts + own linked cards); gun scopes grant control, not visibility;
  admins see everything
- Account page shows the logged-in user's permissions in plain words
  (Administrator badge, or the guns/relays they control), built solely
  from data already visible to them
- Start button arms only when the gun reports Preparing (cable in the
  car); idle unplugged gun shows an explanatory hint instead
- keep owner's app rename to 'Art IoT'
- smoke test: 59 checks (gun-scoped user sees no foreign sessions)
This commit is contained in:
2026-07-12 09:04:06 +02:00
parent 3387f8689e
commit 069d544bb5
12 changed files with 98 additions and 17 deletions
+8 -3
View File
@@ -1,4 +1,6 @@
import { isAdmin } from "../api";
import { useSessions, useStatus } from "../queries";
import { useApp } from "../store";
import type { Session } from "../types";
const fmtKwh = (wh: number | null) => (wh == null ? "—" : (wh / 1000).toFixed(2));
@@ -23,6 +25,8 @@ function gunLabel(s: Session, chargers: Record<string, { label?: string; guns?:
}
export default function History() {
const me = useApp((s) => s.me)!;
const admin = isAdmin(me.scopes);
const { data: sessions, isLoading } = useSessions();
const { data: status } = useStatus();
@@ -30,8 +34,9 @@ export default function History() {
if (!sessions?.length)
return (
<p className="empty">
No charging sessions yet. The first card tap or in-app start will appear here with who,
when, how, and how many kWh.
{admin
? "No charging sessions yet. The first card tap or in-app start will appear here with who, when, how, and how many kWh."
: "No charging sessions of yours yet. Sessions you start — by card or in-app — appear here."}
</p>
);
@@ -40,7 +45,7 @@ export default function History() {
return (
<section className="panel">
<header className="panel__head">
<h2>Charging sessions</h2>
<h2>{admin ? "All charging sessions" : "Your charging sessions"}</h2>
<span className="panel__meta">
{sessions.length} session{sessions.length === 1 ? "" : "s"} ·{" "}
<strong className="mono">{totalKwh.toFixed(1)} kWh</strong> total