mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
feat(api): ✨ Add Lysand roles to user accounts
This commit is contained in:
parent
4f2c98390c
commit
efe202ea27
6 changed files with 76 additions and 1 deletions
|
|
@ -14,6 +14,10 @@ import { RoleToUsers, Roles } from "~/drizzle/schema";
|
|||
export class Role {
|
||||
private constructor(private role: InferSelectModel<typeof Roles>) {}
|
||||
|
||||
public static fromRole(role: InferSelectModel<typeof Roles>) {
|
||||
return new Role(role);
|
||||
}
|
||||
|
||||
public static async fromId(id: string | null): Promise<Role | null> {
|
||||
if (!id) return null;
|
||||
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ import { type Config, config } from "~/packages/config-manager";
|
|||
import type { Account as APIAccount } from "~/types/mastodon/account";
|
||||
import type { Mention as APIMention } from "~/types/mastodon/mention";
|
||||
import type { Note } from "./note";
|
||||
import { Role } from "./role";
|
||||
|
||||
/**
|
||||
* Gives helpers to fetch users from database in a nice format
|
||||
|
|
@ -602,6 +603,36 @@ export class User {
|
|||
suspended: false,
|
||||
discoverable: undefined,
|
||||
mute_expires_at: undefined,
|
||||
roles: user.roles
|
||||
.map((role) => Role.fromRole(role))
|
||||
.concat(
|
||||
Role.fromRole({
|
||||
id: "default",
|
||||
name: "Default",
|
||||
permissions: config.permissions.default,
|
||||
priority: 0,
|
||||
description: "Default role for all users",
|
||||
visible: false,
|
||||
icon: null,
|
||||
}),
|
||||
)
|
||||
.concat(
|
||||
user.isAdmin
|
||||
? [
|
||||
Role.fromRole({
|
||||
id: "admin",
|
||||
name: "Admin",
|
||||
permissions: config.permissions.admin,
|
||||
priority: 2 ** 31 - 1,
|
||||
description:
|
||||
"Default role for all administrators",
|
||||
visible: false,
|
||||
icon: null,
|
||||
}),
|
||||
]
|
||||
: [],
|
||||
)
|
||||
.map((r) => r.toAPI()),
|
||||
group: false,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue