diff options
Diffstat (limited to 'server/helpers')
-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 { |