aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/videos.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-05-16 11:33:11 +0200
committerChocobozzz <me@florianbigard.com>2018-05-17 10:55:49 +0200
commit6200d8d91710b03a72a27e35cbe6eed1e6cc8c62 (patch)
treeccd64f46009e45272d1a3426e206438cd5d50d4c /server/helpers/custom-validators/videos.ts
parenta14d3b6b23816299dba2c5e1010ea8f6eb3d3289 (diff)
downloadPeerTube-6200d8d91710b03a72a27e35cbe6eed1e6cc8c62.tar.gz
PeerTube-6200d8d91710b03a72a27e35cbe6eed1e6cc8c62.tar.zst
PeerTube-6200d8d91710b03a72a27e35cbe6eed1e6cc8c62.zip
Fix video channel update with an admin account
Diffstat (limited to 'server/helpers/custom-validators/videos.ts')
-rw-r--r--server/helpers/custom-validators/videos.ts21
1 files changed, 18 insertions, 3 deletions
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'
3import { values } from 'lodash' 3import { values } from 'lodash'
4import 'multer' 4import 'multer'
5import * as validator from 'validator' 5import * as validator from 'validator'
6import { VideoRateType } from '../../../shared' 6import { UserRight, VideoRateType } from '../../../shared'
7import { 7import {
8 CONSTRAINTS_FIELDS, 8 CONSTRAINTS_FIELDS,
9 VIDEO_CATEGORIES, 9 VIDEO_CATEGORIES,
@@ -15,6 +15,7 @@ import {
15import { VideoModel } from '../../models/video/video' 15import { VideoModel } from '../../models/video/video'
16import { exists, isArray, isFileValid } from './misc' 16import { exists, isArray, isFileValid } from './misc'
17import { VideoChannelModel } from '../../models/video/video-channel' 17import { VideoChannelModel } from '../../models/video/video-channel'
18import { UserModel } from '../../models/account/user'
18 19
19const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS 20const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS
20const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES 21const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES
@@ -127,8 +128,22 @@ async function isVideoExist (id: string, res: Response) {
127 return true 128 return true
128} 129}
129 130
130async function isVideoChannelOfAccountExist (channelId: number, accountId: number, res: Response) { 131async function isVideoChannelOfAccountExist (channelId: number, user: UserModel, res: Response) {
131 const videoChannel = await VideoChannelModel.loadByIdAndAccount(channelId, accountId) 132 if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) {
133 const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId)
134 if (!videoChannel) {
135 res.status(400)
136 .json({ error: 'Unknown video video channel on this instance.' })
137 .end()
138
139 return false
140 }
141
142 res.locals.videoChannel = videoChannel
143 return true
144 }
145
146 const videoChannel = await VideoChannelModel.loadByIdAndAccount(channelId, user.Account.id)
132 if (!videoChannel) { 147 if (!videoChannel) {
133 res.status(400) 148 res.status(400)
134 .json({ error: 'Unknown video video channel for this account.' }) 149 .json({ error: 'Unknown video video channel for this account.' })