diff options
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/custom-validators/videos.ts | 21 |
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' | |||
3 | import { values } from 'lodash' | 3 | import { values } from 'lodash' |
4 | import 'multer' | 4 | import 'multer' |
5 | import * as validator from 'validator' | 5 | import * as validator from 'validator' |
6 | import { VideoRateType } from '../../../shared' | 6 | import { UserRight, VideoRateType } from '../../../shared' |
7 | import { | 7 | import { |
8 | CONSTRAINTS_FIELDS, | 8 | CONSTRAINTS_FIELDS, |
9 | VIDEO_CATEGORIES, | 9 | VIDEO_CATEGORIES, |
@@ -15,6 +15,7 @@ import { | |||
15 | import { VideoModel } from '../../models/video/video' | 15 | import { VideoModel } from '../../models/video/video' |
16 | import { exists, isArray, isFileValid } from './misc' | 16 | import { exists, isArray, isFileValid } from './misc' |
17 | import { VideoChannelModel } from '../../models/video/video-channel' | 17 | import { VideoChannelModel } from '../../models/video/video-channel' |
18 | import { UserModel } from '../../models/account/user' | ||
18 | 19 | ||
19 | const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS | 20 | const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS |
20 | const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES | 21 | const 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 | ||
130 | async function isVideoChannelOfAccountExist (channelId: number, accountId: number, res: Response) { | 131 | async 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.' }) |