From 38fa2065831b5f55be0d7f30f19a62c967397208 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 10 Nov 2017 14:48:08 +0100 Subject: Remove references to author --- server/middlewares/validators/video-channels.ts | 20 ++++++++++---------- server/middlewares/validators/videos.ts | 14 +++++++------- 2 files changed, 17 insertions(+), 17 deletions(-) (limited to 'server/middlewares') diff --git a/server/middlewares/validators/video-channels.ts b/server/middlewares/validators/video-channels.ts index 7d611728b..53416a857 100644 --- a/server/middlewares/validators/video-channels.ts +++ b/server/middlewares/validators/video-channels.ts @@ -9,19 +9,19 @@ import { isVideoChannelDescriptionValid, isVideoChannelNameValid, checkVideoChannelExists, - checkVideoAuthorExists + checkVideoAccountExists } from '../../helpers' import { UserInstance } from '../../models' import { UserRight } from '../../../shared' -const listVideoAuthorChannelsValidator = [ - param('authorId').custom(isIdOrUUIDValid).withMessage('Should have a valid author id'), +const listVideoAccountChannelsValidator = [ + param('accountId').custom(isIdOrUUIDValid).withMessage('Should have a valid account id'), (req: express.Request, res: express.Response, next: express.NextFunction) => { - logger.debug('Checking listVideoAuthorChannelsValidator parameters', { parameters: req.body }) + logger.debug('Checking listVideoAccountChannelsValidator parameters', { parameters: req.body }) checkErrors(req, res, () => { - checkVideoAuthorExists(req.params.authorId, res, next) + checkVideoAccountExists(req.params.accountId, res, next) }) } ] @@ -54,7 +54,7 @@ const videoChannelsUpdateValidator = [ .end() } - if (res.locals.videoChannel.Author.userId !== res.locals.oauth.token.User.id) { + if (res.locals.videoChannel.Account.userId !== res.locals.oauth.token.User.id) { return res.status(403) .json({ error: 'Cannot update video channel of another user' }) .end() @@ -98,7 +98,7 @@ const videoChannelGetValidator = [ // --------------------------------------------------------------------------- export { - listVideoAuthorChannelsValidator, + listVideoAccountChannelsValidator, videoChannelsAddValidator, videoChannelsUpdateValidator, videoChannelsRemoveValidator, @@ -119,8 +119,8 @@ function checkUserCanDeleteVideoChannel (res: express.Response, callback: () => // Check if the user can delete the video channel // The user can delete it if s/he is an admin - // Or if s/he is the video channel's author - if (user.hasRight(UserRight.REMOVE_ANY_VIDEO_CHANNEL) === false && res.locals.videoChannel.Author.userId !== user.id) { + // Or if s/he is the video channel's account + if (user.hasRight(UserRight.REMOVE_ANY_VIDEO_CHANNEL) === false && res.locals.videoChannel.Account.userId !== user.id) { return res.status(403) .json({ error: 'Cannot remove video channel of another user' }) .end() @@ -131,7 +131,7 @@ function checkUserCanDeleteVideoChannel (res: express.Response, callback: () => } function checkVideoChannelIsNotTheLastOne (res: express.Response, callback: () => void) { - db.VideoChannel.countByAuthor(res.locals.oauth.token.User.Author.id) + db.VideoChannel.countByAccount(res.locals.oauth.token.User.Account.id) .then(count => { if (count <= 1) { return res.status(409) diff --git a/server/middlewares/validators/videos.ts b/server/middlewares/validators/videos.ts index 15b4629c1..10b426df3 100644 --- a/server/middlewares/validators/videos.ts +++ b/server/middlewares/validators/videos.ts @@ -48,11 +48,11 @@ const videosAddValidator = [ const videoFile: Express.Multer.File = req.files['videofile'][0] const user = res.locals.oauth.token.User - return db.VideoChannel.loadByIdAndAuthor(req.body.channelId, user.Author.id) + return db.VideoChannel.loadByIdAndAccount(req.body.channelId, user.Account.id) .then(videoChannel => { if (!videoChannel) { res.status(400) - .json({ error: 'Unknown video video channel for this author.' }) + .json({ error: 'Unknown video video channel for this account.' }) .end() return undefined @@ -131,7 +131,7 @@ const videosUpdateValidator = [ .end() } - if (video.VideoChannel.Author.userId !== res.locals.oauth.token.User.id) { + if (video.VideoChannel.Account.userId !== res.locals.oauth.token.User.id) { return res.status(403) .json({ error: 'Cannot update video of another user' }) .end() @@ -163,7 +163,7 @@ const videosGetValidator = [ if (video.privacy !== VideoPrivacy.PRIVATE) return next() authenticate(req, res, () => { - if (video.VideoChannel.Author.userId !== res.locals.oauth.token.User.id) { + if (video.VideoChannel.Account.userId !== res.locals.oauth.token.User.id) { return res.status(403) .json({ error: 'Cannot get this private video of another user' }) .end() @@ -256,10 +256,10 @@ function checkUserCanDeleteVideo (userId: number, res: express.Response, callbac // Check if the user can delete the video // The user can delete it if s/he is an admin - // Or if s/he is the video's author - const author = res.locals.video.VideoChannel.Author + // Or if s/he is the video's account + const account = res.locals.video.VideoChannel.Account const user = res.locals.oauth.token.User - if (user.hasRight(UserRight.REMOVE_ANY_VIDEO) === false && author.userId !== user.id) { + if (user.hasRight(UserRight.REMOVE_ANY_VIDEO) === false && account.userId !== user.id) { return res.status(403) .json({ error: 'Cannot remove video of another user' }) .end() -- cgit v1.2.3