aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-17 15:45:42 +0200
committerChocobozzz <me@florianbigard.com>2018-08-27 09:41:54 +0200
commit8a19bee1a1ee39f973bb37429e4f73c3f2873cdb (patch)
tree33c93ef19451d7e46d4be74ce0681359d2dcc70e /server/middlewares
parent965c4b22d0e4d2f853501e844e6ebbb861bd389d (diff)
downloadPeerTube-8a19bee1a1ee39f973bb37429e4f73c3f2873cdb.tar.gz
PeerTube-8a19bee1a1ee39f973bb37429e4f73c3f2873cdb.tar.zst
PeerTube-8a19bee1a1ee39f973bb37429e4f73c3f2873cdb.zip
Add ability to set a name to a channel
Diffstat (limited to 'server/middlewares')
-rw-r--r--server/middlewares/validators/feeds.ts11
-rw-r--r--server/middlewares/validators/video-channels.ts23
2 files changed, 19 insertions, 15 deletions
diff --git a/server/middlewares/validators/feeds.ts b/server/middlewares/validators/feeds.ts
index 3c8532bd9..c1054ad9b 100644
--- a/server/middlewares/validators/feeds.ts
+++ b/server/middlewares/validators/feeds.ts
@@ -1,13 +1,13 @@
1import * as express from 'express' 1import * as express from 'express'
2import { param, query } from 'express-validator/check' 2import { param, query } from 'express-validator/check'
3import { isAccountIdExist, isAccountNameValid } from '../../helpers/custom-validators/accounts' 3import { isAccountIdExist, isAccountNameValid, isAccountNameWithHostExist } from '../../helpers/custom-validators/accounts'
4import { join } from 'path'
5import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' 4import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
6import { logger } from '../../helpers/logger' 5import { logger } from '../../helpers/logger'
7import { areValidationErrors } from './utils' 6import { areValidationErrors } from './utils'
8import { isValidRSSFeed } from '../../helpers/custom-validators/feeds' 7import { isValidRSSFeed } from '../../helpers/custom-validators/feeds'
9import { isVideoChannelExist } from '../../helpers/custom-validators/video-channels' 8import { isVideoChannelIdExist, isVideoChannelNameWithHostExist } from '../../helpers/custom-validators/video-channels'
10import { isVideoExist } from '../../helpers/custom-validators/videos' 9import { isVideoExist } from '../../helpers/custom-validators/videos'
10import { isActorPreferredUsernameValid } from '../../helpers/custom-validators/activitypub/actor'
11 11
12const videoFeedsValidator = [ 12const videoFeedsValidator = [
13 param('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'), 13 param('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'),
@@ -15,6 +15,7 @@ const videoFeedsValidator = [
15 query('accountId').optional().custom(isIdOrUUIDValid), 15 query('accountId').optional().custom(isIdOrUUIDValid),
16 query('accountName').optional().custom(isAccountNameValid), 16 query('accountName').optional().custom(isAccountNameValid),
17 query('videoChannelId').optional().custom(isIdOrUUIDValid), 17 query('videoChannelId').optional().custom(isIdOrUUIDValid),
18 query('videoChannelName').optional().custom(isActorPreferredUsernameValid),
18 19
19 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 20 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
20 logger.debug('Checking feeds parameters', { parameters: req.query }) 21 logger.debug('Checking feeds parameters', { parameters: req.query })
@@ -22,7 +23,9 @@ const videoFeedsValidator = [
22 if (areValidationErrors(req, res)) return 23 if (areValidationErrors(req, res)) return
23 24
24 if (req.query.accountId && !await isAccountIdExist(req.query.accountId, res)) return 25 if (req.query.accountId && !await isAccountIdExist(req.query.accountId, res)) return
25 if (req.query.videoChannelId && !await isVideoChannelExist(req.query.videoChannelId, res)) return 26 if (req.query.videoChannelName && !await isVideoChannelIdExist(req.query.videoChannelName, res)) return
27 if (req.query.accountName && !await isAccountNameWithHostExist(req.query.accountName, res)) return
28 if (req.query.videoChannelName && !await isVideoChannelNameWithHostExist(req.query.videoChannelName, res)) return
26 29
27 return next() 30 return next()
28 } 31 }
diff --git a/server/middlewares/validators/video-channels.ts b/server/middlewares/validators/video-channels.ts
index d354c7e05..79587b028 100644
--- a/server/middlewares/validators/video-channels.ts
+++ b/server/middlewares/validators/video-channels.ts
@@ -2,18 +2,18 @@ import * as express from 'express'
2import { body, param } from 'express-validator/check' 2import { body, param } from 'express-validator/check'
3import { UserRight } from '../../../shared' 3import { UserRight } from '../../../shared'
4import { isAccountNameWithHostExist } from '../../helpers/custom-validators/accounts' 4import { isAccountNameWithHostExist } from '../../helpers/custom-validators/accounts'
5import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
6import { 5import {
7 isLocalVideoChannelNameExist, 6 isLocalVideoChannelNameExist,
8 isVideoChannelDescriptionValid, 7 isVideoChannelDescriptionValid,
9 isVideoChannelExist,
10 isVideoChannelNameValid, 8 isVideoChannelNameValid,
9 isVideoChannelNameWithHostExist,
11 isVideoChannelSupportValid 10 isVideoChannelSupportValid
12} from '../../helpers/custom-validators/video-channels' 11} from '../../helpers/custom-validators/video-channels'
13import { logger } from '../../helpers/logger' 12import { logger } from '../../helpers/logger'
14import { UserModel } from '../../models/account/user' 13import { UserModel } from '../../models/account/user'
15import { VideoChannelModel } from '../../models/video/video-channel' 14import { VideoChannelModel } from '../../models/video/video-channel'
16import { areValidationErrors } from './utils' 15import { areValidationErrors } from './utils'
16import { isActorPreferredUsernameValid } from '../../helpers/custom-validators/activitypub/actor'
17 17
18const listVideoAccountChannelsValidator = [ 18const listVideoAccountChannelsValidator = [
19 param('accountName').exists().withMessage('Should have a valid account name'), 19 param('accountName').exists().withMessage('Should have a valid account name'),
@@ -29,6 +29,7 @@ const listVideoAccountChannelsValidator = [
29] 29]
30 30
31const videoChannelsAddValidator = [ 31const videoChannelsAddValidator = [
32 body('name').custom(isActorPreferredUsernameValid).withMessage('Should have a valid channel name'),
32 body('displayName').custom(isVideoChannelNameValid).withMessage('Should have a valid display name'), 33 body('displayName').custom(isVideoChannelNameValid).withMessage('Should have a valid display name'),
33 body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'), 34 body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'),
34 body('support').optional().custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'), 35 body('support').optional().custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'),
@@ -43,7 +44,7 @@ const videoChannelsAddValidator = [
43] 44]
44 45
45const videoChannelsUpdateValidator = [ 46const videoChannelsUpdateValidator = [
46 param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), 47 param('nameWithHost').exists().withMessage('Should have an video channel name with host'),
47 body('displayName').optional().custom(isVideoChannelNameValid).withMessage('Should have a valid display name'), 48 body('displayName').optional().custom(isVideoChannelNameValid).withMessage('Should have a valid display name'),
48 body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'), 49 body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'),
49 body('support').optional().custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'), 50 body('support').optional().custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'),
@@ -52,7 +53,7 @@ const videoChannelsUpdateValidator = [
52 logger.debug('Checking videoChannelsUpdate parameters', { parameters: req.body }) 53 logger.debug('Checking videoChannelsUpdate parameters', { parameters: req.body })
53 54
54 if (areValidationErrors(req, res)) return 55 if (areValidationErrors(req, res)) return
55 if (!await isVideoChannelExist(req.params.id, res)) return 56 if (!await isVideoChannelNameWithHostExist(req.params.nameWithHost, res)) return
56 57
57 // We need to make additional checks 58 // We need to make additional checks
58 if (res.locals.videoChannel.Actor.isOwned() === false) { 59 if (res.locals.videoChannel.Actor.isOwned() === false) {
@@ -72,13 +73,13 @@ const videoChannelsUpdateValidator = [
72] 73]
73 74
74const videoChannelsRemoveValidator = [ 75const videoChannelsRemoveValidator = [
75 param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), 76 param('nameWithHost').exists().withMessage('Should have an video channel name with host'),
76 77
77 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 78 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
78 logger.debug('Checking videoChannelsRemove parameters', { parameters: req.params }) 79 logger.debug('Checking videoChannelsRemove parameters', { parameters: req.params })
79 80
80 if (areValidationErrors(req, res)) return 81 if (areValidationErrors(req, res)) return
81 if (!await isVideoChannelExist(req.params.id, res)) return 82 if (!await isVideoChannelNameWithHostExist(req.params.nameWithHost, res)) return
82 83
83 if (!checkUserCanDeleteVideoChannel(res.locals.oauth.token.User, res.locals.videoChannel, res)) return 84 if (!checkUserCanDeleteVideoChannel(res.locals.oauth.token.User, res.locals.videoChannel, res)) return
84 if (!await checkVideoChannelIsNotTheLastOne(res)) return 85 if (!await checkVideoChannelIsNotTheLastOne(res)) return
@@ -87,15 +88,15 @@ const videoChannelsRemoveValidator = [
87 } 88 }
88] 89]
89 90
90const videoChannelsGetValidator = [ 91const videoChannelsNameWithHostValidator = [
91 param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), 92 param('nameWithHost').exists().withMessage('Should have an video channel name with host'),
92 93
93 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 94 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
94 logger.debug('Checking videoChannelsGet parameters', { parameters: req.params }) 95 logger.debug('Checking videoChannelsNameWithHostValidator parameters', { parameters: req.params })
95 96
96 if (areValidationErrors(req, res)) return 97 if (areValidationErrors(req, res)) return
97 98
98 if (!await isVideoChannelExist(req.params.id, res)) return 99 if (!await isVideoChannelNameWithHostExist(req.params.nameWithHost, res)) return
99 100
100 return next() 101 return next()
101 } 102 }
@@ -121,7 +122,7 @@ export {
121 videoChannelsAddValidator, 122 videoChannelsAddValidator,
122 videoChannelsUpdateValidator, 123 videoChannelsUpdateValidator,
123 videoChannelsRemoveValidator, 124 videoChannelsRemoveValidator,
124 videoChannelsGetValidator, 125 videoChannelsNameWithHostValidator,
125 localVideoChannelValidator 126 localVideoChannelValidator
126} 127}
127 128