diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-10-27 16:55:03 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-10-27 16:55:03 +0200 |
commit | 954605a804da399317ca62afa2fb9244afa11ebf (patch) | |
tree | de6ee69280bfb928bc01c29430e13d5b820e921a /server/helpers/custom-validators | |
parent | e02573ad67626210ed279bad321ee139094921a1 (diff) | |
download | PeerTube-954605a804da399317ca62afa2fb9244afa11ebf.tar.gz PeerTube-954605a804da399317ca62afa2fb9244afa11ebf.tar.zst PeerTube-954605a804da399317ca62afa2fb9244afa11ebf.zip |
Support roles with rights and add moderator role
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r-- | server/helpers/custom-validators/users.ts | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/server/helpers/custom-validators/users.ts b/server/helpers/custom-validators/users.ts index c180eccda..f423d6317 100644 --- a/server/helpers/custom-validators/users.ts +++ b/server/helpers/custom-validators/users.ts | |||
@@ -1,9 +1,8 @@ | |||
1 | import { values } from 'lodash' | ||
2 | import * as validator from 'validator' | 1 | import * as validator from 'validator' |
3 | import 'express-validator' | 2 | import 'express-validator' |
4 | 3 | ||
5 | import { exists } from './misc' | 4 | import { exists } from './misc' |
6 | import { CONSTRAINTS_FIELDS, USER_ROLES } from '../../initializers' | 5 | import { CONSTRAINTS_FIELDS } from '../../initializers' |
7 | import { UserRole } from '../../../shared' | 6 | import { UserRole } from '../../../shared' |
8 | 7 | ||
9 | const USERS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.USERS | 8 | const USERS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.USERS |
@@ -12,10 +11,6 @@ function isUserPasswordValid (value: string) { | |||
12 | return validator.isLength(value, USERS_CONSTRAINTS_FIELDS.PASSWORD) | 11 | return validator.isLength(value, USERS_CONSTRAINTS_FIELDS.PASSWORD) |
13 | } | 12 | } |
14 | 13 | ||
15 | function isUserRoleValid (value: string) { | ||
16 | return values(USER_ROLES).indexOf(value as UserRole) !== -1 | ||
17 | } | ||
18 | |||
19 | function isUserVideoQuotaValid (value: string) { | 14 | function isUserVideoQuotaValid (value: string) { |
20 | return exists(value) && validator.isInt(value + '', USERS_CONSTRAINTS_FIELDS.VIDEO_QUOTA) | 15 | return exists(value) && validator.isInt(value + '', USERS_CONSTRAINTS_FIELDS.VIDEO_QUOTA) |
21 | } | 16 | } |
@@ -30,6 +25,10 @@ function isUserDisplayNSFWValid (value: any) { | |||
30 | return typeof value === 'boolean' || (typeof value === 'string' && validator.isBoolean(value)) | 25 | return typeof value === 'boolean' || (typeof value === 'string' && validator.isBoolean(value)) |
31 | } | 26 | } |
32 | 27 | ||
28 | function isUserRoleValid (value: any) { | ||
29 | return exists(value) && validator.isInt('' + value) && UserRole[value] !== undefined | ||
30 | } | ||
31 | |||
33 | // --------------------------------------------------------------------------- | 32 | // --------------------------------------------------------------------------- |
34 | 33 | ||
35 | export { | 34 | export { |