From 6200d8d91710b03a72a27e35cbe6eed1e6cc8c62 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 16 May 2018 11:33:11 +0200 Subject: Fix video channel update with an admin account --- server/helpers/custom-validators/videos.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'server/helpers/custom-validators') diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index 002324fe0..0c268a684 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts @@ -3,7 +3,7 @@ import 'express-validator' import { values } from 'lodash' import 'multer' import * as validator from 'validator' -import { VideoRateType } from '../../../shared' +import { UserRight, VideoRateType } from '../../../shared' import { CONSTRAINTS_FIELDS, VIDEO_CATEGORIES, @@ -15,6 +15,7 @@ import { import { VideoModel } from '../../models/video/video' import { exists, isArray, isFileValid } from './misc' import { VideoChannelModel } from '../../models/video/video-channel' +import { UserModel } from '../../models/account/user' const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES @@ -127,8 +128,22 @@ async function isVideoExist (id: string, res: Response) { return true } -async function isVideoChannelOfAccountExist (channelId: number, accountId: number, res: Response) { - const videoChannel = await VideoChannelModel.loadByIdAndAccount(channelId, accountId) +async function isVideoChannelOfAccountExist (channelId: number, user: UserModel, res: Response) { + if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) { + const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId) + if (!videoChannel) { + res.status(400) + .json({ error: 'Unknown video video channel on this instance.' }) + .end() + + return false + } + + res.locals.videoChannel = videoChannel + return true + } + + const videoChannel = await VideoChannelModel.loadByIdAndAccount(channelId, user.Account.id) if (!videoChannel) { res.status(400) .json({ error: 'Unknown video video channel for this account.' }) -- cgit v1.2.3