mirror of
https://github.com/detleph/server.git
synced 2026-09-04 16:46:04 +02:00
added STANDARD admin responsibility
This commit is contained in:
@@ -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!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user