mirror of
https://github.com/hexastack/hexabot
synced 2025-01-22 18:45:57 +00:00
fix: adapt ability guard
This commit is contained in:
parent
869d7d167d
commit
88cb281694
@ -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]),
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user