mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-12 13:13:45 +01:00
Migrate setCollaboratorInfo to zod
GitOrigin-RevId: e65bb6e17115362e7521f3e234757aa812aa89bc
This commit is contained in:
@@ -14,6 +14,8 @@ import { hasAdminAccess } from '../Helpers/AdminAuthorizationHelper.js'
|
||||
import TokenAccessHandler from '../TokenAccess/TokenAccessHandler.js'
|
||||
import ProjectAuditLogHandler from '../Project/ProjectAuditLogHandler.mjs'
|
||||
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'
|
||||
|
||||
const ObjectId = mongodb.ObjectId
|
||||
@@ -74,11 +76,26 @@ async function getAllMembers(req, res, next) {
|
||||
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) {
|
||||
try {
|
||||
const projectId = req.params.Project_id
|
||||
const userId = req.params.user_id
|
||||
const { privilegeLevel } = req.body
|
||||
const { params, body } = validateReq(req, setCollaboratorInfoSchema)
|
||||
const projectId = params.Project_id
|
||||
const userId = params.user_id
|
||||
const { privilegeLevel } = body
|
||||
|
||||
const allowed =
|
||||
await LimitationsManager.promises.canChangeCollaboratorPrivilegeLevel(
|
||||
|
||||
@@ -43,21 +43,6 @@ export default {
|
||||
webRouter.put(
|
||||
'/project/:Project_id/users/:user_id',
|
||||
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,
|
||||
CollaboratorsController.setCollaboratorInfo
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user