1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 10:19:35 +02:00

Add user update for admins

This commit is contained in:
Chocobozzz 2017-09-05 21:29:39 +02:00
parent 980246ea8f
commit 8094a89802
21 changed files with 290 additions and 51 deletions

View file

@ -53,16 +53,35 @@ function usersRemoveValidator (req: express.Request, res: express.Response, next
function usersUpdateValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
req.checkParams('id', 'Should have a valid id').notEmpty().isInt()
// Add old password verification
req.checkBody('password', 'Should have a valid password').optional().isUserPasswordValid()
req.checkBody('displayNSFW', 'Should have a valid display Not Safe For Work attribute').optional().isUserDisplayNSFWValid()
req.checkBody('email', 'Should have a valid email attribute').optional().isEmail()
req.checkBody('videoQuota', 'Should have a valid user quota').optional().isUserVideoQuotaValid()
logger.debug('Checking usersUpdate parameters', { parameters: req.body })
checkErrors(req, res, () => {
checkUserExists(req.params.id, res, next)
})
}
function usersUpdateMeValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
// Add old password verification
req.checkBody('password', 'Should have a valid password').optional().isUserPasswordValid()
req.checkBody('email', 'Should have a valid email attribute').optional().isEmail()
req.checkBody('displayNSFW', 'Should have a valid display Not Safe For Work attribute').optional().isUserDisplayNSFWValid()
logger.debug('Checking usersUpdate parameters', { parameters: req.body })
checkErrors(req, res, next)
}
function usersGetValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
req.checkParams('id', 'Should have a valid id').notEmpty().isInt()
checkErrors(req, res, () => {
checkUserExists(req.params.id, res, next)
})
}
function usersVideoRatingValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
req.checkParams('videoId', 'Should have a valid video id').notEmpty().isVideoIdOrUUIDValid()
@ -106,6 +125,24 @@ export {
usersAddValidator,
usersRemoveValidator,
usersUpdateValidator,
usersUpdateMeValidator,
usersVideoRatingValidator,
ensureUserRegistrationAllowed
ensureUserRegistrationAllowed,
usersGetValidator
}
// ---------------------------------------------------------------------------
function checkUserExists (id: number, res: express.Response, callback: () => void) {
db.User.loadById(id)
.then(user => {
if (!user) return res.status(404).send('User not found')
res.locals.user = user
callback()
})
.catch(err => {
logger.error('Error in user request validator.', err)
return res.sendStatus(500)
})
}