From 299474e8279675adb6c5ce140e7e39c6f3439453 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 2 Aug 2018 16:33:29 +0200 Subject: Add ability to remove a video import --- server/middlewares/validators/video-imports.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'server/middlewares') diff --git a/server/middlewares/validators/video-imports.ts b/server/middlewares/validators/video-imports.ts index 0ba759ff0..0dedcf803 100644 --- a/server/middlewares/validators/video-imports.ts +++ b/server/middlewares/validators/video-imports.ts @@ -4,9 +4,11 @@ import { isIdValid } from '../../helpers/custom-validators/misc' import { logger } from '../../helpers/logger' import { areValidationErrors } from './utils' import { getCommonVideoAttributes } from './videos' -import { isVideoImportTargetUrlValid } from '../../helpers/custom-validators/video-imports' +import { isVideoImportTargetUrlValid, isVideoImportExist } from '../../helpers/custom-validators/video-imports' import { cleanUpReqFiles } from '../../helpers/utils' -import { isVideoChannelOfAccountExist, isVideoNameValid } from '../../helpers/custom-validators/videos' +import { isVideoChannelOfAccountExist, isVideoNameValid, checkUserCanManageVideo } from '../../helpers/custom-validators/videos' +import { VideoImportModel } from '../../models/video/video-import' +import { UserRight } from '../../../shared' const videoImportAddValidator = getCommonVideoAttributes().concat([ body('targetUrl').custom(isVideoImportTargetUrlValid).withMessage('Should have a valid video import target URL'), @@ -32,10 +34,16 @@ const videoImportAddValidator = getCommonVideoAttributes().concat([ const videoImportDeleteValidator = [ param('id').custom(isIdValid).not().isEmpty().withMessage('Should have a valid id'), - (req: express.Request, res: express.Response, next: express.NextFunction) => { + async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking videoImportDeleteValidator parameters', { parameters: req.body }) if (areValidationErrors(req, res)) return + if (!await isVideoImportExist(req.params.id, res)) return + + const user = res.locals.oauth.token.User + const videoImport: VideoImportModel = res.locals.videoImport + + if (!await checkUserCanManageVideo(user, videoImport.Video, UserRight.UPDATE_ANY_VIDEO, res)) return return next() } -- cgit v1.2.3