fix: adapt ability guard

This commit is contained in:
yassinedorbozgithub 2025-01-09 08:46:27 +01:00
parent 869d7d167d
commit 88cb281694

View File

@ -53,6 +53,7 @@ export class Ability implements CanActivate {
if (user?.roles?.length) { if (user?.roles?.length) {
if ( if (
_parsedUrl.pathname &&
[ [
// Allow access to all routes available for authenticated users // Allow access to all routes available for authenticated users
'/auth/logout', '/auth/logout',
@ -68,9 +69,9 @@ export class Ability implements CanActivate {
) { ) {
return true; return true;
} }
const modelFromPathname = _parsedUrl.pathname const modelFromPathname = _parsedUrl?.pathname
.split('/')[1] ?.split('/')[1]
.toLowerCase() as TModel; .toLowerCase() as TModel | undefined;
const permissions = await this.permissionService.getPermissions(); const permissions = await this.permissionService.getPermissions();
@ -80,6 +81,7 @@ export class Ability implements CanActivate {
.map(([_, value]) => value); .map(([_, value]) => value);
if ( if (
modelFromPathname &&
permissionsFromRoles.some((permission) => permissionsFromRoles.some((permission) =>
permission[modelFromPathname]?.includes(MethodToAction[method]), permission[modelFromPathname]?.includes(MethodToAction[method]),
) )