From ebd762cdb69a21d3edc5adee018f42bb5d1e730d Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 8 Oct 2024 17:19:18 +0200 Subject: [PATCH] Fixes --- packages/backend-core/src/security/roles.ts | 4 ++-- packages/server/src/api/controllers/permission.ts | 4 ++-- packages/server/src/api/routes/tests/permissions.spec.ts | 8 +++++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/backend-core/src/security/roles.ts b/packages/backend-core/src/security/roles.ts index 65339832cf..9ae3788aab 100644 --- a/packages/backend-core/src/security/roles.ts +++ b/packages/backend-core/src/security/roles.ts @@ -42,7 +42,7 @@ export class Role implements RoleDoc { _id: string _rev?: string name: string - permissionId: string + permissionId: BuiltinPermissionID inherits?: string version?: string permissions: Record = {} @@ -51,7 +51,7 @@ export class Role implements RoleDoc { constructor( id: string, name: string, - permissionId: string, + permissionId: BuiltinPermissionID, uiMetadata?: RoleUIMetadata ) { this._id = id diff --git a/packages/server/src/api/controllers/permission.ts b/packages/server/src/api/controllers/permission.ts index cbe260367c..a58d94ce80 100644 --- a/packages/server/src/api/controllers/permission.ts +++ b/packages/server/src/api/controllers/permission.ts @@ -33,7 +33,7 @@ export async function fetch( ) { const db = context.getAppDB() const dbRoles = await sdk.permissions.getAllDBRoles(db) - let permissions: any = {} + let permissions: Record> = {} // create an object with structure role ID -> resource ID -> level for (let role of dbRoles) { if (!role.permissions) { @@ -45,7 +45,7 @@ export async function fetch( } for (let [resource, levelArr] of Object.entries(role.permissions)) { const levels: string[] = Array.isArray(levelArr) ? levelArr : [levelArr] - const perms: Record = {} + const perms: Record = permissions[resource] || {} levels.forEach(level => (perms[level] = roleId!)) permissions[resource] = perms } diff --git a/packages/server/src/api/routes/tests/permissions.spec.ts b/packages/server/src/api/routes/tests/permissions.spec.ts index 3b45d042c7..83452b4f1f 100644 --- a/packages/server/src/api/routes/tests/permissions.spec.ts +++ b/packages/server/src/api/routes/tests/permissions.spec.ts @@ -39,6 +39,8 @@ describe("/permission", () => { }) describe("table permissions", () => { + const DEFAULT_TABLE_ROLE_ID = BUILTIN_ROLE_IDS.ADMIN + let tableId: string let row: Row let view: ViewV2 @@ -67,11 +69,11 @@ describe("/permission", () => { expect(permissions).toEqual({ read: { permissionType: "BASE", - role: "BASIC", + role: DEFAULT_TABLE_ROLE_ID, }, write: { permissionType: "BASE", - role: "BASIC", + role: DEFAULT_TABLE_ROLE_ID, }, }) }) @@ -91,7 +93,7 @@ describe("/permission", () => { expect(res.body).toEqual({ permissions: { read: { permissionType: "EXPLICIT", role: STD_ROLE_ID }, - write: { permissionType: "BASE", role: HIGHER_ROLE_ID }, + write: { permissionType: "BASE", role: DEFAULT_TABLE_ROLE_ID }, }, }) })