Fix scheduled privacy and verify email validations

This commit is contained in:
Chocobozzz 2019-07-25 17:28:45 +02:00
parent 552d95b1e6
commit 2b65c4e535
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
4 changed files with 7 additions and 12 deletions

View File

@ -1,7 +1,6 @@
import 'multer' import 'multer'
import * as validator from 'validator' import * as validator from 'validator'
import { sep } from 'path' import { sep } from 'path'
import toBoolean = require('validator/lib/toBoolean')
function exists (value: any) { function exists (value: any) {
return value !== undefined && value !== null return value !== undefined && value !== null
@ -52,7 +51,7 @@ function toIntOrNull (value: string) {
if (v === null || v === undefined) return v if (v === null || v === undefined) return v
if (typeof v === 'number') return v if (typeof v === 'number') return v
return validator.toInt(v) return validator.toInt('' + v)
} }
function toBooleanOrNull (value: any) { function toBooleanOrNull (value: any) {
@ -61,7 +60,7 @@ function toBooleanOrNull (value: any) {
if (v === null || v === undefined) return v if (v === null || v === undefined) return v
if (typeof v === 'boolean') return v if (typeof v === 'boolean') return v
return toBoolean(v) return validator.toBoolean('' + v)
} }
function toValueOrNull (value: string) { function toValueOrNull (value: string) {

View File

@ -98,15 +98,11 @@ function isVideoImage (files: { [ fieldname: string ]: Express.Multer.File[] } |
} }
function isVideoPrivacyValid (value: number) { function isVideoPrivacyValid (value: number) {
return validator.isInt(value + '') && VIDEO_PRIVACIES[ value ] !== undefined return VIDEO_PRIVACIES[ value ] !== undefined
} }
function isScheduleVideoUpdatePrivacyValid (value: number) { function isScheduleVideoUpdatePrivacyValid (value: number) {
return validator.isInt(value + '') && return value === VideoPrivacy.UNLISTED || value === VideoPrivacy.PUBLIC
(
value === VideoPrivacy.UNLISTED ||
value === VideoPrivacy.PUBLIC
)
} }
function isVideoOriginallyPublishedAtValid (value: string | null) { function isVideoOriginallyPublishedAtValid (value: string | null) {

View File

@ -2,7 +2,7 @@ import * as Bluebird from 'bluebird'
import * as express from 'express' import * as express from 'express'
import { body, param } from 'express-validator' import { body, param } from 'express-validator'
import { omit } from 'lodash' import { omit } from 'lodash'
import { isIdOrUUIDValid, toIntOrNull } from '../../helpers/custom-validators/misc' import { isIdOrUUIDValid, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc'
import { import {
isUserAdminFlagsValid, isUserAdminFlagsValid,
isUserAutoPlayVideoValid, isUserAutoPlayVideoValid,
@ -357,7 +357,7 @@ const usersVerifyEmailValidator = [
.not().isEmpty().withMessage('Should have a valid verification string'), .not().isEmpty().withMessage('Should have a valid verification string'),
body('isPendingEmail') body('isPendingEmail')
.optional() .optional()
.customSanitizer(toIntOrNull), .customSanitizer(toBooleanOrNull),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking usersVerifyEmail parameters', { parameters: req.params }) logger.debug('Checking usersVerifyEmail parameters', { parameters: req.params })

View File

@ -349,7 +349,7 @@ function getCommonVideoEditAttributes () {
.custom(isDateValid).withMessage('Should have a valid schedule update date'), .custom(isDateValid).withMessage('Should have a valid schedule update date'),
body('scheduleUpdate.privacy') body('scheduleUpdate.privacy')
.optional() .optional()
.customSanitizer(toValueOrNull) .customSanitizer(toIntOrNull)
.custom(isScheduleVideoUpdatePrivacyValid).withMessage('Should have correct schedule update privacy') .custom(isScheduleVideoUpdatePrivacyValid).withMessage('Should have correct schedule update privacy')
] as (ValidationChain | express.Handler)[] ] as (ValidationChain | express.Handler)[]
} }