added STANDARD admin responsibility

This commit is contained in:
Laurin
2022-06-06 18:34:59 +02:00
parent 339ecff938
commit 60100273fb
10 changed files with 92 additions and 43 deletions
+13 -3
View File
@@ -173,12 +173,22 @@ export const requireConfiguredAuthentication =
next();
};
export function requireResponsibleForGroup(auth: AuthJWTPayload | undefined, groupPid: string) {
export function requireResponsibleForGroups(auth: AuthJWTPayload | undefined, groupPids: string[] | string) {
if (auth?.permission_level === "ELEVATED") {
return;
}
if (!auth?.groups.includes(groupPid)) {
throw new AuthError("The provided authorization is not valid for the requested operation!");
if (Array.isArray(groupPids)) {
groupPids.forEach(gr => {
if (auth?.groups.includes(gr)) {
return;
}
throw new AuthError("The provided authorization is not valid for the requested operation!");
});
} else {
if (auth?.groups.includes(groupPids)) {
throw new AuthError("The provided authorization is not valid for the requested operation!");
}
}
}
+2 -1
View File
@@ -85,7 +85,8 @@ export const _requireTeamleaderAuthentication =
export const requireTeamleaderAuthentication = _requireTeamleaderAuthentication({ optional: false, controlled: false });
export function requireLeaderOfTeam(auth: TeamleaderJWTPayload | undefined, teamPid: string) {
export async function requireLeaderOfTeam(auth: TeamleaderJWTPayload | undefined, teamPid: string) {
await checkTeamExistence(teamPid);
if (auth?.team !== teamPid) {
throw new AuthError("The provided authorization is not valid for the requested team");
}