Restrict admin to system management
This commit is contained in:
1 parent
0bef65ab75
commit
19e4621aeb
13 files changed
+634
-882
No files matched your search
+102
-60
@@ -378,13 +378,21 @@ export function App() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentUser.role === "admin") {
|
||||
setTimers([]);
|
||||
setSelectedTimerId(null);
|
||||
setTimerOwnerId(currentUser.id);
|
||||
setTimersLoaded(true);
|
||||
return;
|
||||
}
|
||||
|
||||
setTimers(readStoredTimers(currentUser.id));
|
||||
setTimerOwnerId(currentUser.id);
|
||||
setTimersLoaded(true);
|
||||
}, [currentUser]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!currentUser || !timersLoaded || timerOwnerId !== currentUser.id) {
|
||||
if (!currentUser || currentUser.role === "admin" || !timersLoaded || timerOwnerId !== currentUser.id) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -401,7 +409,7 @@ export function App() {
|
||||
}, [currentUser, timers, selectedTimerId, timersLoaded, timerOwnerId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!currentUser || !timersLoaded || timerOwnerId !== currentUser.id) {
|
||||
if (!currentUser || currentUser.role === "admin" || !timersLoaded || timerOwnerId !== currentUser.id) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -467,7 +475,26 @@ export function App() {
|
||||
return () => window.clearInterval(interval);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!currentUser || currentUser.role !== "admin") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (route.page === "admin-users" || route.page === "profile" || route.page === "faq") {
|
||||
return;
|
||||
}
|
||||
|
||||
navigate("/admin/users");
|
||||
}, [currentUser, route.page]);
|
||||
|
||||
async function startQuickTimer(rawTicketNumber: string) {
|
||||
if (currentUser?.role === "admin") {
|
||||
toast.error("Admin erfasst keine Sessions", {
|
||||
description: "Der Adminbereich ist nur für die Systemverwaltung vorgesehen."
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
const ticketNumber = rawTicketNumber.trim();
|
||||
|
||||
if (!ticketPattern.test(ticketNumber)) {
|
||||
@@ -532,21 +559,29 @@ export function App() {
|
||||
}
|
||||
|
||||
const navItems: NavMenuEntry[] = [
|
||||
{ type: "item", href: "/timer", label: "Timer", icon: Timer, active: path.startsWith("/timer") || path === "/" },
|
||||
{ type: "item", href: "/analysis", label: "Auswertung", icon: BarChart3, active: path.startsWith("/analysis") },
|
||||
{ type: "separator", key: "after-analysis" },
|
||||
{ type: "item", href: "/monthly-close", label: "Monatsabschluss", icon: ClipboardCheck, active: path.startsWith("/monthly-close") },
|
||||
{ type: "separator", key: "after-monthly-close" },
|
||||
{ type: "item", href: "/statistics", label: "Statistiken", icon: ChartNoAxesCombined, active: path.startsWith("/statistics") },
|
||||
{ type: "item", href: "/recurring", label: "Fixe Abrechnung", icon: Repeat, active: path.startsWith("/recurring") },
|
||||
{ type: "separator", key: "before-profile" },
|
||||
{ type: "item", href: "/profile", label: "Profil", icon: UserCog, active: path.startsWith("/profile") },
|
||||
...(currentUser.role === "admin"
|
||||
? [{ type: "item" as const, href: "/admin/users", label: "Benutzer", icon: Shield, active: path.startsWith("/admin/users") }]
|
||||
: []),
|
||||
{ type: "separator", key: "before-faq" },
|
||||
{ type: "item", href: "/faq", label: "FAQ", icon: CircleHelp, active: path.startsWith("/faq") },
|
||||
? [
|
||||
{ type: "item" as const, href: "/admin/users", label: "Administration", icon: Shield, active: path.startsWith("/admin/users") },
|
||||
{ type: "separator" as const, key: "before-profile" },
|
||||
{ type: "item" as const, href: "/profile", label: "Profil", icon: UserCog, active: path.startsWith("/profile") },
|
||||
{ type: "separator" as const, key: "before-faq" },
|
||||
{ type: "item" as const, href: "/faq", label: "FAQ", icon: CircleHelp, active: path.startsWith("/faq") }
|
||||
]
|
||||
: [
|
||||
{ type: "item" as const, href: "/timer", label: "Session starten", icon: Timer, active: path.startsWith("/timer") || path === "/" },
|
||||
{ type: "item" as const, href: "/analysis", label: "Auswertung", icon: BarChart3, active: path.startsWith("/analysis") },
|
||||
{ type: "separator" as const, key: "after-analysis" },
|
||||
{ type: "item" as const, href: "/monthly-close", label: "Monatsabschluss", icon: ClipboardCheck, active: path.startsWith("/monthly-close") },
|
||||
{ type: "separator" as const, key: "after-monthly-close" },
|
||||
{ type: "item" as const, href: "/statistics", label: "Statistiken", icon: ChartNoAxesCombined, active: path.startsWith("/statistics") },
|
||||
{ type: "item" as const, href: "/recurring", label: "Fixe Abrechnung", icon: Repeat, active: path.startsWith("/recurring") },
|
||||
{ type: "separator" as const, key: "before-profile" },
|
||||
{ type: "item" as const, href: "/profile", label: "Profil", icon: UserCog, active: path.startsWith("/profile") },
|
||||
{ type: "separator" as const, key: "before-faq" },
|
||||
{ type: "item" as const, href: "/faq", label: "FAQ", icon: CircleHelp, active: path.startsWith("/faq") }
|
||||
])
|
||||
];
|
||||
const isAdmin = currentUser.role === "admin";
|
||||
const runningTimer = timers.find((timer) => timer.phase === "running") ?? null;
|
||||
const runningElapsedSeconds = runningTimer ? Math.floor(activeElapsedMs(runningTimer, tick) / 1000) : 0;
|
||||
|
||||
@@ -564,7 +599,7 @@ export function App() {
|
||||
<SidebarMenu>
|
||||
<SidebarMenuItem>
|
||||
<SidebarMenuButton asChild>
|
||||
<a href="/timer" onClick={navHandler("/timer")}>
|
||||
<a href={isAdmin ? "/admin/users" : "/timer"} onClick={navHandler(isAdmin ? "/admin/users" : "/timer")}>
|
||||
<Command />
|
||||
<span className="font-semibold text-base">TicketTracker</span>
|
||||
</a>
|
||||
@@ -574,36 +609,40 @@ export function App() {
|
||||
</SidebarHeader>
|
||||
|
||||
<SidebarContent>
|
||||
<SidebarGroup>
|
||||
<SidebarGroupContent className="flex flex-col gap-2">
|
||||
<SidebarMenu>
|
||||
<SidebarMenuItem className="flex items-center gap-2">
|
||||
<SidebarMenuButton
|
||||
asChild
|
||||
tooltip="Session starten"
|
||||
className="min-w-8 bg-primary text-primary-foreground duration-200 ease-linear hover:bg-primary/90 hover:text-primary-foreground active:bg-primary/90 active:text-primary-foreground"
|
||||
>
|
||||
<a href="/timer" onClick={navHandler("/timer")}>
|
||||
<Timer />
|
||||
<span>Session starten</span>
|
||||
</a>
|
||||
</SidebarMenuButton>
|
||||
</SidebarMenuItem>
|
||||
</SidebarMenu>
|
||||
</SidebarGroupContent>
|
||||
</SidebarGroup>
|
||||
{!isAdmin ? (
|
||||
<>
|
||||
<SidebarGroup>
|
||||
<SidebarGroupContent className="flex flex-col gap-2">
|
||||
<SidebarMenu>
|
||||
<SidebarMenuItem className="flex items-center gap-2">
|
||||
<SidebarMenuButton
|
||||
asChild
|
||||
tooltip="Session starten"
|
||||
className="min-w-8 bg-primary text-primary-foreground duration-200 ease-linear hover:bg-primary/90 hover:text-primary-foreground active:bg-primary/90 active:text-primary-foreground"
|
||||
>
|
||||
<a href="/timer" onClick={navHandler("/timer")}>
|
||||
<Timer />
|
||||
<span>Session starten</span>
|
||||
</a>
|
||||
</SidebarMenuButton>
|
||||
</SidebarMenuItem>
|
||||
</SidebarMenu>
|
||||
</SidebarGroupContent>
|
||||
</SidebarGroup>
|
||||
|
||||
<SidebarTimers
|
||||
timers={timers}
|
||||
selectedTimerId={selectedTimerId}
|
||||
setSelectedTimerId={setSelectedTimerId}
|
||||
setTimers={setTimers}
|
||||
tick={tick}
|
||||
onOpenTimer={() => navigate("/timer")}
|
||||
/>
|
||||
<SidebarTimers
|
||||
timers={timers}
|
||||
selectedTimerId={selectedTimerId}
|
||||
setSelectedTimerId={setSelectedTimerId}
|
||||
setTimers={setTimers}
|
||||
tick={tick}
|
||||
onOpenTimer={() => navigate("/timer")}
|
||||
/>
|
||||
</>
|
||||
) : null}
|
||||
|
||||
<SidebarGroup>
|
||||
<SidebarGroupLabel>Workflows</SidebarGroupLabel>
|
||||
<SidebarGroupLabel>{isAdmin ? "Verwaltung" : "Workflow"}</SidebarGroupLabel>
|
||||
<SidebarGroupContent>
|
||||
<SidebarMenu>
|
||||
{navItems.map((item) =>
|
||||
@@ -629,13 +668,13 @@ export function App() {
|
||||
</SidebarContent>
|
||||
|
||||
<SidebarFooter>
|
||||
<div className="mx-2 rounded-lg border bg-card p-3 text-sm shadow-xs group-data-[collapsible=icon]:hidden">
|
||||
{!isAdmin ? <div className="mx-2 rounded-lg border bg-card p-3 text-sm shadow-xs group-data-[collapsible=icon]:hidden">
|
||||
<div className="mb-2 flex items-center gap-2 font-medium">
|
||||
<CheckCircle2 className="size-4 text-muted-foreground" />
|
||||
Abschluss
|
||||
</div>
|
||||
<p className="text-muted-foreground">Offene Bewertungen findest du im Monatsabschluss.</p>
|
||||
</div>
|
||||
</div> : null}
|
||||
<SidebarMenu>
|
||||
<SidebarMenuItem>
|
||||
<SidebarMenuButton tooltip="Worklog">
|
||||
@@ -684,11 +723,13 @@ export function App() {
|
||||
<span className="truncate text-sm font-semibold">TicketTracker</span>
|
||||
</div>
|
||||
</div>
|
||||
<QuickTimerStarter
|
||||
inputId="quick-ticket-number-desktop"
|
||||
className="mx-3 hidden max-w-md flex-1 md:flex"
|
||||
onStartTimer={startQuickTimer}
|
||||
/>
|
||||
{!isAdmin ? (
|
||||
<QuickTimerStarter
|
||||
inputId="quick-ticket-number-desktop"
|
||||
className="mx-3 hidden max-w-md flex-1 md:flex"
|
||||
onStartTimer={startQuickTimer}
|
||||
/>
|
||||
) : null}
|
||||
<div className="flex items-center gap-2">
|
||||
<ThemeSwitcher />
|
||||
<DropdownMenu>
|
||||
@@ -716,12 +757,12 @@ export function App() {
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<div className="border-b bg-background/95 px-3 py-2 md:hidden">
|
||||
{!isAdmin ? <div className="border-b bg-background/95 px-3 py-2 md:hidden">
|
||||
<QuickTimerStarter inputId="quick-ticket-number-mobile" onStartTimer={startQuickTimer} />
|
||||
</div>
|
||||
</div> : null}
|
||||
<main className="min-h-0 min-w-0 flex-1 overflow-x-hidden p-3 sm:p-4 md:p-5">
|
||||
<div className="mx-auto w-full max-w-screen-2xl">
|
||||
{route.page === "timer" ? (
|
||||
{!isAdmin && route.page === "timer" ? (
|
||||
<TimerPage
|
||||
timers={timers}
|
||||
setTimers={setTimers}
|
||||
@@ -730,14 +771,14 @@ export function App() {
|
||||
tick={tick}
|
||||
/>
|
||||
) : null}
|
||||
{route.page === "analysis" ? <AnalysisPage onNavigate={navigate} /> : null}
|
||||
{route.page === "monthly-close" ? <MonthlyClosePage onNavigate={navigate} /> : null}
|
||||
{route.page === "statistics" ? <StatisticsPage onNavigate={navigate} /> : null}
|
||||
{route.page === "recurring" ? <RecurringBillingsPage /> : null}
|
||||
{!isAdmin && route.page === "analysis" ? <AnalysisPage onNavigate={navigate} /> : null}
|
||||
{!isAdmin && route.page === "monthly-close" ? <MonthlyClosePage onNavigate={navigate} /> : null}
|
||||
{!isAdmin && route.page === "statistics" ? <StatisticsPage onNavigate={navigate} /> : null}
|
||||
{!isAdmin && route.page === "recurring" ? <RecurringBillingsPage /> : null}
|
||||
{route.page === "faq" ? <FaqPage /> : null}
|
||||
{route.page === "profile" ? <ProfilePage currentUser={currentUser} onUserUpdated={setCurrentUser} /> : null}
|
||||
{route.page === "admin-users" && currentUser.role === "admin" ? <AdminUsersPage currentUser={currentUser} /> : null}
|
||||
{route.page === "admin-users" && currentUser.role !== "admin" ? (
|
||||
{route.page === "admin-users" && isAdmin ? <AdminUsersPage currentUser={currentUser} /> : null}
|
||||
{route.page === "admin-users" && !isAdmin ? (
|
||||
<TimerPage
|
||||
timers={timers}
|
||||
setTimers={setTimers}
|
||||
@@ -746,9 +787,10 @@ export function App() {
|
||||
tick={tick}
|
||||
/>
|
||||
) : null}
|
||||
{route.page === "ticket" ? (
|
||||
{!isAdmin && route.page === "ticket" ? (
|
||||
<TicketDetailPage periodType={route.periodType} period={route.period} ticketId={route.ticketId} onNavigate={navigate} />
|
||||
) : null}
|
||||
{isAdmin && route.page !== "admin-users" && route.page !== "profile" && route.page !== "faq" ? <AdminUsersPage currentUser={currentUser} /> : null}
|
||||
</div>
|
||||
</main>
|
||||
</SidebarInset>
|
||||
|
||||
Reference in new issue
Block a user