Account/channel descriptions are not required anymore
This commit is contained in:
parent
bf69686953
commit
360329cc02
9 changed files with 100 additions and 61 deletions
|
@ -47,7 +47,7 @@ export class MyAccountProfileComponent extends FormReactive implements OnInit {
|
||||||
|
|
||||||
updateMyProfile () {
|
updateMyProfile () {
|
||||||
const displayName = this.form.value['display-name']
|
const displayName = this.form.value['display-name']
|
||||||
const description = this.form.value['description']
|
const description = this.form.value['description'] || null
|
||||||
|
|
||||||
this.error = null
|
this.error = null
|
||||||
|
|
||||||
|
|
|
@ -64,8 +64,8 @@ export class MyAccountVideoChannelCreateComponent extends MyAccountVideoChannelE
|
||||||
const body = this.form.value
|
const body = this.form.value
|
||||||
const videoChannelCreate: VideoChannelCreate = {
|
const videoChannelCreate: VideoChannelCreate = {
|
||||||
displayName: body['display-name'],
|
displayName: body['display-name'],
|
||||||
description: body.description || undefined,
|
description: body.description || null,
|
||||||
support: body.support || undefined
|
support: body.support || null
|
||||||
}
|
}
|
||||||
|
|
||||||
this.videoChannelService.createVideoChannel(videoChannelCreate).subscribe(
|
this.videoChannelService.createVideoChannel(videoChannelCreate).subscribe(
|
||||||
|
|
|
@ -92,8 +92,8 @@ export class MyAccountVideoChannelUpdateComponent extends MyAccountVideoChannelE
|
||||||
const body = this.form.value
|
const body = this.form.value
|
||||||
const videoChannelUpdate: VideoChannelUpdate = {
|
const videoChannelUpdate: VideoChannelUpdate = {
|
||||||
displayName: body['display-name'],
|
displayName: body['display-name'],
|
||||||
description: body.description || undefined,
|
description: body.description || null,
|
||||||
support: body.support || undefined
|
support: body.support || null
|
||||||
}
|
}
|
||||||
|
|
||||||
this.videoChannelService.updateVideoChannel(this.videoChannelToUpdate.uuid, videoChannelUpdate).subscribe(
|
this.videoChannelService.updateVideoChannel(this.videoChannelToUpdate.uuid, videoChannelUpdate).subscribe(
|
||||||
|
|
|
@ -60,12 +60,10 @@ export const USER_DISPLAY_NAME = {
|
||||||
}
|
}
|
||||||
export const USER_DESCRIPTION = {
|
export const USER_DESCRIPTION = {
|
||||||
VALIDATORS: [
|
VALIDATORS: [
|
||||||
Validators.required,
|
|
||||||
Validators.minLength(3),
|
Validators.minLength(3),
|
||||||
Validators.maxLength(250)
|
Validators.maxLength(250)
|
||||||
],
|
],
|
||||||
MESSAGES: {
|
MESSAGES: {
|
||||||
'required': 'Description is required.',
|
|
||||||
'minlength': 'Description must be at least 3 characters long.',
|
'minlength': 'Description must be at least 3 characters long.',
|
||||||
'maxlength': 'Description cannot be more than 250 characters long.'
|
'maxlength': 'Description cannot be more than 250 characters long.'
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ function objectToFormData (obj: any, form?: FormData, namespace?: string) {
|
||||||
|
|
||||||
if (obj[key] === undefined) continue
|
if (obj[key] === undefined) continue
|
||||||
|
|
||||||
if (typeof obj[ key ] === 'object' && !(obj[ key ] instanceof File)) {
|
if (obj[key] !== null && typeof obj[ key ] === 'object' && !(obj[ key ] instanceof File)) {
|
||||||
objectToFormData(obj[ key ], fd, key)
|
objectToFormData(obj[ key ], fd, key)
|
||||||
} else {
|
} else {
|
||||||
fd.append(formKey, obj[ key ])
|
fd.append(formKey, obj[ key ])
|
||||||
|
|
|
@ -54,11 +54,11 @@ export class VideoService {
|
||||||
}
|
}
|
||||||
|
|
||||||
updateVideo (video: VideoEdit) {
|
updateVideo (video: VideoEdit) {
|
||||||
const language = video.language || undefined
|
const language = video.language || null
|
||||||
const licence = video.licence || undefined
|
const licence = video.licence || null
|
||||||
const category = video.category || undefined
|
const category = video.category || null
|
||||||
const description = video.description || undefined
|
const description = video.description || null
|
||||||
const support = video.support || undefined
|
const support = video.support || null
|
||||||
|
|
||||||
const body: VideoUpdate = {
|
const body: VideoUpdate = {
|
||||||
name: video.name,
|
name: video.name,
|
||||||
|
|
|
@ -25,10 +25,22 @@ function isIdOrUUIDValid (value: string) {
|
||||||
return isIdValid(value) || isUUIDValid(value)
|
return isIdValid(value) || isUUIDValid(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
function isBooleanValid (value: string) {
|
function isBooleanValid (value: any) {
|
||||||
return typeof value === 'boolean' || (typeof value === 'string' && validator.isBoolean(value))
|
return typeof value === 'boolean' || (typeof value === 'string' && validator.isBoolean(value))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toIntOrNull (value: string) {
|
||||||
|
if (value === 'null') return null
|
||||||
|
|
||||||
|
return validator.toInt(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
function toStringOrNull (value: string) {
|
||||||
|
if (value === 'null') return null
|
||||||
|
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
function isFileValid (
|
function isFileValid (
|
||||||
files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[],
|
files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[],
|
||||||
mimeTypeRegex: string,
|
mimeTypeRegex: string,
|
||||||
|
@ -61,6 +73,8 @@ export {
|
||||||
isUUIDValid,
|
isUUIDValid,
|
||||||
isIdOrUUIDValid,
|
isIdOrUUIDValid,
|
||||||
isDateValid,
|
isDateValid,
|
||||||
|
toStringOrNull,
|
||||||
isBooleanValid,
|
isBooleanValid,
|
||||||
|
toIntOrNull,
|
||||||
isFileValid
|
isFileValid
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import * as express from 'express'
|
||||||
import 'express-validator'
|
import 'express-validator'
|
||||||
import { body, param, query } from 'express-validator/check'
|
import { body, param, query } from 'express-validator/check'
|
||||||
import { UserRight, VideoPrivacy } from '../../../shared'
|
import { UserRight, VideoPrivacy } from '../../../shared'
|
||||||
import { isBooleanValid, isIdOrUUIDValid, isIdValid, isUUIDValid } from '../../helpers/custom-validators/misc'
|
import { isBooleanValid, isIdOrUUIDValid, isIdValid, isUUIDValid, toIntOrNull, toStringOrNull } from '../../helpers/custom-validators/misc'
|
||||||
import {
|
import {
|
||||||
isVideoAbuseReasonValid,
|
isVideoAbuseReasonValid,
|
||||||
isVideoCategoryValid,
|
isVideoCategoryValid,
|
||||||
|
@ -14,7 +14,8 @@ import {
|
||||||
isVideoLicenceValid,
|
isVideoLicenceValid,
|
||||||
isVideoNameValid,
|
isVideoNameValid,
|
||||||
isVideoPrivacyValid,
|
isVideoPrivacyValid,
|
||||||
isVideoRatingTypeValid, isVideoSupportValid,
|
isVideoRatingTypeValid,
|
||||||
|
isVideoSupportValid,
|
||||||
isVideoTagsValid
|
isVideoTagsValid
|
||||||
} from '../../helpers/custom-validators/videos'
|
} from '../../helpers/custom-validators/videos'
|
||||||
import { getDurationFromVideoFile } from '../../helpers/ffmpeg-utils'
|
import { getDurationFromVideoFile } from '../../helpers/ffmpeg-utils'
|
||||||
|
@ -41,16 +42,40 @@ const videosAddValidator = [
|
||||||
+ CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME.join(', ')
|
+ CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME.join(', ')
|
||||||
),
|
),
|
||||||
body('name').custom(isVideoNameValid).withMessage('Should have a valid name'),
|
body('name').custom(isVideoNameValid).withMessage('Should have a valid name'),
|
||||||
body('category').optional().custom(isVideoCategoryValid).withMessage('Should have a valid category'),
|
body('category')
|
||||||
body('licence').optional().custom(isVideoLicenceValid).withMessage('Should have a valid licence'),
|
.optional()
|
||||||
body('language').optional().custom(isVideoLanguageValid).withMessage('Should have a valid language'),
|
.customSanitizer(toIntOrNull)
|
||||||
body('nsfw').custom(isBooleanValid).withMessage('Should have a valid NSFW attribute'),
|
.custom(isVideoCategoryValid).withMessage('Should have a valid category'),
|
||||||
body('description').optional().custom(isVideoDescriptionValid).withMessage('Should have a valid description'),
|
body('licence')
|
||||||
body('support').optional().custom(isVideoSupportValid).withMessage('Should have a valid support text'),
|
.optional()
|
||||||
|
.customSanitizer(toIntOrNull)
|
||||||
|
.custom(isVideoLicenceValid).withMessage('Should have a valid licence'),
|
||||||
|
body('language')
|
||||||
|
.optional()
|
||||||
|
.customSanitizer(toStringOrNull)
|
||||||
|
.custom(isVideoLanguageValid).withMessage('Should have a valid language'),
|
||||||
|
body('nsfw')
|
||||||
|
.toBoolean()
|
||||||
|
.custom(isBooleanValid).withMessage('Should have a valid NSFW attribute'),
|
||||||
|
body('description')
|
||||||
|
.optional()
|
||||||
|
.customSanitizer(toStringOrNull)
|
||||||
|
.custom(isVideoDescriptionValid).withMessage('Should have a valid description'),
|
||||||
|
body('support')
|
||||||
|
.optional()
|
||||||
|
.customSanitizer(toStringOrNull)
|
||||||
|
.custom(isVideoSupportValid).withMessage('Should have a valid support text'),
|
||||||
|
body('tags')
|
||||||
|
.optional()
|
||||||
|
.custom(isVideoTagsValid).withMessage('Should have correct tags'),
|
||||||
|
body('commentsEnabled')
|
||||||
|
.toBoolean()
|
||||||
|
.custom(isBooleanValid).withMessage('Should have comments enabled boolean'),
|
||||||
|
body('privacy')
|
||||||
|
.optional()
|
||||||
|
.toInt()
|
||||||
|
.custom(isVideoPrivacyValid).withMessage('Should have correct video privacy'),
|
||||||
body('channelId').custom(isIdValid).withMessage('Should have correct video channel id'),
|
body('channelId').custom(isIdValid).withMessage('Should have correct video channel id'),
|
||||||
body('privacy').custom(isVideoPrivacyValid).withMessage('Should have correct video privacy'),
|
|
||||||
body('tags').optional().custom(isVideoTagsValid).withMessage('Should have correct tags'),
|
|
||||||
body('commentsEnabled').custom(isBooleanValid).withMessage('Should have comments enabled boolean'),
|
|
||||||
|
|
||||||
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||||
logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files })
|
logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files })
|
||||||
|
@ -110,16 +135,44 @@ const videosUpdateValidator = [
|
||||||
'This preview file is not supported. Please, make sure it is of the following type : '
|
'This preview file is not supported. Please, make sure it is of the following type : '
|
||||||
+ CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME.join(', ')
|
+ CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME.join(', ')
|
||||||
),
|
),
|
||||||
body('name').optional().custom(isVideoNameValid).withMessage('Should have a valid name'),
|
body('name')
|
||||||
body('category').optional().custom(isVideoCategoryValid).withMessage('Should have a valid category'),
|
.optional()
|
||||||
body('licence').optional().custom(isVideoLicenceValid).withMessage('Should have a valid licence'),
|
.custom(isVideoNameValid).withMessage('Should have a valid name'),
|
||||||
body('language').optional().custom(isVideoLanguageValid).withMessage('Should have a valid language'),
|
body('category')
|
||||||
body('nsfw').optional().custom(isBooleanValid).withMessage('Should have a valid NSFW attribute'),
|
.optional()
|
||||||
body('privacy').optional().custom(isVideoPrivacyValid).withMessage('Should have correct video privacy'),
|
.customSanitizer(toIntOrNull)
|
||||||
body('description').optional().custom(isVideoDescriptionValid).withMessage('Should have a valid description'),
|
.custom(isVideoCategoryValid).withMessage('Should have a valid category'),
|
||||||
body('support').optional().custom(isVideoSupportValid).withMessage('Should have a valid support text'),
|
body('licence')
|
||||||
body('tags').optional().custom(isVideoTagsValid).withMessage('Should have correct tags'),
|
.optional()
|
||||||
body('commentsEnabled').optional().custom(isBooleanValid).withMessage('Should have comments enabled boolean'),
|
.customSanitizer(toIntOrNull)
|
||||||
|
.custom(isVideoLicenceValid).withMessage('Should have a valid licence'),
|
||||||
|
body('language')
|
||||||
|
.optional()
|
||||||
|
.customSanitizer(toStringOrNull)
|
||||||
|
.custom(isVideoLanguageValid).withMessage('Should have a valid language'),
|
||||||
|
body('nsfw')
|
||||||
|
.optional()
|
||||||
|
.toBoolean()
|
||||||
|
.custom(isBooleanValid).withMessage('Should have a valid NSFW attribute'),
|
||||||
|
body('privacy')
|
||||||
|
.optional()
|
||||||
|
.toInt()
|
||||||
|
.custom(isVideoPrivacyValid).withMessage('Should have correct video privacy'),
|
||||||
|
body('description')
|
||||||
|
.optional()
|
||||||
|
.customSanitizer(toStringOrNull)
|
||||||
|
.custom(isVideoDescriptionValid).withMessage('Should have a valid description'),
|
||||||
|
body('support')
|
||||||
|
.optional()
|
||||||
|
.customSanitizer(toStringOrNull)
|
||||||
|
.custom(isVideoSupportValid).withMessage('Should have a valid support text'),
|
||||||
|
body('tags')
|
||||||
|
.optional()
|
||||||
|
.custom(isVideoTagsValid).withMessage('Should have correct tags'),
|
||||||
|
body('commentsEnabled')
|
||||||
|
.optional()
|
||||||
|
.toBoolean()
|
||||||
|
.custom(isBooleanValid).withMessage('Should have comments enabled boolean'),
|
||||||
|
|
||||||
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||||
logger.debug('Checking videosUpdate parameters', { parameters: req.body })
|
logger.debug('Checking videosUpdate parameters', { parameters: req.body })
|
||||||
|
|
|
@ -231,13 +231,6 @@ describe('Test videos API validator', function () {
|
||||||
await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
|
await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should fail with a bad nsfw attribute', async function () {
|
|
||||||
const fields = immutableAssign(baseCorrectParams, { nsfw: 2 })
|
|
||||||
const attaches = baseCorrectAttaches
|
|
||||||
|
|
||||||
await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
|
|
||||||
})
|
|
||||||
|
|
||||||
it('Should fail without commentsEnabled attribute', async function () {
|
it('Should fail without commentsEnabled attribute', async function () {
|
||||||
const fields = omit(baseCorrectParams, 'commentsEnabled')
|
const fields = omit(baseCorrectParams, 'commentsEnabled')
|
||||||
const attaches = baseCorrectAttaches
|
const attaches = baseCorrectAttaches
|
||||||
|
@ -245,13 +238,6 @@ describe('Test videos API validator', function () {
|
||||||
await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
|
await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should fail with a bad commentsEnabled attribute', async function () {
|
|
||||||
const fields = immutableAssign(baseCorrectParams, { commentsEnabled: 2 })
|
|
||||||
const attaches = baseCorrectAttaches
|
|
||||||
|
|
||||||
await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
|
|
||||||
})
|
|
||||||
|
|
||||||
it('Should fail with a long description', async function () {
|
it('Should fail with a long description', async function () {
|
||||||
const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
|
const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
|
||||||
const attaches = baseCorrectAttaches
|
const attaches = baseCorrectAttaches
|
||||||
|
@ -485,18 +471,6 @@ describe('Test videos API validator', function () {
|
||||||
await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
|
await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should fail with a bad nsfw attribute', async function () {
|
|
||||||
const fields = immutableAssign(baseCorrectParams, { nsfw: 2 })
|
|
||||||
|
|
||||||
await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
|
|
||||||
})
|
|
||||||
|
|
||||||
it('Should fail with a bad commentsEnabled attribute', async function () {
|
|
||||||
const fields = immutableAssign(baseCorrectParams, { commentsEnabled: 2 })
|
|
||||||
|
|
||||||
await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
|
|
||||||
})
|
|
||||||
|
|
||||||
it('Should fail with a long description', async function () {
|
it('Should fail with a long description', async function () {
|
||||||
const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
|
const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue