Remove one retired device pairing and its owned history from the device detail

This commit is contained in:
2026-11-18 11:03:55 +01:00
parent 374b7e42d6
commit 07154833b3
9 changed files with 396 additions and 21 deletions
+4 -3
View File
@@ -45,11 +45,12 @@ export function page(value: unknown): Page {
return { items: r.items.map(v => record(v)), next_cursor: r.next_cursor, completeness: stringField(r, 'completeness'), truncated: r.truncated !== false, as_of: stringField(r, 'as_of') };
}
export class ApiError extends Error { constructor(public status: number, public code: string, message: string, public correlation: string) { super(`${code}: ${message}${correlation ? ` (Korrelation ${correlation})` : ''}`); } }
export async function request(path: string, options: { body?: unknown; csrf?: string; signal?: AbortSignal; method?: 'PATCH'; tenantId?: string } = {}): Promise<unknown> {
export async function request(path: string, options: { body?: unknown; csrf?: string; signal?: AbortSignal; method?: 'PATCH' | 'DELETE'; tenantId?: string } = {}): Promise<unknown> {
if (!path.startsWith('/') || path.startsWith('//')) throw new Error('Nur gleiche Origin erlaubt');
const changing = options.body !== undefined;
const hasBody = options.body !== undefined;
const changing = hasBody || options.method !== undefined;
const response = await fetch(path, { method: options.method ?? (changing ? 'POST' : 'GET'), credentials: 'same-origin', cache: 'no-store', signal: options.signal,
headers: { ...(changing ? { 'Content-Type': 'application/json' } : {}), ...(changing && options.csrf ? { 'X-CSRF-Token': options.csrf } : {}), ...(options.tenantId ? { 'X-RMM-Tenant': options.tenantId } : {}) }, body: changing ? JSON.stringify(options.body) : undefined });
headers: { ...(hasBody ? { 'Content-Type': 'application/json' } : {}), ...(changing && options.csrf ? { 'X-CSRF-Token': options.csrf } : {}), ...(options.tenantId ? { 'X-RMM-Tenant': options.tenantId } : {}) }, body: hasBody ? JSON.stringify(options.body) : undefined });
const raw: unknown = response.status === 204 ? {} : await response.json().catch(() => { throw new ApiError(response.status, 'HTTP_ERROR', 'keine JSON-Antwort', ''); });
if (!response.ok) { const r = record(raw); throw new ApiError(response.status, stringField(r, 'code'), stringField(r, 'message'), typeof r.correlation_id === 'string' ? r.correlation_id : ''); }
return raw;
+55 -10
View File
@@ -1,5 +1,6 @@
import { useEffect, useState } from 'react';
import {
ApiError,
objectId,
page,
pretty,
@@ -129,7 +130,7 @@ function DeviceDetail({
auth: Session;
back: () => void;
openOperation: (id: string, jobId: string) => void;
changed: () => void;
changed: (notice?: string) => void;
}) {
const path = devicePath(customer, asset);
const detail = useResource(
@@ -143,6 +144,8 @@ function DeviceDetail({
);
const [busy, setBusy] = useState(false),
[error, setError] = useState<string | null>(null);
const [confirmDelete, setConfirmDelete] = useState(false);
const [managing, setManaging] = useState(false);
const d = detail.data;
const scoped = membership.data;
const volumes = Array.isArray(d?.volumes) ? d.volumes.map((v) => record(v)) : [];
@@ -162,7 +165,7 @@ function DeviceDetail({
<button className="quiet" onClick={back}>
<NavIcon name="zurueck" /> Zur Geräteliste
</button>
<ErrorBox error={detail.error ?? membership.error ?? error} />
<ErrorBox error={detail.error ?? membership.error} />
{!d && !detail.error && <p>Inventar wird geladen …</p>}
{d && (
<>
@@ -238,9 +241,11 @@ function DeviceDetail({
<CatalogCheckNotice device={d} />
<pre aria-label="Vollständiges Geräteinventar">{pretty(d)}</pre>
</details>
{scoped && allowed(scoped, 'devices:revoke') && (
<details>
{scoped && allowed(scoped, 'devices:revoke') &&
d.tenant_id === customer && d.asset_id === asset && d.agent_id === agent && (
<details open={managing} onToggle={e => setManaging(e.currentTarget.open)}>
<summary>Gerät verwalten</summary>
<ErrorBox error={error} />
{['archived', 'current'].includes(String(d.lifecycle)) && (
<button
disabled={busy}
@@ -265,16 +270,52 @@ function DeviceDetail({
: 'In die Historie verschieben'}
</button>
)}
{d.lifecycle === 'current' && (
{d.lifecycle !== 'revoked' && (
<AdminControl
auth={scoped}
path={path + '/revocation'}
path={path + '/revocation?agent_id=' + encodeURIComponent(agent)}
permission="devices:revoke"
title="Geräteidentität widerrufen"
warning="Der Widerruf unterbricht die Geräteverwaltung und sperrt neue Starts. Die Wiederaufnahme erfordert eine neue Registrierung."
done={changed}
warning="Der Widerruf unterbricht die Geräteverwaltung und sperrt neue Starts. Danach können Sie diese Kopplung endgültig löschen. Eine Wiederaufnahme erfordert eine neue Registrierung."
done={detail.reload}
/>
)}
{d.lifecycle === 'revoked' && (confirmDelete ? (
<div>
<p className="warning">
Die Kopplung von <strong>{label(d.hostname)}</strong> bei <strong>{label(d.customer_name)}</strong>
{' '}wird mit ihrem Inventar und ihren Geräteergebnissen dauerhaft gelöscht.
Andere Installationen bleiben erhalten.
</p>
<p>Kopplungs-ID <code>{agent}</code></p>
<button className="danger" disabled={busy} onClick={async () => {
setBusy(true);
setError(null);
try {
await request(path + '?agent_id=' + encodeURIComponent(agent), {
method: 'DELETE', csrf: scoped.csrf_token, tenantId: customer
});
changed(`Kopplung von „${label(d.hostname)}“ bei „${label(d.customer_name)}“ gelöscht.`);
} catch (e) {
if (e instanceof ApiError && e.code === 'DEVICE_HAS_OPEN_WORK') {
setError('Für diese Kopplung gibt es offene Aufträge oder Genehmigungen. Prüfen Sie diese vor dem Löschen.');
} else if (e instanceof ApiError && e.code === 'DEVICE_REVOCATION_REQUIRED') {
setError('Widerrufen Sie diese Geräteidentität vor dem Löschen.');
} else {
setError(errorText(e));
}
} finally {
setBusy(false);
}
}}>Endgültig löschen</button>
<button className="quiet" disabled={busy} onClick={() => {
setConfirmDelete(false);
setError(null);
}}>Abbrechen</button>
</div>
) : (
<button className="danger" onClick={() => setConfirmDelete(true)}>Kopplung löschen</button>
))}
</details>
)}
</section>
@@ -313,6 +354,7 @@ export function Devices({
[query, setQuery] = useState(''),
[status, setStatus] = useState(''),
[history, setHistory] = useState(false);
const [deletionNotice, setDeletionNotice] = useState('');
const [trail, setTrail] = useState<{ filter: string; routes: string[] }>({ filter, routes: [] });
const routes = trail.filter === filter ? trail.routes : [];
function setRoutes(next: string[] | ((old: string[]) => string[])) {
@@ -361,12 +403,13 @@ export function Devices({
if (target)
return (
<DeviceDetail
key={target.agent}
key={detailPath}
{...target}
auth={auth}
back={back}
openOperation={(id, jobId) => onOperation(target.customer, id, jobId)}
changed={() => {
changed={(notice) => {
setDeletionNotice(notice ?? '');
back();
setRoutes([]);
onSelection({ customer: '', ids: [] });
@@ -386,6 +429,7 @@ export function Devices({
</button>
)}
</div>
{deletionNotice && <p role="status">{deletionNotice}</p>}
<section className="fleet" aria-label="Gerätebestand">
<div className="fleet-tabs">
<button
@@ -487,6 +531,7 @@ export function Devices({
customer = objectId(d, 'tenant'),
model = cpu(d);
const show = () => {
setDeletionNotice('');
window.location.hash = ['geraete', customer, asset, agent]
.map(encodeURIComponent)
.join('/');