Started implementing the roles permissions

This commit is contained in:
Tiago Ribeiro
2024-10-10 19:13:18 +01:00
parent c43ab9a911
commit 55204e2ce1
67 changed files with 1357 additions and 1134 deletions

View File

@@ -17,29 +17,16 @@ import CardList from "@/components/High/CardList";
import {getEntitiesWithRoles} from "@/utils/entities.be";
import {EntityWithRoles} from "@/interfaces/entity";
import Separator from "@/components/Low/Separator";
import { requestUser } from "@/utils/api";
import { redirect } from "@/utils";
type EntitiesWithCount = {entity: EntityWithRoles; users: User[]; count: number};
export const getServerSideProps = withIronSessionSsr(async ({req}) => {
const user = req.session.user;
export const getServerSideProps = withIronSessionSsr(async ({req, res}) => {
const user = await requestUser(req, res)
if (!user) return redirect("/login")
if (!user) {
return {
redirect: {
destination: "/login",
permanent: false,
},
};
}
if (shouldRedirectHome(user)) {
return {
redirect: {
destination: "/",
permanent: false,
},
};
}
if (shouldRedirectHome(user)) return redirect("/")
const entities = await getEntitiesWithRoles(
checkAccess(user, getTypesOfUser(["admin", "developer"])) ? user.entities.map((x) => x.id) : undefined,
@@ -99,18 +86,21 @@ export default function Home({user, entities}: Props) {
<link rel="icon" href="/favicon.ico" />
</Head>
<ToastContainer />
{user && (
<Layout user={user} className="!gap-4">
<section className="flex flex-col gap-4 w-full h-full">
<div className="flex flex-col gap-4">
<h2 className="font-bold text-2xl">Entities</h2>
<Separator />
</div>
<Layout user={user} className="!gap-4">
<section className="flex flex-col gap-4 w-full h-full">
<div className="flex flex-col gap-4">
<h2 className="font-bold text-2xl">Entities</h2>
<Separator />
</div>
<CardList<EntitiesWithCount> list={entities} searchFields={SEARCH_FIELDS} renderCard={renderCard} firstCard={firstCard} />
</section>
</Layout>
)}
<CardList<EntitiesWithCount>
list={entities}
searchFields={SEARCH_FIELDS}
renderCard={renderCard}
firstCard={["admin", "developer"].includes(user.type) ? firstCard : undefined}
/>
</section>
</Layout>
</>
);
}