-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Roles, Career): implement role inheritance
- Loading branch information
1 parent
ded9852
commit 3e4cb50
Showing
21 changed files
with
474 additions
and
85 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
app/prisma/migrations/20250113121029_add_role_inheritance/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
-- CreateTable | ||
CREATE TABLE "_inheritance" ( | ||
"A" TEXT NOT NULL, | ||
"B" TEXT NOT NULL | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "_inheritance_AB_unique" ON "_inheritance"("A", "B"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "_inheritance_B_index" ON "_inheritance"("B"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "_inheritance" ADD CONSTRAINT "_inheritance_A_fkey" FOREIGN KEY ("A") REFERENCES "Role"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "_inheritance" ADD CONSTRAINT "_inheritance_B_fkey" FOREIGN KEY ("B") REFERENCES "Role"("id") ON DELETE CASCADE ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { authenticatePage } from "@/auth/server"; | ||
import { SingleRole } from "@/common/components/SingleRole"; | ||
import { log } from "@/logging"; | ||
import { InheritanceForm } from "@/roles/components/InheritanceForm"; | ||
import { Navigation } from "@/roles/components/Navigation"; | ||
import { getRoleById, getRoles } from "@/roles/queries"; | ||
import { type Metadata } from "next"; | ||
import { notFound } from "next/navigation"; | ||
import { serializeError } from "serialize-error"; | ||
|
||
type Params = Promise<{ | ||
id: string; | ||
}>; | ||
|
||
export async function generateMetadata(props: { | ||
params: Params; | ||
}): Promise<Metadata> { | ||
try { | ||
const role = await getRoleById((await props.params).id); | ||
|
||
return { | ||
title: `${role?.name} - Vererbungen | S.A.M. - Sinister Incorporated`, | ||
}; | ||
} catch (error) { | ||
void log.error( | ||
"Error while generating metadata for /app/roles/[id]/inheritance/page.tsx", | ||
{ | ||
error: serializeError(error), | ||
}, | ||
); | ||
|
||
return { | ||
title: `Error | S.A.M. - Sinister Incorporated`, | ||
}; | ||
} | ||
} | ||
|
||
type Props = Readonly<{ | ||
params: Params; | ||
}>; | ||
|
||
export default async function Page({ params }: Props) { | ||
const authentication = await authenticatePage("/app/roles"); | ||
await authentication.authorizePage("role", "manage"); | ||
|
||
const roleId = (await params).id; | ||
const role = await getRoleById(roleId); | ||
if (!role) notFound(); | ||
|
||
const roles = await getRoles(); | ||
const _roles = roles | ||
.filter((r) => r.id !== role.id) | ||
.toSorted((a, b) => a.name.localeCompare(b.name)); | ||
|
||
return ( | ||
<main className="p-4 pb-20 lg:p-8 max-w-[1920px] mx-auto"> | ||
<div className="flex gap-2 font-bold text-xl"> | ||
<span className="text-neutral-500">Rolle /</span> | ||
<p>{role?.name}</p> | ||
</div> | ||
|
||
<Navigation | ||
role={role} | ||
active={`/app/roles/${roleId}/inheritance`} | ||
className="mt-2" | ||
/> | ||
|
||
<section className="rounded-2xl bg-neutral-800/50 p-4 lg:p-8 mt-4"> | ||
<h2 className="text-xl font-bold mb-2">Vererbungen</h2> | ||
<p> | ||
Die Rolle <SingleRole role={role} className="inline-flex align-sub" />{" "} | ||
erhält alle Berechtigungen von den folgenden ausgewählten Rollen. Im | ||
Karrieresystem gelten die folgenden Rollen ebenfalls als | ||
freigeschaltet. Verschachtelte Vererbungen werden nicht | ||
berücksichtigt. | ||
</p> | ||
|
||
<InheritanceForm currentRole={role} roles={_roles} className="mt-4" /> | ||
</section> | ||
</main> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.