Update role enum and access control Remove isRouteAnAPI(route: string):

boolean

Refactor role determination logic to use `eduPersonPrimaryAffiliation`
and `amuComposante`. This simplifies checking for Polytech affiliation
and identifies roles like professor, administration, and student more
accurately. The API access control is updated to reflect the new role
names.
This commit is contained in:
2026-01-07 22:56:06 +01:00
parent 718e7f9d76
commit 229e72da88
2 changed files with 9 additions and 28 deletions
+8 -27
View File
@@ -26,14 +26,6 @@ function isRoutePublic(route: string): boolean {
);
}
/**
* Checks if the given route is an API route.
* @param route The route to check.
* @returns `true` if the route is an API route, `false` otherwise.
*/
function isRouteAnAPI(route: string): boolean {
return route.includes("/api/");
}
/**
* Get the given user's key, creating it if not already existing.
* @param user The key's user.
@@ -82,26 +74,21 @@ export const handler: MiddlewareHandler<State>[] = [
getJwtPayload(cookies["sessionToken"]) as LoginJWT
).user;
const isFromPolytech = Object.values(session.memberOf).some(
(value) =>
typeof value === "string" && value.includes("cn=amu:ufr:polytech"),
);
const isFromPolytech = session.amuComposante.includes("polytech");
context.state.isFromPolytech = isFromPolytech;
if (isFromPolytech) {
context.state.session = session;
if (Object.values(session.memberOf).some(
(value) => typeof value === "string" && value.includes("cn=amu:ufr:polytech:personnels")
)) {
context.state.role = "personnels";
} else if (Object.values(session.memberOf).some(
(value) => typeof value === "string" && value.includes("cn=amu:ufr:polytech:etudiants")
)) {
context.state.role = "etudiants";
if (session.eduPersonPrimaryAffiliation.includes("faculty")) {
context.state.role = "professeur"
} else if (session.eduPersonPrimaryAffiliation.includes("employee")) {
context.state.role = "administration"
} else if (session.eduPersonPrimaryAffiliation.includes("student")) {
context.state.role = "etudiant";
} else {
context.state.role = "autres";
context.state.role = "autre";
}
}
}
@@ -139,12 +126,6 @@ export const handler: MiddlewareHandler<State>[] = [
},
});
}
if (isRouteAnAPI(url.pathname) && !(context.state.role == "personnels")) {
return new Response(null, {
status: 403,
});
}
}
return await context.next();