refactor(core): Setup decorator based RBAC (no-changelog) (#5787)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2023-04-24 09:45:31 +00:00
committed by GitHub
parent feb2ba09b9
commit 1eeadc6114
23 changed files with 133 additions and 165 deletions

View File

@@ -196,30 +196,6 @@ export async function getUserById(userId: string): Promise<User> {
return user;
}
/**
* Check if a URL contains an auth-excluded endpoint.
*/
export function isAuthExcluded(url: string, ignoredEndpoints: Readonly<string[]>): boolean {
return !!ignoredEndpoints
.filter(Boolean) // skip empty paths
.find((ignoredEndpoint) => url.startsWith(`/${ignoredEndpoint}`));
}
/**
* Check if the endpoint is `POST /users/:id`.
*/
export function isPostUsersId(req: express.Request, restEndpoint: string): boolean {
return (
req.method === 'POST' &&
new RegExp(`/${restEndpoint}/users/[\\w\\d-]*`).test(req.url) &&
!req.url.includes('reinvite')
);
}
export function isAuthenticatedRequest(request: express.Request): request is AuthenticatedRequest {
return request.user !== undefined;
}
// ----------------------------------
// hashing
// ----------------------------------