mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 13:59:16 +01:00
feat(api): ✨ Overhaul Role API, add ability to edit roles and assign/unassign them from any user
This commit is contained in:
parent
7431c1e21d
commit
49c53de99e
10 changed files with 926 additions and 153 deletions
|
|
@ -22,13 +22,13 @@ type RoleType = InferSelectModel<typeof Roles>;
|
|||
|
||||
export class Role extends BaseInterface<typeof Roles> {
|
||||
public static schema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
id: z.string().uuid(),
|
||||
name: z.string().min(1).max(128),
|
||||
permissions: z.array(z.nativeEnum(RolePermission)),
|
||||
priority: z.number(),
|
||||
description: z.string().nullable(),
|
||||
priority: z.number().int(),
|
||||
description: z.string().min(0).max(1024).nullable(),
|
||||
visible: z.boolean(),
|
||||
icon: z.string().nullable(),
|
||||
icon: z.string().url().nullable(),
|
||||
});
|
||||
|
||||
public static $type: RoleType;
|
||||
|
|
@ -70,6 +70,29 @@ export class Role extends BaseInterface<typeof Roles> {
|
|||
return new Role(found);
|
||||
}
|
||||
|
||||
public static async getAll(): Promise<Role[]> {
|
||||
return (await Role.manyFromSql(undefined)).concat(
|
||||
new Role({
|
||||
id: "default",
|
||||
name: "Default",
|
||||
permissions: config.permissions.default,
|
||||
priority: 0,
|
||||
description: "Default role for all users",
|
||||
visible: false,
|
||||
icon: null,
|
||||
}),
|
||||
new Role({
|
||||
id: "admin",
|
||||
name: "Admin",
|
||||
permissions: config.permissions.admin,
|
||||
priority: 2 ** 31 - 1,
|
||||
description: "Default role for all administrators",
|
||||
visible: false,
|
||||
icon: null,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public static async getUserRoles(
|
||||
userId: string,
|
||||
isAdmin: boolean,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue