Merge branch 'master' of github.com:Budibase/budibase into v3-ui

This commit is contained in:
Andrew Kingston 2024-09-13 14:29:37 +01:00
commit 3af090d50f
No known key found for this signature in database
3 changed files with 59 additions and 28 deletions

View File

@ -48,9 +48,14 @@ export class Role implements RoleDoc {
permissions: Record<string, PermissionLevel[]> = {} permissions: Record<string, PermissionLevel[]> = {}
uiMetadata?: RoleUIMetadata uiMetadata?: RoleUIMetadata
constructor(id: string, permissionId: string, uiMetadata?: RoleUIMetadata) { constructor(
id: string,
name: string,
permissionId: string,
uiMetadata?: RoleUIMetadata
) {
this._id = id this._id = id
this.name = uiMetadata?.displayName || id this.name = name
this.uiMetadata = uiMetadata this.uiMetadata = uiMetadata
this.permissionId = permissionId this.permissionId = permissionId
// version for managing the ID - removing the role_ when responding // version for managing the ID - removing the role_ when responding
@ -64,31 +69,56 @@ export class Role implements RoleDoc {
} }
const BUILTIN_ROLES = { const BUILTIN_ROLES = {
ADMIN: new Role(BUILTIN_IDS.ADMIN, BuiltinPermissionID.ADMIN, { ADMIN: new Role(
displayName: "App admin", BUILTIN_IDS.ADMIN,
description: "Can do everything", BUILTIN_IDS.ADMIN,
color: RoleColor.ADMIN, BuiltinPermissionID.ADMIN,
}).addInheritance(BUILTIN_IDS.POWER), {
POWER: new Role(BUILTIN_IDS.POWER, BuiltinPermissionID.POWER, { displayName: "App admin",
displayName: "App power user", description: "Can do everything",
description: "An app user with more access", color: RoleColor.ADMIN,
color: RoleColor.POWER, }
}).addInheritance(BUILTIN_IDS.BASIC), ).addInheritance(BUILTIN_IDS.POWER),
BASIC: new Role(BUILTIN_IDS.BASIC, BuiltinPermissionID.WRITE, { POWER: new Role(
displayName: "App user", BUILTIN_IDS.POWER,
description: "Any logged in user", BUILTIN_IDS.POWER,
color: RoleColor.BASIC, BuiltinPermissionID.POWER,
}).addInheritance(BUILTIN_IDS.PUBLIC), {
PUBLIC: new Role(BUILTIN_IDS.PUBLIC, BuiltinPermissionID.PUBLIC, { displayName: "App power user",
displayName: "Public user", description: "An app user with more access",
description: "Accessible to anyone", color: RoleColor.POWER,
color: RoleColor.PUBLIC, }
}), ).addInheritance(BUILTIN_IDS.BASIC),
BUILDER: new Role(BUILTIN_IDS.BUILDER, BuiltinPermissionID.ADMIN, { BASIC: new Role(
displayName: "Builder user", BUILTIN_IDS.BASIC,
description: "Users that can edit this app", BUILTIN_IDS.BASIC,
color: RoleColor.BUILDER, BuiltinPermissionID.WRITE,
}), {
displayName: "App user",
description: "Any logged in user",
color: RoleColor.BASIC,
}
).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,
BUILTIN_IDS.BUILDER,
BuiltinPermissionID.ADMIN,
{
displayName: "Builder user",
description: "Users that can edit this app",
color: RoleColor.BUILDER,
}
),
} }
export function getBuiltinRoles(): { [key: string]: RoleDoc } { export function getBuiltinRoles(): { [key: string]: RoleDoc } {

View File

@ -89,7 +89,7 @@ export async function save(ctx: UserCtx<SaveRoleRequest, SaveRoleResponse>) {
ctx.throw(400, "Cannot change custom role name") 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, displayName: uiMetadata?.displayName || name,
description: uiMetadata?.description || "Custom role", description: uiMetadata?.description || "Custom role",
color: uiMetadata?.color || RoleColor.DEFAULT_CUSTOM, color: uiMetadata?.color || RoleColor.DEFAULT_CUSTOM,

View File

@ -35,6 +35,7 @@ describe("/api/global/roles", () => {
const role = new roles.Role( const role = new roles.Role(
db.generateRoleID(ROLE_NAME), db.generateRoleID(ROLE_NAME),
ROLE_NAME,
permissions.BuiltinPermissionID.READ_ONLY, permissions.BuiltinPermissionID.READ_ONLY,
{ displayName: roles.BUILTIN_ROLE_IDS.BASIC } { displayName: roles.BUILTIN_ROLE_IDS.BASIC }
) )