diff options
Diffstat (limited to 'server/middlewares/validators/video-channels.ts')
-rw-r--r-- | server/middlewares/validators/video-channels.ts | 31 |
1 files changed, 3 insertions, 28 deletions
diff --git a/server/middlewares/validators/video-channels.ts b/server/middlewares/validators/video-channels.ts index 068fd210f..cc7d54c06 100644 --- a/server/middlewares/validators/video-channels.ts +++ b/server/middlewares/validators/video-channels.ts | |||
@@ -3,7 +3,7 @@ import { body, param } from 'express-validator/check' | |||
3 | import { UserRight } from '../../../shared' | 3 | import { UserRight } from '../../../shared' |
4 | import { logger } from '../../helpers' | 4 | import { logger } from '../../helpers' |
5 | import { isAccountIdExist } from '../../helpers/custom-validators/accounts' | 5 | import { isAccountIdExist } from '../../helpers/custom-validators/accounts' |
6 | import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc' | 6 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' |
7 | import { | 7 | import { |
8 | isVideoChannelDescriptionValid, | 8 | isVideoChannelDescriptionValid, |
9 | isVideoChannelExist, | 9 | isVideoChannelExist, |
@@ -11,7 +11,6 @@ import { | |||
11 | } from '../../helpers/custom-validators/video-channels' | 11 | } from '../../helpers/custom-validators/video-channels' |
12 | import { UserModel } from '../../models/account/user' | 12 | import { UserModel } from '../../models/account/user' |
13 | import { VideoChannelModel } from '../../models/video/video-channel' | 13 | import { VideoChannelModel } from '../../models/video/video-channel' |
14 | import { VideoChannelShareModel } from '../../models/video/video-channel-share' | ||
15 | import { areValidationErrors } from './utils' | 14 | import { areValidationErrors } from './utils' |
16 | 15 | ||
17 | const listVideoAccountChannelsValidator = [ | 16 | const listVideoAccountChannelsValidator = [ |
@@ -98,28 +97,6 @@ const videoChannelsGetValidator = [ | |||
98 | } | 97 | } |
99 | ] | 98 | ] |
100 | 99 | ||
101 | const videoChannelsShareValidator = [ | ||
102 | param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), | ||
103 | param('accountId').custom(isIdValid).not().isEmpty().withMessage('Should have a valid account id'), | ||
104 | |||
105 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
106 | logger.debug('Checking videoChannelShare parameters', { parameters: req.params }) | ||
107 | |||
108 | if (areValidationErrors(req, res)) return | ||
109 | if (!await isVideoChannelExist(req.params.id, res)) return | ||
110 | |||
111 | const share = await VideoChannelShareModel.load(res.locals.video.id, req.params.accountId, undefined) | ||
112 | if (!share) { | ||
113 | return res.status(404) | ||
114 | .end() | ||
115 | } | ||
116 | |||
117 | res.locals.videoChannelShare = share | ||
118 | |||
119 | return next() | ||
120 | } | ||
121 | ] | ||
122 | |||
123 | // --------------------------------------------------------------------------- | 100 | // --------------------------------------------------------------------------- |
124 | 101 | ||
125 | export { | 102 | export { |
@@ -127,15 +104,13 @@ export { | |||
127 | videoChannelsAddValidator, | 104 | videoChannelsAddValidator, |
128 | videoChannelsUpdateValidator, | 105 | videoChannelsUpdateValidator, |
129 | videoChannelsRemoveValidator, | 106 | videoChannelsRemoveValidator, |
130 | videoChannelsGetValidator, | 107 | videoChannelsGetValidator |
131 | videoChannelsShareValidator | ||
132 | } | 108 | } |
133 | 109 | ||
134 | // --------------------------------------------------------------------------- | 110 | // --------------------------------------------------------------------------- |
135 | 111 | ||
136 | function checkUserCanDeleteVideoChannel (user: UserModel, videoChannel: VideoChannelModel, res: express.Response) { | 112 | function checkUserCanDeleteVideoChannel (user: UserModel, videoChannel: VideoChannelModel, res: express.Response) { |
137 | // Retrieve the user who did the request | 113 | if (videoChannel.Actor.isOwned() === false) { |
138 | if (videoChannel.isOwned() === false) { | ||
139 | res.status(403) | 114 | res.status(403) |
140 | .json({ error: 'Cannot remove video channel of another server.' }) | 115 | .json({ error: 'Cannot remove video channel of another server.' }) |
141 | .end() | 116 | .end() |