Split authorized middleware to handle resource id fetch
This commit is contained in:
parent
b4a824a843
commit
9a15277fa1
|
@ -1,10 +1,11 @@
|
||||||
import Router from "@koa/router"
|
import Router from "@koa/router"
|
||||||
import * as rowController from "../controllers/row"
|
import * as rowController from "../controllers/row"
|
||||||
import authorized from "../../middleware/authorized"
|
import authorized, { authorizedResource } from "../../middleware/authorized"
|
||||||
import { paramResource, paramSubResource } from "../../middleware/resourceId"
|
import { paramResource, paramSubResource } from "../../middleware/resourceId"
|
||||||
import { permissions } from "@budibase/backend-core"
|
import { permissions } from "@budibase/backend-core"
|
||||||
import { internalSearchValidator } from "./utils/validators"
|
import { internalSearchValidator } from "./utils/validators"
|
||||||
import trimViewRowInfo from "../../middleware/trimViewRowInfo"
|
import trimViewRowInfo from "../../middleware/trimViewRowInfo"
|
||||||
|
import { extractViewInfoFromID } from "../../db/utils"
|
||||||
const { PermissionType, PermissionLevel } = permissions
|
const { PermissionType, PermissionLevel } = permissions
|
||||||
|
|
||||||
const router: Router = new Router()
|
const router: Router = new Router()
|
||||||
|
@ -269,7 +270,8 @@ router
|
||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
"/api/v2/views/:viewId/search",
|
"/api/v2/views/:viewId/search",
|
||||||
authorized(PermissionType.TABLE, PermissionLevel.READ),
|
paramResource("viewId", val => extractViewInfoFromID(val).tableId),
|
||||||
|
authorizedResource(PermissionType.TABLE, PermissionLevel.READ),
|
||||||
rowController.views.searchView
|
rowController.views.searchView
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,8 @@ const checkAuthorizedResource = async (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default (
|
const authorized =
|
||||||
|
(
|
||||||
permType: PermissionType,
|
permType: PermissionType,
|
||||||
permLevel?: PermissionLevel,
|
permLevel?: PermissionLevel,
|
||||||
opts = { schema: false }
|
opts = { schema: false }
|
||||||
|
@ -143,3 +144,14 @@ export default (
|
||||||
// csrf protection
|
// csrf protection
|
||||||
return csrf(ctx, next)
|
return csrf(ctx, next)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default (
|
||||||
|
permType: PermissionType,
|
||||||
|
permLevel?: PermissionLevel,
|
||||||
|
opts = { schema: false }
|
||||||
|
) => authorized(permType, permLevel, opts)
|
||||||
|
|
||||||
|
export const authorizedResource = (
|
||||||
|
permType: PermissionType,
|
||||||
|
permLevel?: PermissionLevel
|
||||||
|
) => authorized(permType, permLevel)
|
||||||
|
|
|
@ -43,6 +43,7 @@ export class ResourceIdGetter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @deprecated we should use the authorizedResource middleware instead */
|
||||||
export function paramResource(main: string) {
|
export function paramResource(main: string) {
|
||||||
return new ResourceIdGetter("params").mainResource(main).build()
|
return new ResourceIdGetter("params").mainResource(main).build()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue