Add basic sdk checks

This commit is contained in:
Adria Navarro 2023-08-21 17:56:40 +03:00
parent 62579fab4e
commit 54c285f71c
2 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,32 @@
import {
DocumentType,
PermissionLevel,
VirtualDocumentType,
} from "@budibase/types"
import { isViewID } from "../../../db/utils"
type ResourceActionAllowedResult =
| { allowed: true }
| {
allowed: false
level: PermissionLevel
resourceType: DocumentType | VirtualDocumentType
}
export async function resourceActionAllowed({
resourceId,
level,
}: {
resourceId: string
level: PermissionLevel
}): Promise<ResourceActionAllowedResult> {
if (!isViewID(resourceId)) {
return { allowed: true }
}
return {
allowed: false,
level,
resourceType: VirtualDocumentType.VIEW,
}
}

View File

@ -8,6 +8,7 @@ import { default as rows } from "./app/rows"
import { default as users } from "./users" import { default as users } from "./users"
import { default as plugins } from "./plugins" import { default as plugins } from "./plugins"
import * as views from "./app/views" import * as views from "./app/views"
import * as permissions from "./app/permissions"
const sdk = { const sdk = {
backups, backups,
@ -20,6 +21,7 @@ const sdk = {
queries, queries,
plugins, plugins,
views, views,
permissions,
} }
// default export for TS // default export for TS