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
+1 -1
View File
@@ -6,7 +6,7 @@
<meta name="theme-color" content="#171d1b" />
<link rel="icon" href="/icon.svg" type="image/svg+xml" />
<link rel="manifest" href="/manifest.json" />
<title>Charge Control</title>
<title>Art IoT</title>
</head>
<body>
<div id="root"></div>
+1 -1
View File
@@ -1,5 +1,5 @@
{
"name": "Charge Control",
"name": "Art IoT",
"short_name": "Charge",
"description": "Home EV charger and relay control",
"start_url": "/",
+1 -1
View File
@@ -32,7 +32,7 @@ export default function Layout() {
<path d="M55 12 L28 56 L46 56 L41 88 L72 42 L52 42 Z" />
</svg>
<div>
<span className="brand__name">Charge Control</span>
<span className="brand__name">Art IoT</span>
<span className="brand__sub">private CSMS</span>
</div>
</div>
+63 -1
View File
@@ -1,7 +1,66 @@
import { FormEvent, useState } from "react";
import { api } from "../api";
import { api, isAdmin, scopeAllowed } from "../api";
import { useStatus } from "../queries";
import { useApp } from "../store";
/** The logged-in user's own permissions, in plain words. Built purely from
* data this user may already see (status carries charger gun labels for
* everyone, and only the relays they control). */
function MyPermissions() {
const me = useApp((s) => s.me)!;
const { data: status } = useStatus();
if (isAdmin(me.scopes)) {
return (
<section className="panel" style={{ maxWidth: 440 }}>
<header className="panel__head">
<h2>Your permissions</h2>
</header>
<span className="chip chip--card">Administrator</span>
<p className="dim" style={{ marginTop: 8, fontSize: 14 }}>
Full access: both guns, all relays, cards, users and history of everyone.
</p>
</section>
);
}
const guns: string[] = [];
for (const [cp, meta] of Object.entries(status?.chargers ?? {}))
for (const [conn, label] of Object.entries(meta.guns ?? {}))
if (scopeAllowed(me.scopes, `charger:${cp}:${conn}`))
guns.push(`${meta.label ?? cp} — ${label}`);
const relays = Object.values(status?.relays ?? {}).map((r) => r.label);
return (
<section className="panel" style={{ maxWidth: 440 }}>
<header className="panel__head">
<h2>Your permissions</h2>
</header>
{guns.length + relays.length === 0 ? (
<p className="dim" style={{ fontSize: 14 }}>
No device permissions yet — ask an admin to grant you a gun or a relay.
</p>
) : (
<ul className="permlist">
{guns.map((g) => (
<li key={g}>
<span className="chip chip--plugged">Gun</span> {g}
</li>
))}
{relays.map((r) => (
<li key={r}>
<span className="chip chip--app">Relay</span> {r}
</li>
))}
</ul>
)}
<p className="dim" style={{ marginTop: 8, fontSize: 13 }}>
History shows only your own charging sessions.
</p>
</section>
);
}
export default function Account() {
const me = useApp((s) => s.me)!;
const toast = useApp((s) => s.toast);
@@ -31,6 +90,8 @@ export default function Account() {
}
return (
<>
<MyPermissions />
<section className="panel" style={{ maxWidth: 440 }}>
<header className="panel__head">
<h2>Account</h2>
@@ -75,5 +136,6 @@ export default function Account() {
</div>
</form>
</section>
</>
);
}
+6 -1
View File
@@ -93,7 +93,9 @@ function gunState(gun: Gun): { label: string; cls: string } {
function GunBay({ gun, scopes }: { gun: Gun; scopes: string[] }) {
const toast = useApp((s) => s.toast);
const may = scopeAllowed(scopes, `charger:${gun.cp}:${gun.connector}`);
const ready = !gun.tx && (gun.ocppStatus === "Preparing" || gun.ocppStatus === "Available");
// Start arms ONLY with a cable in the car (Preparing / pulsing blue) —
// an idle, unplugged gun keeps the button disabled (owner, 2026-07-12)
const ready = !gun.tx && gun.ocppStatus === "Preparing";
const start = useAction(
() =>
@@ -160,6 +162,9 @@ function GunBay({ gun, scopes }: { gun: Gun; scopes: string[] }) {
</button>
)}
{!may && <span className="bay__hint">no permission for this gun</span>}
{may && !gun.tx && !ready && gun.ocppStatus === "Available" && (
<span className="bay__hint">plug the cable into the car to enable</span>
)}
</footer>
</article>
);
+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
+1 -1
View File
@@ -31,7 +31,7 @@ export default function Login() {
<svg viewBox="0 0 100 100" className="login__mark" aria-hidden>
<path d="M55 12 L28 56 L46 56 L41 88 L72 42 L52 42 Z" />
</svg>
<h1>Charge Control</h1>
<h1>Art IoT</h1>
<p>Private charging backend — sign in to operate.</p>
</div>
<label className="field">
+4 -1
View File
@@ -1,5 +1,5 @@
/* ============================================================
Charge Control — instrument-panel design system
Art IoT — instrument-panel design system
Surfaces like enameled switchgear, copper-busbar accent,
indicator lamps as the signature element.
Type: Archivo (UI) + IBM Plex Mono (telemetry & identifiers).
@@ -335,6 +335,9 @@ button, input, select { font: inherit; color: inherit; }
.cardform__actions { display: flex; gap: 10px; }
.gunpicker, .matrix { display: flex; flex-direction: column; gap: 6px; }
.permlist { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.permlist li { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.matrix__group { margin-top: 8px; }
/* ---------- tables & lists ---------- */