Add basic sdk checks
This commit is contained in:
parent
62579fab4e
commit
54c285f71c
|
@ -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,
|
||||||
|
}
|
||||||
|
}
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue