From baf806275bbc59f01fb0bf286251708e950628a9 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 22 Feb 2022 17:38:27 +0000 Subject: [PATCH] Getting prettier running on the public routes. --- .prettierignore | 3 +- .../api/controllers/public/applications.js | 20 +++------- .../src/api/controllers/public/queries.js | 8 +--- .../server/src/api/controllers/public/rows.js | 17 ++++----- .../src/api/controllers/public/tables.js | 20 +++------- .../src/api/controllers/public/users.js | 20 +++------- .../server/src/api/routes/public/index.js | 11 ++---- packages/server/src/api/routes/public/rows.js | 38 ++++++++++++++++--- packages/server/src/api/routes/row.js | 1 + 9 files changed, 64 insertions(+), 74 deletions(-) diff --git a/.prettierignore b/.prettierignore index 522d218640..00ee85f781 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,9 +1,8 @@ node_modules -public dist *.spec.js packages/builder/src/components/design/AppPreview/CurrentItemPreview.svelte packages/server/builder packages/server/coverage packages/server/client -packages/builder/.routify \ No newline at end of file +packages/builder/.routify diff --git a/packages/server/src/api/controllers/public/applications.js b/packages/server/src/api/controllers/public/applications.js index 6698018aa7..459e314bbf 100644 --- a/packages/server/src/api/controllers/public/applications.js +++ b/packages/server/src/api/controllers/public/applications.js @@ -1,19 +1,9 @@ -exports.search = () => { +exports.search = () => {} -} +exports.create = () => {} -exports.create = () => { +exports.read = () => {} -} +exports.update = () => {} -exports.read = () => { - -} - -exports.update = () => { - -} - -exports.delete = () => { - -} \ No newline at end of file +exports.delete = () => {} diff --git a/packages/server/src/api/controllers/public/queries.js b/packages/server/src/api/controllers/public/queries.js index 781b8414e2..09775340aa 100644 --- a/packages/server/src/api/controllers/public/queries.js +++ b/packages/server/src/api/controllers/public/queries.js @@ -1,7 +1,3 @@ -exports.search = () => { +exports.search = () => {} -} - -exports.execute = () => { - -} +exports.execute = () => {} diff --git a/packages/server/src/api/controllers/public/rows.js b/packages/server/src/api/controllers/public/rows.js index c2e2188b68..3c5e8e677c 100644 --- a/packages/server/src/api/controllers/public/rows.js +++ b/packages/server/src/api/controllers/public/rows.js @@ -1,3 +1,5 @@ +const rowController = require("../row") + // makes sure that the user doesn't need to pass in the type, tableId or _id params for // the call to be correct function fixRow(row, params) { @@ -16,22 +18,19 @@ function fixRow(row, params) { return row } -exports.search = () => { - +exports.search = async ctx => { + await rowController.search(ctx) + console.log(ctx.body) } -exports.create = () => { +exports.create = ctx => { ctx.request.body = fixRow(ctx.request.body, ctx.params) } -exports.read = () => { - -} +exports.read = () => {} exports.update = async ctx => { ctx.request.body = fixRow(ctx.request.body, ctx.params) } -exports.delete = () => { - -} \ No newline at end of file +exports.delete = () => {} diff --git a/packages/server/src/api/controllers/public/tables.js b/packages/server/src/api/controllers/public/tables.js index 6698018aa7..459e314bbf 100644 --- a/packages/server/src/api/controllers/public/tables.js +++ b/packages/server/src/api/controllers/public/tables.js @@ -1,19 +1,9 @@ -exports.search = () => { +exports.search = () => {} -} +exports.create = () => {} -exports.create = () => { +exports.read = () => {} -} +exports.update = () => {} -exports.read = () => { - -} - -exports.update = () => { - -} - -exports.delete = () => { - -} \ No newline at end of file +exports.delete = () => {} diff --git a/packages/server/src/api/controllers/public/users.js b/packages/server/src/api/controllers/public/users.js index 6698018aa7..459e314bbf 100644 --- a/packages/server/src/api/controllers/public/users.js +++ b/packages/server/src/api/controllers/public/users.js @@ -1,19 +1,9 @@ -exports.search = () => { +exports.search = () => {} -} +exports.create = () => {} -exports.create = () => { +exports.read = () => {} -} +exports.update = () => {} -exports.read = () => { - -} - -exports.update = () => { - -} - -exports.delete = () => { - -} \ No newline at end of file +exports.delete = () => {} diff --git a/packages/server/src/api/routes/public/index.js b/packages/server/src/api/routes/public/index.js index a4dc684771..e52c9f8291 100644 --- a/packages/server/src/api/routes/public/index.js +++ b/packages/server/src/api/routes/public/index.js @@ -4,20 +4,17 @@ const tableRoute = require("./tables") const rowRoute = require("./rows") const userRoute = require("./users") const Router = require("@koa/router") +const usage = require("../../../middleware/usageQuota") const PREFIX = "/api/public/v1" -const ROUTES = [ - appRoute, - queryRoute, - tableRoute, - rowRoute, - userRoute -] +const ROUTES = [appRoute, queryRoute, tableRoute, rowRoute, userRoute] const router = new Router({ prefix: PREFIX, }) for (let route of ROUTES) { + // apply usage to everything, middleware will work out whats needs it + route.use(usage) router.use(route.routes()) router.use(route.allowedMethods()) } diff --git a/packages/server/src/api/routes/public/rows.js b/packages/server/src/api/routes/public/rows.js index 2d011e22ca..45d9f25027 100644 --- a/packages/server/src/api/routes/public/rows.js +++ b/packages/server/src/api/routes/public/rows.js @@ -1,8 +1,16 @@ const Router = require("@koa/router") const controller = require("../../controllers/public/rows") +const authorized = require("../../../middleware/authorized") +const { paramSubResource } = require("../../../middleware/resourceId") +const { + PermissionLevels, + PermissionTypes, +} = require("@budibase/backend-core/permissions") const router = Router() +router.use(paramSubResource("tableId", "rowId")) + /** * @openapi * /tables/{tableId}/rows/search: @@ -119,7 +127,11 @@ const router = Router() * search: * $ref: '#/components/examples/rows' */ -router.post("/tables/:tableId/rows/search", controller.search) +router.post( + "/tables/:tableId/rows/search", + authorized(PermissionTypes.TABLE, PermissionLevels.READ), + controller.search +) /** * @openapi @@ -152,7 +164,11 @@ router.post("/tables/:tableId/rows/search", controller.search) * row: * $ref: '#/components/examples/row' */ -router.post("/tables/:tableId/rows", controller.create) +router.post( + "/tables/:tableId/rows", + authorized(PermissionTypes.TABLE, PermissionLevels.WRITE), + controller.create +) /** * @openapi @@ -185,7 +201,11 @@ router.post("/tables/:tableId/rows", controller.create) * row: * $ref: '#/components/examples/row' */ -router.put("/tables/:tableId/rows/:rowId", controller.update) +router.put( + "/tables/:tableId/rows/:rowId", + authorized(PermissionTypes.TABLE, PermissionLevels.WRITE), + controller.update +) /** * @openapi @@ -209,7 +229,11 @@ router.put("/tables/:tableId/rows/:rowId", controller.update) * row: * $ref: '#/components/examples/row' */ -router.delete("/tables/:tableId/rows/:rowId", controller.delete) +router.delete( + "/tables/:tableId/rows/:rowId", + authorized(PermissionTypes.TABLE, PermissionLevels.WRITE), + controller.delete +) /** * @openapi @@ -233,6 +257,10 @@ router.delete("/tables/:tableId/rows/:rowId", controller.delete) * row: * $ref: '#/components/examples/row' */ -router.get("/tables/:tableId/rows/:rowId", controller.read) +router.get( + "/tables/:tableId/rows/:rowId", + authorized(PermissionTypes.TABLE, PermissionLevels.READ), + controller.read +) module.exports = router diff --git a/packages/server/src/api/routes/row.js b/packages/server/src/api/routes/row.js index 802496833a..ef314ad0a4 100644 --- a/packages/server/src/api/routes/row.js +++ b/packages/server/src/api/routes/row.js @@ -193,6 +193,7 @@ router "/api/:tableId/rows", paramResource("tableId"), authorized(PermissionTypes.TABLE, PermissionLevels.WRITE), + usage, rowController.patch ) /**