mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 06:33:55 +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 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
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user