mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-30 20:31:34 +02:00
Migrate UserMembershipMiddleware.fetchEntity to zod
GitOrigin-RevId: 6f0cac9d3ba1f0d3de69609e19f3d36a1a9ded10
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
// @ts-check
|
||||
|
||||
const { expressify } = require('@overleaf/promise-utils')
|
||||
const async = require('async')
|
||||
const UserMembershipAuthorization = require('./UserMembershipAuthorization')
|
||||
@@ -7,6 +9,7 @@ const EntityConfigs = require('./UserMembershipEntityConfigs')
|
||||
const Errors = require('../Errors/Errors')
|
||||
const HttpErrorHandler = require('../Errors/HttpErrorHandler')
|
||||
const TemplatesManager = require('../Templates/TemplatesManager')
|
||||
const { z, zz, validateReq } = require('../../infrastructure/Validation')
|
||||
const { useAdminCapabilities } = require('../Helpers/AdminAuthorizationHelper')
|
||||
|
||||
// set of middleware arrays or functions that checks user access to an entity
|
||||
@@ -244,11 +247,18 @@ function fetchEntityConfig(entityName) {
|
||||
}
|
||||
|
||||
// fetch the entity with id and config, and set it in the request
|
||||
const fetchEntitySchema = z.object({
|
||||
params: z.object({
|
||||
id: zz.objectId(),
|
||||
}),
|
||||
})
|
||||
|
||||
function fetchEntity() {
|
||||
return expressify(async (req, res, next) => {
|
||||
const { params } = validateReq(req, fetchEntitySchema)
|
||||
req.entity =
|
||||
await UserMembershipHandler.promises.getEntityWithoutAuthorizationCheck(
|
||||
req.params.id,
|
||||
params.id,
|
||||
req.entityConfig
|
||||
)
|
||||
next()
|
||||
|
||||
Reference in New Issue
Block a user