reverting some breaking changes

This commit is contained in:
Mateus Badan de Pieri 2023-04-14 11:45:27 +01:00
parent 038476523f
commit 2f98ce9772
1 changed files with 23 additions and 41 deletions

View File

@ -1,21 +1,13 @@
import { import {
RoleHierarchy, doesHaveBasePermission,
getBuiltinPermissionByID,
isPermissionLevelHigherThanRead,
PermissionLevel, PermissionLevel,
PermissionType, PermissionType,
levelToNumber, levelToNumber,
getAllowedLevels, getAllowedLevels,
BuiltinPermissionID,
getBuiltinPermissions,
getBuiltinPermissionByID,
doesHaveBasePermission,
isPermissionLevelHigherThanRead,
BUILDER,
} from "../permissions" } from "../permissions"
jest.mock("../permissions", () => ({
// getTenantId: jest.fn(() => "budibase"),
// DEFAULT_TENANT_ID: "default",
}))
describe("levelToNumber", () => { describe("levelToNumber", () => {
it("should return 0 for EXECUTE", () => { it("should return 0 for EXECUTE", () => {
expect(levelToNumber(PermissionLevel.EXECUTE)).toBe(0) expect(levelToNumber(PermissionLevel.EXECUTE)).toBe(0)
@ -73,38 +65,28 @@ describe("getAllowedLevels", () => {
}) })
describe("doesHaveBasePermission", () => { describe("doesHaveBasePermission", () => {
const rolesHierarchy: RoleHierarchy = [ it("should return true if base permission has the required level", () => {
{ permissionId: BuiltinPermissionID.READ_ONLY }, const permType = PermissionType.APP
] const permLevel = PermissionLevel.READ
const rolesHierarchy = [
it("should return true for read permission of read only role", () => { { roleId: "role1", permissionId: "permission1" },
expect( { roleId: "role2", permissionId: "permission2" },
doesHaveBasePermission( ]
PermissionType.TABLE, expect(doesHaveBasePermission(permType, permLevel, rolesHierarchy)).toBe(
PermissionLevel.READ, true
rolesHierarchy )
)
).toBe(true)
}) })
it("should return false for write permission of read only role", () => { it("should return false if base permission does not have the required level", () => {
expect( const permType = PermissionType.APP
doesHaveBasePermission( const permLevel = PermissionLevel.READ
PermissionType.TABLE, const rolesHierarchy = [
PermissionLevel.WRITE, { roleId: "role1", permissionId: "permission1" },
rolesHierarchy { roleId: "role2", permissionId: "permission2" },
) ]
).toBe(false) expect(doesHaveBasePermission(permType, permLevel, rolesHierarchy)).toBe(
}) false
)
it("should return true for execute permission of public role", () => {
expect(
doesHaveBasePermission(
PermissionType.WEBHOOK,
PermissionLevel.EXECUTE,
rolesHierarchy
)
).toBe(true)
}) })
}) })