Don't use display names as role names, and restore usual names for built in roles
This commit is contained in:
parent
dabe401753
commit
663c0f20af
|
@ -48,9 +48,14 @@ export class Role implements RoleDoc {
|
|||
permissions: Record<string, PermissionLevel[]> = {}
|
||||
uiMetadata?: RoleUIMetadata
|
||||
|
||||
constructor(id: string, permissionId: string, uiMetadata?: RoleUIMetadata) {
|
||||
constructor(
|
||||
id: string,
|
||||
name: string,
|
||||
permissionId: string,
|
||||
uiMetadata?: RoleUIMetadata
|
||||
) {
|
||||
this._id = id
|
||||
this.name = uiMetadata?.displayName || id
|
||||
this.name = name
|
||||
this.uiMetadata = uiMetadata
|
||||
this.permissionId = permissionId
|
||||
// version for managing the ID - removing the role_ when responding
|
||||
|
@ -64,31 +69,56 @@ export class Role implements RoleDoc {
|
|||
}
|
||||
|
||||
const BUILTIN_ROLES = {
|
||||
ADMIN: new Role(BUILTIN_IDS.ADMIN, BuiltinPermissionID.ADMIN, {
|
||||
ADMIN: new Role(
|
||||
BUILTIN_IDS.ADMIN,
|
||||
BUILTIN_IDS.ADMIN,
|
||||
BuiltinPermissionID.ADMIN,
|
||||
{
|
||||
displayName: "App admin",
|
||||
description: "Can do everything",
|
||||
color: RoleColor.ADMIN,
|
||||
}).addInheritance(BUILTIN_IDS.POWER),
|
||||
POWER: new Role(BUILTIN_IDS.POWER, BuiltinPermissionID.POWER, {
|
||||
}
|
||||
).addInheritance(BUILTIN_IDS.POWER),
|
||||
POWER: new Role(
|
||||
BUILTIN_IDS.POWER,
|
||||
BUILTIN_IDS.POWER,
|
||||
BuiltinPermissionID.POWER,
|
||||
{
|
||||
displayName: "App power user",
|
||||
description: "An app user with more access",
|
||||
color: RoleColor.POWER,
|
||||
}).addInheritance(BUILTIN_IDS.BASIC),
|
||||
BASIC: new Role(BUILTIN_IDS.BASIC, BuiltinPermissionID.WRITE, {
|
||||
}
|
||||
).addInheritance(BUILTIN_IDS.BASIC),
|
||||
BASIC: new Role(
|
||||
BUILTIN_IDS.BASIC,
|
||||
BUILTIN_IDS.BASIC,
|
||||
BuiltinPermissionID.WRITE,
|
||||
{
|
||||
displayName: "App user",
|
||||
description: "Any logged in user",
|
||||
color: RoleColor.BASIC,
|
||||
}).addInheritance(BUILTIN_IDS.PUBLIC),
|
||||
PUBLIC: new Role(BUILTIN_IDS.PUBLIC, BuiltinPermissionID.PUBLIC, {
|
||||
}
|
||||
).addInheritance(BUILTIN_IDS.PUBLIC),
|
||||
PUBLIC: new Role(
|
||||
BUILTIN_IDS.PUBLIC,
|
||||
BUILTIN_IDS.PUBLIC,
|
||||
BuiltinPermissionID.PUBLIC,
|
||||
{
|
||||
displayName: "Public user",
|
||||
description: "Accessible to anyone",
|
||||
color: RoleColor.PUBLIC,
|
||||
}),
|
||||
BUILDER: new Role(BUILTIN_IDS.BUILDER, BuiltinPermissionID.ADMIN, {
|
||||
}
|
||||
),
|
||||
BUILDER: new Role(
|
||||
BUILTIN_IDS.BUILDER,
|
||||
BUILTIN_IDS.BUILDER,
|
||||
BuiltinPermissionID.ADMIN,
|
||||
{
|
||||
displayName: "Builder user",
|
||||
description: "Users that can edit this app",
|
||||
color: RoleColor.BUILDER,
|
||||
}),
|
||||
}
|
||||
),
|
||||
}
|
||||
|
||||
export function getBuiltinRoles(): { [key: string]: RoleDoc } {
|
||||
|
|
|
@ -89,7 +89,7 @@ export async function save(ctx: UserCtx<SaveRoleRequest, SaveRoleResponse>) {
|
|||
ctx.throw(400, "Cannot change custom role name")
|
||||
}
|
||||
|
||||
const role = new roles.Role(_id, permissionId, {
|
||||
const role = new roles.Role(_id, name, permissionId, {
|
||||
displayName: uiMetadata?.displayName || name,
|
||||
description: uiMetadata?.description || "Custom role",
|
||||
color: uiMetadata?.color || RoleColor.DEFAULT_CUSTOM,
|
||||
|
|
|
@ -35,6 +35,7 @@ describe("/api/global/roles", () => {
|
|||
|
||||
const role = new roles.Role(
|
||||
db.generateRoleID(ROLE_NAME),
|
||||
ROLE_NAME,
|
||||
permissions.BuiltinPermissionID.READ_ONLY,
|
||||
{ displayName: roles.BUILTIN_ROLE_IDS.BASIC }
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue