Migrate setCollaboratorInfo to zod

GitOrigin-RevId: e65bb6e17115362e7521f3e234757aa812aa89bc
This commit is contained in:
Eric Mc Sween
2025-09-23 08:06:21 +00:00
committed by Copybot
parent 9cbeaf53f8
commit f19ced47cb
2 changed files with 20 additions and 18 deletions
@@ -14,6 +14,8 @@ import { hasAdminAccess } from '../Helpers/AdminAuthorizationHelper.js'
import TokenAccessHandler from '../TokenAccess/TokenAccessHandler.js' import TokenAccessHandler from '../TokenAccess/TokenAccessHandler.js'
import ProjectAuditLogHandler from '../Project/ProjectAuditLogHandler.mjs' import ProjectAuditLogHandler from '../Project/ProjectAuditLogHandler.mjs'
import LimitationsManager from '../Subscription/LimitationsManager.js' import LimitationsManager from '../Subscription/LimitationsManager.js'
import PrivilegeLevels from '../Authorization/PrivilegeLevels.js'
import { z, zz, validateReq } from '../../infrastructure/Validation.js'
import Features from '../../infrastructure/Features.js' import Features from '../../infrastructure/Features.js'
const ObjectId = mongodb.ObjectId const ObjectId = mongodb.ObjectId
@@ -74,11 +76,26 @@ async function getAllMembers(req, res, next) {
res.json({ members }) res.json({ members })
} }
const setCollaboratorInfoSchema = z.object({
params: z.object({
Project_id: zz.objectId(),
user_id: zz.objectId(),
}),
body: z.object({
privilegeLevel: z.enum([
PrivilegeLevels.READ_ONLY,
PrivilegeLevels.READ_AND_WRITE,
PrivilegeLevels.REVIEW,
]),
}),
})
async function setCollaboratorInfo(req, res, next) { async function setCollaboratorInfo(req, res, next) {
try { try {
const projectId = req.params.Project_id const { params, body } = validateReq(req, setCollaboratorInfoSchema)
const userId = req.params.user_id const projectId = params.Project_id
const { privilegeLevel } = req.body const userId = params.user_id
const { privilegeLevel } = body
const allowed = const allowed =
await LimitationsManager.promises.canChangeCollaboratorPrivilegeLevel( await LimitationsManager.promises.canChangeCollaboratorPrivilegeLevel(
@@ -43,21 +43,6 @@ export default {
webRouter.put( webRouter.put(
'/project/:Project_id/users/:user_id', '/project/:Project_id/users/:user_id',
AuthenticationController.requireLogin(), AuthenticationController.requireLogin(),
validate({
params: Joi.object({
Project_id: Joi.objectId(),
user_id: Joi.objectId(),
}),
body: Joi.object({
privilegeLevel: Joi.string()
.valid(
PrivilegeLevels.READ_ONLY,
PrivilegeLevels.READ_AND_WRITE,
PrivilegeLevels.REVIEW
)
.required(),
}),
}),
AuthorizationMiddleware.ensureUserCanAdminProject, AuthorizationMiddleware.ensureUserCanAdminProject,
CollaboratorsController.setCollaboratorInfo CollaboratorsController.setCollaboratorInfo
) )