Bug: Frontend prüfte nur istAdmin, Materialverantwortliche und Leitungs- verantwortliche sahen exakt dieselbe UI wie Mitarbeiter - obwohl das Backend längst granular unterscheidet (require_roles je Endpunkt). - AuthContext gibt volle Rollenliste + istVerantwortlich/istMaterial- verantwortlich/istLeitungsverantwortlich weiter. - /admin-Route für alle drei Rollen offen, AdminPage filtert Tabs nach Rolle (Material/Leitung: Objekte-Pflege, Kontrollverantwortung, Änderungslog; nur Administration: Stammdaten/Benutzer/Eskalation/ Zuständigkeit). - ObjektSection blendet Anlegen/Duplizieren/Kopplung für Nicht-Admins aus (waren admin-only im Backend, hätten 403 geworfen). - Promise.allSettled statt Promise.all beim Laden, damit ein admin-only Endpunkt (z.B. /benutzer) nicht die ganze Seite für niedrigere Rollen blockiert. - Backend: GET /benutzer jetzt auch für Material-/Leitungsverantwortliche lesbar (für Kontrollverantwortung-Auswahl im Frontend nötig), Schreiben bleibt admin-only. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CVgbozhYmuEhiEJHffRXCV
67 lines
1.9 KiB
TypeScript
67 lines
1.9 KiB
TypeScript
import type { ReactNode } from "react";
|
|
import { Navigate, Route, Routes } from "react-router-dom";
|
|
|
|
import { AuthProvider, useAuth } from "./auth/AuthContext";
|
|
import { AppShell } from "./components/AppShell";
|
|
import { AdminPage } from "./pages/AdminPage";
|
|
import { KontrollPage } from "./pages/KontrollPage";
|
|
import { LoginPage } from "./pages/LoginPage";
|
|
import { ObjektListPage } from "./pages/ObjektListPage";
|
|
|
|
function GeschuetzteRoute({ children }: { children: ReactNode }) {
|
|
const { eingeloggt } = useAuth();
|
|
if (!eingeloggt) {
|
|
return <Navigate to="/login" replace />;
|
|
}
|
|
return <AppShell>{children}</AppShell>;
|
|
}
|
|
|
|
function AdminRoute({ children }: { children: ReactNode }) {
|
|
const { eingeloggt, istVerantwortlich } = useAuth();
|
|
if (!eingeloggt) {
|
|
return <Navigate to="/login" replace />;
|
|
}
|
|
// Nicht mehr admin-exklusiv: Materialverantwortliche/Leitungsverantwortliche
|
|
// dürfen rein, sehen dort aber nur die für sie freigeschalteten Tabs
|
|
// (AdminPage filtert selbst nach Rolle, Backend erzwingt es ohnehin je Endpunkt).
|
|
if (!istVerantwortlich) {
|
|
return <Navigate to="/objekte" replace />;
|
|
}
|
|
return <AppShell>{children}</AppShell>;
|
|
}
|
|
|
|
export default function App() {
|
|
return (
|
|
<AuthProvider>
|
|
<Routes>
|
|
<Route path="/login" element={<LoginPage />} />
|
|
<Route
|
|
path="/objekte"
|
|
element={
|
|
<GeschuetzteRoute>
|
|
<ObjektListPage />
|
|
</GeschuetzteRoute>
|
|
}
|
|
/>
|
|
<Route
|
|
path="/objekte/:objektId/kontrolle"
|
|
element={
|
|
<GeschuetzteRoute>
|
|
<KontrollPage />
|
|
</GeschuetzteRoute>
|
|
}
|
|
/>
|
|
<Route
|
|
path="/admin"
|
|
element={
|
|
<AdminRoute>
|
|
<AdminPage />
|
|
</AdminRoute>
|
|
}
|
|
/>
|
|
<Route path="*" element={<Navigate to="/objekte" replace />} />
|
|
</Routes>
|
|
</AuthProvider>
|
|
);
|
|
}
|