From 2135776343f7b146a015d0dc314c562c840a5741 Mon Sep 17 00:00:00 2001 From: Jonny Date: Mon, 2 Nov 2026 09:24:25 +0100 Subject: [PATCH] feat: Disponent und Admin stempeln sich selbst ein und aus Co-Authored-By: Claude Opus 5.5 --- web/app/zeiterfassung/actions.ts | 9 +++++---- web/app/zeiterfassung/page.tsx | 14 ++++++++------ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/web/app/zeiterfassung/actions.ts b/web/app/zeiterfassung/actions.ts index a345923..74d03c5 100644 --- a/web/app/zeiterfassung/actions.ts +++ b/web/app/zeiterfassung/actions.ts @@ -2,6 +2,7 @@ import { createClient } from "@/lib/supabase/server"; import { loadProfile } from "@/lib/auth/profile"; +import { istEinsatzrolle } from "@/lib/auth/roles"; import { validateSchichtKorrektur } from "@/lib/zeiterfassung/validate-korrektur"; import { findeOffeneSchicht, listSchichten } from "@/lib/zeiterfassung/queries"; import { pauseMinuten, nettoMinuten } from "@/lib/zeiterfassung/zeit-berechnung"; @@ -11,8 +12,8 @@ export type MutationResult = { success: true } | { success: false; error: string export async function kommen(): Promise { const profileResult = await loadProfile(); - if (profileResult.status !== "ok" || profileResult.profile.role !== "fahrer") { - return { success: false, error: "Nur Fahrer koennen sich einstempeln." }; + if (profileResult.status !== "ok" || !istEinsatzrolle(profileResult.profile.role)) { + return { success: false, error: "Diese Rolle kann sich nicht einstempeln." }; } const offeneSchicht = await findeOffeneSchicht(profileResult.profile.id); @@ -34,8 +35,8 @@ export async function kommen(): Promise { export async function gehen(schichtId: string): Promise { const profileResult = await loadProfile(); - if (profileResult.status !== "ok" || profileResult.profile.role !== "fahrer") { - return { success: false, error: "Nur Fahrer koennen sich ausstempeln." }; + if (profileResult.status !== "ok" || !istEinsatzrolle(profileResult.profile.role)) { + return { success: false, error: "Diese Rolle kann sich nicht ausstempeln." }; } const supabase = await createClient(); diff --git a/web/app/zeiterfassung/page.tsx b/web/app/zeiterfassung/page.tsx index d3d982c..347cd45 100644 --- a/web/app/zeiterfassung/page.tsx +++ b/web/app/zeiterfassung/page.tsx @@ -1,6 +1,6 @@ import { redirect } from "next/navigation"; import { loadProfile } from "@/lib/auth/profile"; -import { kannZeiterfassungNutzen, personBezeichnung } from "@/lib/auth/roles"; +import { istEinsatzrolle, kannAuftraegeVerwalten, kannZeiterfassungNutzen, personBezeichnung } from "@/lib/auth/roles"; import { listSchichten, listOffeneSchichten, @@ -41,11 +41,12 @@ export default async function ZeiterfassungPage({ const bisDatum = bis ?? heute.toISOString().slice(0, 10); const zeitraum = { von: `${vonDatum}T00:00:00.000Z`, bis: `${bisDatum}T23:59:59.999Z` }; - const istDisponentOderAdmin = profileResult.profile.role === "admin" || profileResult.profile.role === "disponent"; + const istDisponentOderAdmin = kannAuftraegeVerwalten(profileResult.profile.role); + const kannStempeln = istEinsatzrolle(profileResult.profile.role); const [schichten, offeneSchicht, fahrerListe, offeneSchichtenAlle] = await Promise.all([ listSchichten(zeitraum, istDisponentOderAdmin ? fahrer_id : profileResult.profile.id), - istDisponentOderAdmin ? Promise.resolve(null) : findeOffeneSchicht(profileResult.profile.id), + kannStempeln ? findeOffeneSchicht(profileResult.profile.id) : Promise.resolve(null), istDisponentOderAdmin ? listEinsatzPersonen().then((personen) => personen.map((p) => ({ id: p.id, name: personBezeichnung(p) }))) : Promise.resolve([]), @@ -76,8 +77,9 @@ export default async function ZeiterfassungPage({ )} - {!istDisponentOderAdmin && ( + {kannStempeln && (
+ {istDisponentOderAdmin &&

Meine Schicht

}
)} @@ -90,9 +92,9 @@ export default async function ZeiterfassungPage({ {istDisponentOderAdmin && ( - +