Check views
This commit is contained in:
parent
0ece6a4d2d
commit
b461025639
|
@ -514,8 +514,12 @@ describe("/rowsActions", () => {
|
||||||
2
|
2
|
||||||
)
|
)
|
||||||
|
|
||||||
const viewId1 = generator.guid()
|
const { id: viewId1 } = await config.api.viewV2.create(
|
||||||
const viewId2 = generator.guid()
|
setup.structures.viewV2.createRequest(tableId)
|
||||||
|
)
|
||||||
|
const { id: viewId2 } = await config.api.viewV2.create(
|
||||||
|
setup.structures.viewV2.createRequest(tableId)
|
||||||
|
)
|
||||||
|
|
||||||
await config.api.rowAction.setViewPermission(
|
await config.api.rowAction.setViewPermission(
|
||||||
tableId,
|
tableId,
|
||||||
|
@ -584,8 +588,12 @@ describe("/rowsActions", () => {
|
||||||
|
|
||||||
const [actionId] = _.sampleSize(Object.keys(persisted.actions), 1)
|
const [actionId] = _.sampleSize(Object.keys(persisted.actions), 1)
|
||||||
|
|
||||||
const viewId1 = generator.guid()
|
const { id: viewId1 } = await config.api.viewV2.create(
|
||||||
const viewId2 = generator.guid()
|
setup.structures.viewV2.createRequest(tableId)
|
||||||
|
)
|
||||||
|
const { id: viewId2 } = await config.api.viewV2.create(
|
||||||
|
setup.structures.viewV2.createRequest(tableId)
|
||||||
|
)
|
||||||
|
|
||||||
await config.api.rowAction.setViewPermission(tableId, viewId1, actionId, {
|
await config.api.rowAction.setViewPermission(tableId, viewId1, actionId, {
|
||||||
status: 200,
|
status: 200,
|
||||||
|
|
|
@ -141,11 +141,19 @@ export async function update(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function guardView(tableId: string, viewId: string) {
|
||||||
|
const view = await sdk.views.get(viewId)
|
||||||
|
if (!view || view.tableId !== tableId) {
|
||||||
|
throw new HTTPError(`View '${viewId}' not found in '${tableId}'`, 400)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function setViewPermission(
|
export async function setViewPermission(
|
||||||
tableId: string,
|
tableId: string,
|
||||||
rowActionId: string,
|
rowActionId: string,
|
||||||
viewId: string
|
viewId: string
|
||||||
) {
|
) {
|
||||||
|
await guardView(tableId, viewId)
|
||||||
return await updateDoc(tableId, rowActionId, async actionsDoc => {
|
return await updateDoc(tableId, rowActionId, async actionsDoc => {
|
||||||
actionsDoc.actions[rowActionId].permissions.views[viewId] = {
|
actionsDoc.actions[rowActionId].permissions.views[viewId] = {
|
||||||
runAllowed: true,
|
runAllowed: true,
|
||||||
|
@ -159,6 +167,7 @@ export async function unsetViewPermission(
|
||||||
rowActionId: string,
|
rowActionId: string,
|
||||||
viewId: string
|
viewId: string
|
||||||
) {
|
) {
|
||||||
|
await guardView(tableId, viewId)
|
||||||
return await updateDoc(tableId, rowActionId, async actionsDoc => {
|
return await updateDoc(tableId, rowActionId, async actionsDoc => {
|
||||||
delete actionsDoc.actions[rowActionId].permissions.views[viewId]
|
delete actionsDoc.actions[rowActionId].permissions.views[viewId]
|
||||||
return actionsDoc
|
return actionsDoc
|
||||||
|
|
|
@ -30,6 +30,7 @@ import {
|
||||||
BBReferenceFieldSubType,
|
BBReferenceFieldSubType,
|
||||||
JsonFieldSubType,
|
JsonFieldSubType,
|
||||||
AutoFieldSubType,
|
AutoFieldSubType,
|
||||||
|
CreateViewRequest,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { LoopInput } from "../../definitions/automations"
|
import { LoopInput } from "../../definitions/automations"
|
||||||
import { merge } from "lodash"
|
import { merge } from "lodash"
|
||||||
|
@ -145,6 +146,17 @@ export function view(tableId: string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function viewV2CreateRequest(tableId: string): CreateViewRequest {
|
||||||
|
return {
|
||||||
|
tableId,
|
||||||
|
name: generator.guid(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const viewV2 = {
|
||||||
|
createRequest: viewV2CreateRequest,
|
||||||
|
}
|
||||||
|
|
||||||
export function automationStep(
|
export function automationStep(
|
||||||
actionDefinition = BUILTIN_ACTION_DEFINITIONS.CREATE_ROW
|
actionDefinition = BUILTIN_ACTION_DEFINITIONS.CREATE_ROW
|
||||||
): AutomationStep {
|
): AutomationStep {
|
||||||
|
|
Loading…
Reference in New Issue