Implemment checks
This commit is contained in:
parent
c792e55675
commit
664f257239
|
@ -102,6 +102,10 @@ export const useAppBuilders = () => {
|
||||||
return useFeature(Feature.APP_BUILDERS)
|
return useFeature(Feature.APP_BUILDERS)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const useViewPermissions = () => {
|
||||||
|
return useFeature(Feature.VIEW_PERMISSIONS)
|
||||||
|
}
|
||||||
|
|
||||||
// QUOTAS
|
// QUOTAS
|
||||||
|
|
||||||
export const setAutomationLogsQuota = (value: number) => {
|
export const setAutomationLogsQuota = (value: number) => {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import {
|
||||||
VirtualDocumentType,
|
VirtualDocumentType,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { isViewID } from "../../../db/utils"
|
import { isViewID } from "../../../db/utils"
|
||||||
|
import { features } from "@budibase/pro"
|
||||||
|
|
||||||
type ResourceActionAllowedResult =
|
type ResourceActionAllowedResult =
|
||||||
| { allowed: true }
|
| { allowed: true }
|
||||||
|
@ -24,6 +25,10 @@ export async function resourceActionAllowed({
|
||||||
return { allowed: true }
|
return { allowed: true }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (await features.isViewPermissionEnabled()) {
|
||||||
|
return { allowed: true }
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
allowed: false,
|
allowed: false,
|
||||||
level,
|
level,
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
import TestConfiguration from "../../../../tests/utilities/TestConfiguration"
|
||||||
|
import { PermissionLevel } from "@budibase/types"
|
||||||
|
import { mocks, structures } from "@budibase/backend-core/tests"
|
||||||
|
import { resourceActionAllowed } from ".."
|
||||||
|
import { generateViewID } from "../../../../db/utils"
|
||||||
|
|
||||||
|
describe("permissions sdk", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
new TestConfiguration()
|
||||||
|
mocks.licenses.useCloudFree()
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("resourceActionAllowed", () => {
|
||||||
|
it("non view resources actions are always allowed", async () => {
|
||||||
|
const resourceId = structures.users.user()._id!
|
||||||
|
|
||||||
|
const result = await resourceActionAllowed({
|
||||||
|
resourceId,
|
||||||
|
level: PermissionLevel.READ,
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(result).toEqual({ allowed: true })
|
||||||
|
})
|
||||||
|
|
||||||
|
it("view resources actions allowed if the feature flag is enabled", async () => {
|
||||||
|
mocks.licenses.useViewPermissions()
|
||||||
|
const resourceId = generateViewID(structures.generator.guid())
|
||||||
|
|
||||||
|
const result = await resourceActionAllowed({
|
||||||
|
resourceId,
|
||||||
|
level: PermissionLevel.READ,
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(result).toEqual({ allowed: true })
|
||||||
|
})
|
||||||
|
|
||||||
|
it("view resources actions allowed if the feature flag is disabled", async () => {
|
||||||
|
const resourceId = generateViewID(structures.generator.guid())
|
||||||
|
|
||||||
|
const result = await resourceActionAllowed({
|
||||||
|
resourceId,
|
||||||
|
level: PermissionLevel.READ,
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(result).toEqual({
|
||||||
|
allowed: false,
|
||||||
|
level: "read",
|
||||||
|
resourceType: "view",
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
|
@ -12,6 +12,7 @@ export enum Feature {
|
||||||
APP_BUILDERS = "appBuilders",
|
APP_BUILDERS = "appBuilders",
|
||||||
OFFLINE = "offline",
|
OFFLINE = "offline",
|
||||||
USER_ROLE_PUBLIC_API = "userRolePublicApi",
|
USER_ROLE_PUBLIC_API = "userRolePublicApi",
|
||||||
|
VIEW_PERMISSIONS = "viewPermission",
|
||||||
}
|
}
|
||||||
|
|
||||||
export type PlanFeatures = { [key in PlanType]: Feature[] | undefined }
|
export type PlanFeatures = { [key in PlanType]: Feature[] | undefined }
|
||||||
|
|
Loading…
Reference in New Issue