Fixed UserController errors

This commit is contained in:
2026-01-25 15:09:55 -06:00
parent e76caa68f1
commit d96f18e6cf
2 changed files with 20 additions and 14 deletions
+4 -4
View File
@@ -78,7 +78,7 @@ export class RoleController {
}); });
throw new PermissionsVerificationError( throw new PermissionsVerificationError(
`Unable to verify permissions for role '${this.title}, it is recommended that you override and rewrite these permissions immediately.`, `Unable to verify permissions for role '${this.title}, it is recommended that you override and rewrite these permissions immediately.`,
(err as Error).message (err as Error).message,
); );
} }
@@ -248,14 +248,14 @@ export class RoleController {
title: string; title: string;
moniker: string; moniker: string;
permissions: string[]; permissions: string[];
}> }>,
) { ) {
const schema = z const schema = z
.object({ .object({
title: z.string().min(1, "Title cannot be empty."), title: z.string().min(1, "Title cannot be empty."),
moniker: z.string().min(1, "Moniker cannot be empty."), moniker: z.string().min(1, "Moniker cannot be empty."),
permissions: z.array( permissions: z.array(
z.string().min(1, "Permission node cannot be empty") z.string().min(1, "Permission node cannot be empty"),
), ),
}) })
.partial() .partial()
@@ -271,7 +271,7 @@ export class RoleController {
if (checkMoniker) if (checkMoniker)
throw new RoleError( throw new RoleError(
"Moniker is already taken.", "Moniker is already taken.",
"Another role with this moniker already exists in the databse." "Another role with this moniker already exists in the databse.",
); );
} }
+10 -4
View File
@@ -141,16 +141,22 @@ export default class UserController {
}, },
}); });
const implicitPermissions = Object.keys(resources ?? {}) const resourceKeys: string[] = Object.keys(resources ?? {}) as string[];
.filter((v) => resources![v].length > 0)
const implicitPermissions = resources
? resourceKeys
// @ts-ignore
.filter((v) => resources[v].length > 0)
.map( .map(
(v) => (v) =>
//@ts-ignore
`resource.${v}.[${(resources![v] as { id: string }[]) `resource.${v}.[${(resources![v] as { id: string }[])
.map((o) => o.id) .map((o) => o.id)
.join(",")}].user.${this.id}.implicit`, .join(",")}].user.${this.id}.implicit`,
); )
: [];
console.log(implicitPermissions); // console.log(implicitPermissions);
let checks = [ let checks = [
(await this.fetchRoles()).map((v) => v.checkPermission(permission)), (await this.fetchRoles()).map((v) => v.checkPermission(permission)),