Crud endpoints only for builder
This commit is contained in:
parent
98347b45ce
commit
922b746029
|
@ -2,9 +2,9 @@ import Router from "@koa/router"
|
||||||
import Joi from "joi"
|
import Joi from "joi"
|
||||||
import { middleware, permissions } from "@budibase/backend-core"
|
import { middleware, permissions } from "@budibase/backend-core"
|
||||||
import * as rowActionController from "../controllers/rowAction"
|
import * as rowActionController from "../controllers/rowAction"
|
||||||
import { authorizedResource } from "../../middleware/authorized"
|
import authorized, { authorizedResource } from "../../middleware/authorized"
|
||||||
|
|
||||||
const { PermissionLevel, PermissionType } = permissions
|
const { PermissionLevel, PermissionType, BUILDER } = permissions
|
||||||
|
|
||||||
function rowActionValidator() {
|
function rowActionValidator() {
|
||||||
return middleware.joiValidator.body(
|
return middleware.joiValidator.body(
|
||||||
|
@ -30,34 +30,34 @@ const router: Router = new Router()
|
||||||
router
|
router
|
||||||
.get(
|
.get(
|
||||||
"/api/tables/:tableId/actions",
|
"/api/tables/:tableId/actions",
|
||||||
authorizedResource(PermissionType.TABLE, PermissionLevel.READ, "tableId"),
|
authorized(BUILDER),
|
||||||
rowActionController.find
|
rowActionController.find
|
||||||
)
|
)
|
||||||
.post(
|
.post(
|
||||||
"/api/tables/:tableId/actions",
|
"/api/tables/:tableId/actions",
|
||||||
authorizedResource(PermissionType.TABLE, PermissionLevel.READ, "tableId"),
|
authorized(BUILDER),
|
||||||
rowActionValidator(),
|
rowActionValidator(),
|
||||||
rowActionController.create
|
rowActionController.create
|
||||||
)
|
)
|
||||||
.put(
|
.put(
|
||||||
"/api/tables/:tableId/actions/:actionId",
|
"/api/tables/:tableId/actions/:actionId",
|
||||||
authorizedResource(PermissionType.TABLE, PermissionLevel.READ, "tableId"),
|
authorized(BUILDER),
|
||||||
rowActionValidator(),
|
rowActionValidator(),
|
||||||
rowActionController.update
|
rowActionController.update
|
||||||
)
|
)
|
||||||
.delete(
|
.delete(
|
||||||
"/api/tables/:tableId/actions/:actionId",
|
"/api/tables/:tableId/actions/:actionId",
|
||||||
authorizedResource(PermissionType.TABLE, PermissionLevel.READ, "tableId"),
|
authorized(BUILDER),
|
||||||
rowActionController.remove
|
rowActionController.remove
|
||||||
)
|
)
|
||||||
.post(
|
.post(
|
||||||
"/api/tables/:tableId/actions/:actionId/permissions/:viewId",
|
"/api/tables/:tableId/actions/:actionId/permissions/:viewId",
|
||||||
authorizedResource(PermissionType.TABLE, PermissionLevel.READ, "tableId"),
|
authorized(BUILDER),
|
||||||
rowActionController.setViewPermission
|
rowActionController.setViewPermission
|
||||||
)
|
)
|
||||||
.delete(
|
.delete(
|
||||||
"/api/tables/:tableId/actions/:actionId/permissions/:viewId",
|
"/api/tables/:tableId/actions/:actionId/permissions/:viewId",
|
||||||
authorizedResource(PermissionType.TABLE, PermissionLevel.READ, "tableId"),
|
authorized(BUILDER),
|
||||||
rowActionController.unsetViewPermission
|
rowActionController.unsetViewPermission
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -4,11 +4,13 @@ import tk from "timekeeper"
|
||||||
import {
|
import {
|
||||||
CreateRowActionRequest,
|
CreateRowActionRequest,
|
||||||
DocumentType,
|
DocumentType,
|
||||||
|
PermissionLevel,
|
||||||
RowActionResponse,
|
RowActionResponse,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import * as setup from "./utilities"
|
import * as setup from "./utilities"
|
||||||
import { generator } from "@budibase/backend-core/tests"
|
import { generator } from "@budibase/backend-core/tests"
|
||||||
import { Expectations } from "../../../tests/utilities/api/base"
|
import { Expectations } from "../../../tests/utilities/api/base"
|
||||||
|
import { roles } from "@budibase/backend-core"
|
||||||
|
|
||||||
const expectAutomationId = () =>
|
const expectAutomationId = () =>
|
||||||
expect.stringMatching(`^${DocumentType.AUTOMATION}_.+`)
|
expect.stringMatching(`^${DocumentType.AUTOMATION}_.+`)
|
||||||
|
@ -69,6 +71,31 @@ describe("/rowsActions", () => {
|
||||||
await config.withUser(user, async () => {
|
await config.withUser(user, async () => {
|
||||||
await createRowAction(generator.guid(), createRowActionRequest(), {
|
await createRowAction(generator.guid(), createRowActionRequest(), {
|
||||||
status: 403,
|
status: 403,
|
||||||
|
body: {
|
||||||
|
message: "Not Authorized",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns forbidden (403) for non-builder users even if they have table write permissions", async () => {
|
||||||
|
const user = await config.createUser({
|
||||||
|
builder: {},
|
||||||
|
})
|
||||||
|
const tableId = generator.guid()
|
||||||
|
for (const role of Object.values(roles.BUILTIN_ROLE_IDS)) {
|
||||||
|
await config.api.permission.add({
|
||||||
|
roleId: role,
|
||||||
|
resourceId: tableId,
|
||||||
|
level: PermissionLevel.EXECUTE,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
await config.withUser(user, async () => {
|
||||||
|
await createRowAction(tableId, createRowActionRequest(), {
|
||||||
|
status: 403,
|
||||||
|
body: {
|
||||||
|
message: "Not Authorized",
|
||||||
|
},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue