]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix scheduled privacy and verify email validations
authorChocobozzz <me@florianbigard.com>
Thu, 25 Jul 2019 15:28:45 +0000 (17:28 +0200)
committerChocobozzz <me@florianbigard.com>
Thu, 25 Jul 2019 15:28:45 +0000 (17:28 +0200)
server/helpers/custom-validators/misc.ts
server/helpers/custom-validators/videos.ts
server/middlewares/validators/users.ts
server/middlewares/validators/videos/videos.ts

index 1b7e00431094aef26d0d15369b7f53467e7171ea..0c3df1cd0800777a28fc13d8eaa9d69d2b5c58e5 100644 (file)
@@ -1,7 +1,6 @@
 import 'multer'
 import * as validator from 'validator'
 import { sep } from 'path'
-import toBoolean = require('validator/lib/toBoolean')
 
 function exists (value: any) {
   return value !== undefined && value !== null
@@ -52,7 +51,7 @@ function toIntOrNull (value: string) {
   if (v === null || v === undefined) return v
   if (typeof v === 'number') return v
 
-  return validator.toInt(v)
+  return validator.toInt('' + v)
 }
 
 function toBooleanOrNull (value: any) {
@@ -61,7 +60,7 @@ function toBooleanOrNull (value: any) {
   if (v === null || v === undefined) return v
   if (typeof v === 'boolean') return v
 
-  return toBoolean(v)
+  return validator.toBoolean('' + v)
 }
 
 function toValueOrNull (value: string) {
index 9ab1ef23437e019ae222f7dba5fa510bd3c61a38..e92ef9b92588e7c6054d6b1c089b6206d044b7e1 100644 (file)
@@ -98,15 +98,11 @@ function isVideoImage (files: { [ fieldname: string ]: Express.Multer.File[] } |
 }
 
 function isVideoPrivacyValid (value: number) {
-  return validator.isInt(value + '') && VIDEO_PRIVACIES[ value ] !== undefined
+  return VIDEO_PRIVACIES[ value ] !== undefined
 }
 
 function isScheduleVideoUpdatePrivacyValid (value: number) {
-  return validator.isInt(value + '') &&
-    (
-      value === VideoPrivacy.UNLISTED ||
-      value === VideoPrivacy.PUBLIC
-    )
+  return value === VideoPrivacy.UNLISTED || value === VideoPrivacy.PUBLIC
 }
 
 function isVideoOriginallyPublishedAtValid (value: string | null) {
index db03dc23161a9e45165e4ec5fd86a3d576291af0..da92c715d4dcd60821130013e4bfb6d97e7a5dba 100644 (file)
@@ -2,7 +2,7 @@ import * as Bluebird from 'bluebird'
 import * as express from 'express'
 import { body, param } from 'express-validator'
 import { omit } from 'lodash'
-import { isIdOrUUIDValid, toIntOrNull } from '../../helpers/custom-validators/misc'
+import { isIdOrUUIDValid, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc'
 import {
   isUserAdminFlagsValid,
   isUserAutoPlayVideoValid,
@@ -357,7 +357,7 @@ const usersVerifyEmailValidator = [
     .not().isEmpty().withMessage('Should have a valid verification string'),
   body('isPendingEmail')
     .optional()
-    .customSanitizer(toIntOrNull),
+    .customSanitizer(toBooleanOrNull),
 
   async (req: express.Request, res: express.Response, next: express.NextFunction) => {
     logger.debug('Checking usersVerifyEmail parameters', { parameters: req.params })
index 27dfe91ca9ac923bacf3c55d0c0fe3b4198a586f..af06f3c629e1426538045bfd7456ad5051f8aa27 100644 (file)
@@ -349,7 +349,7 @@ function getCommonVideoEditAttributes () {
       .custom(isDateValid).withMessage('Should have a valid schedule update date'),
     body('scheduleUpdate.privacy')
       .optional()
-      .customSanitizer(toValueOrNull)
+      .customSanitizer(toIntOrNull)
       .custom(isScheduleVideoUpdatePrivacyValid).withMessage('Should have correct schedule update privacy')
   ] as (ValidationChain | express.Handler)[]
 }