mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-30 20:31:34 +02:00
Migrate joinProject to zod
GitOrigin-RevId: 8c03002adfdf47a7f83ad3dde32428d29abd9bb9
This commit is contained in:
@@ -11,6 +11,7 @@ import Errors from '../Errors/Errors.js'
|
||||
import { expressify } from '@overleaf/promise-utils'
|
||||
import Settings from '@overleaf/settings'
|
||||
import CollaboratorsGetter from '../Collaborators/CollaboratorsGetter.js'
|
||||
import { z, zz, validateReq } from '../../infrastructure/Validation.js'
|
||||
|
||||
const ProjectAccess = CollaboratorsGetter.ProjectAccess
|
||||
|
||||
@@ -27,9 +28,20 @@ export default {
|
||||
_nameIsAcceptableLength,
|
||||
}
|
||||
|
||||
const joinProjectSchema = z.object({
|
||||
params: z.object({
|
||||
Project_id: zz.objectId(),
|
||||
}),
|
||||
body: z.object({
|
||||
userId: z.string(),
|
||||
anonymousAccessToken: z.string().optional(),
|
||||
}),
|
||||
})
|
||||
|
||||
async function joinProject(req, res, next) {
|
||||
const projectId = req.params.Project_id
|
||||
let userId = req.body.userId // keep schema in sync with router
|
||||
const { params, body } = validateReq(req, joinProjectSchema)
|
||||
const projectId = params.Project_id
|
||||
let userId = body.userId
|
||||
if (userId === 'anonymous-user') {
|
||||
userId = null
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ import AuthenticationController from '../Authentication/AuthenticationController
|
||||
import AuthorizationMiddleware from '../Authorization/AuthorizationMiddleware.mjs'
|
||||
import { RateLimiter } from '../../infrastructure/RateLimiter.js'
|
||||
import RateLimiterMiddleware from '../Security/RateLimiterMiddleware.js'
|
||||
import { validate, Joi } from '../../infrastructure/Validation.js'
|
||||
|
||||
const rateLimiters = {
|
||||
addDocToProject: new RateLimiter('add-doc-to-project', {
|
||||
@@ -74,12 +73,6 @@ export default {
|
||||
// keep schema in sync with controller
|
||||
getUserId: req => req.body.userId,
|
||||
}),
|
||||
validate({
|
||||
body: Joi.object({
|
||||
userId: Joi.string().required(),
|
||||
anonymousAccessToken: Joi.string().optional(),
|
||||
}),
|
||||
}),
|
||||
EditorHttpController.joinProject
|
||||
)
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user