From 3e7391d2550b16c33208c3934e6e8967acabfa11 Mon Sep 17 00:00:00 2001 From: PxlLoewe <72106766+PxlLoewe@users.noreply.github.com> Date: Mon, 17 Mar 2025 22:07:52 -0700 Subject: [PATCH] Added admin permission check --- apps/hub/app/(app)/admin/event/layout.tsx | 20 ++++++++++++++++++++ apps/hub/app/(app)/admin/station/layout.tsx | 20 ++++++++++++++++++++ apps/hub/app/(app)/admin/user/layout.tsx | 20 ++++++++++++++++++++ apps/hub/app/_components/Error.tsx | 20 +++++++++++++++++++- packages/database/prisma/schema/user.prisma | 3 ++- 5 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 apps/hub/app/(app)/admin/event/layout.tsx create mode 100644 apps/hub/app/(app)/admin/station/layout.tsx create mode 100644 apps/hub/app/(app)/admin/user/layout.tsx diff --git a/apps/hub/app/(app)/admin/event/layout.tsx b/apps/hub/app/(app)/admin/event/layout.tsx new file mode 100644 index 00000000..2f1a30f8 --- /dev/null +++ b/apps/hub/app/(app)/admin/event/layout.tsx @@ -0,0 +1,20 @@ +import { prisma } from "@repo/db"; +import { Error } from "_components/Error"; +import { getServerSession } from "api/auth/[...nextauth]/auth"; + +export default async ({ children }: { children: React.ReactNode }) => { + const session = await getServerSession(); + + if (!session) return ; + + const user = await prisma.user.findUnique({ + where: { + id: session.user.id, + }, + }); + + if (!user?.permissions.includes("ADMIN_EVENT")) + return ; + + return <>{children}; +}; diff --git a/apps/hub/app/(app)/admin/station/layout.tsx b/apps/hub/app/(app)/admin/station/layout.tsx new file mode 100644 index 00000000..4b82ebd3 --- /dev/null +++ b/apps/hub/app/(app)/admin/station/layout.tsx @@ -0,0 +1,20 @@ +import { prisma } from "@repo/db"; +import { Error } from "_components/Error"; +import { getServerSession } from "api/auth/[...nextauth]/auth"; + +export default async ({ children }: { children: React.ReactNode }) => { + const session = await getServerSession(); + + if (!session) return ; + + const user = await prisma.user.findUnique({ + where: { + id: session.user.id, + }, + }); + + if (!user?.permissions.includes("ADMIN_STATION")) + return ; + + return <>{children}; +}; diff --git a/apps/hub/app/(app)/admin/user/layout.tsx b/apps/hub/app/(app)/admin/user/layout.tsx new file mode 100644 index 00000000..fcce6a6a --- /dev/null +++ b/apps/hub/app/(app)/admin/user/layout.tsx @@ -0,0 +1,20 @@ +import { prisma } from "@repo/db"; +import { Error } from "_components/Error"; +import { getServerSession } from "api/auth/[...nextauth]/auth"; + +export default async ({ children }: { children: React.ReactNode }) => { + const session = await getServerSession(); + + if (!session) return ; + + const user = await prisma.user.findUnique({ + where: { + id: session.user.id, + }, + }); + + if (!user?.permissions.includes("ADMIN_USER")) + return ; + + return <>{children}; +}; diff --git a/apps/hub/app/_components/Error.tsx b/apps/hub/app/_components/Error.tsx index 683c92e6..a968ed50 100644 --- a/apps/hub/app/_components/Error.tsx +++ b/apps/hub/app/_components/Error.tsx @@ -7,5 +7,23 @@ export const Error = ({ statusCode: number; title: string; }) => { - return ; + return ( +
+
+

{statusCode}

+

+ Oh nein! Ein Fehler ist aufgetreten. +

+

+ {title || "Ein unerwarteter Fehler ist aufgetreten."} +

+ +
+
+ ); }; diff --git a/packages/database/prisma/schema/user.prisma b/packages/database/prisma/schema/user.prisma index df2db4de..38fc1fed 100644 --- a/packages/database/prisma/schema/user.prisma +++ b/packages/database/prisma/schema/user.prisma @@ -11,8 +11,9 @@ enum BADGES { enum PERMISSION { ADMIN_EVENT ADMIN_USER - AUDIO AUDIO_ADMIN + ADMIN_STATION + AUDIO PILOT DISPO }