added format command and added trailing commas to reduce conflicts

This commit is contained in:
dswbx
2025-02-26 20:06:03 +01:00
parent 88b5359f1c
commit 7743f71a11
414 changed files with 3622 additions and 3610 deletions

View File

@@ -37,7 +37,7 @@ export class Guard {
implicit_allow?: boolean;
}
>,
config?: GuardConfig
config?: GuardConfig,
) {
const _roles = roles
? objectTransform(roles, ({ permissions = [], is_default, implicit_allow }, name) => {
@@ -103,7 +103,7 @@ export class Guard {
debug &&
console.log("guard: role not found", {
user: user,
role: user?.role
role: user?.role,
});
return this.getDefaultRole();
}
@@ -141,14 +141,14 @@ export class Guard {
}
const rolePermission = role.permissions.find(
(rolePermission) => rolePermission.permission.name === name
(rolePermission) => rolePermission.permission.name === name,
);
debug &&
console.log("guard: rolePermission, allowing?", {
permission: name,
role: role.name,
allowing: !!rolePermission
allowing: !!rolePermission,
});
return !!rolePermission;
}
@@ -162,7 +162,7 @@ export class Guard {
if (!this.granted(permission, c)) {
throw new Exception(
`Permission "${typeof permission === "string" ? permission : permission.name}" not granted`,
403
403,
);
}
}

View File

@@ -3,7 +3,7 @@ import { Permission } from "core";
export class RolePermission {
constructor(
public permission: Permission,
public config?: any
public config?: any,
) {}
}
@@ -12,20 +12,20 @@ export class Role {
public name: string,
public permissions: RolePermission[] = [],
public is_default: boolean = false,
public implicit_allow: boolean = false
public implicit_allow: boolean = false,
) {}
static createWithPermissionNames(
name: string,
permissionNames: string[],
is_default: boolean = false,
implicit_allow: boolean = false
implicit_allow: boolean = false,
) {
return new Role(
name,
permissionNames.map((name) => new RolePermission(new Permission(name))),
is_default,
implicit_allow
implicit_allow,
);
}
@@ -39,7 +39,7 @@ export class Role {
config.name,
config.permissions?.map((name) => new RolePermission(new Permission(name))) ?? [],
config.is_default,
config.implicit_allow
config.implicit_allow,
);
}
}