Fixes
This commit is contained in:
parent
56459b2736
commit
ebd762cdb6
|
@ -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<string, PermissionLevel[]> = {}
|
||||
|
@ -51,7 +51,7 @@ export class Role implements RoleDoc {
|
|||
constructor(
|
||||
id: string,
|
||||
name: string,
|
||||
permissionId: string,
|
||||
permissionId: BuiltinPermissionID,
|
||||
uiMetadata?: RoleUIMetadata
|
||||
) {
|
||||
this._id = id
|
||||
|
|
|
@ -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<string, Record<string, string>> = {}
|
||||
// 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<string, string> = {}
|
||||
const perms: Record<string, string> = permissions[resource] || {}
|
||||
levels.forEach(level => (perms[level] = roleId!))
|
||||
permissions[resource] = perms
|
||||
}
|
||||
|
|
|
@ -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 },
|
||||
},
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue