Add explicit error message that changing video ownership only works with local accounts (#1214)
* Add explicit error message that changing video ownership only works with local accounts * Remove superfluous logger * Remove unneeded end() to error responses * Add a message on client side to prevent transfering ownership to a remote account
This commit is contained in:
parent
ee7c25c767
commit
9ccff23877
|
@ -1,5 +1,5 @@
|
||||||
import { I18n } from '@ngx-translate/i18n-polyfill'
|
import { I18n } from '@ngx-translate/i18n-polyfill'
|
||||||
import { Validators } from '@angular/forms'
|
import { AbstractControl, ValidationErrors, Validators } from '@angular/forms'
|
||||||
import { Injectable } from '@angular/core'
|
import { Injectable } from '@angular/core'
|
||||||
import { BuildFormValidator } from '@app/shared'
|
import { BuildFormValidator } from '@app/shared'
|
||||||
|
|
||||||
|
@ -9,10 +9,19 @@ export class VideoChangeOwnershipValidatorsService {
|
||||||
|
|
||||||
constructor (private i18n: I18n) {
|
constructor (private i18n: I18n) {
|
||||||
this.USERNAME = {
|
this.USERNAME = {
|
||||||
VALIDATORS: [ Validators.required ],
|
VALIDATORS: [ Validators.required, this.localAccountValidator ],
|
||||||
MESSAGES: {
|
MESSAGES: {
|
||||||
'required': this.i18n('The username is required.')
|
'required': this.i18n('The username is required.'),
|
||||||
|
'localAccountOnly': this.i18n('You can only transfer ownership to a local account')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
localAccountValidator (control: AbstractControl): ValidationErrors {
|
||||||
|
if (control.value.includes('@')) {
|
||||||
|
return { 'localAccountOnly': true }
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,6 @@ const videosAddValidator = getCommonVideoAttributes().concat([
|
||||||
if (isAble === false) {
|
if (isAble === false) {
|
||||||
res.status(403)
|
res.status(403)
|
||||||
.json({ error: 'The user video quota is exceeded with this video.' })
|
.json({ error: 'The user video quota is exceeded with this video.' })
|
||||||
.end()
|
|
||||||
|
|
||||||
return cleanUpReqFiles(req)
|
return cleanUpReqFiles(req)
|
||||||
}
|
}
|
||||||
|
@ -82,7 +81,6 @@ const videosAddValidator = getCommonVideoAttributes().concat([
|
||||||
logger.error('Invalid input file in videosAddValidator.', { err })
|
logger.error('Invalid input file in videosAddValidator.', { err })
|
||||||
res.status(400)
|
res.status(400)
|
||||||
.json({ error: 'Invalid input file.' })
|
.json({ error: 'Invalid input file.' })
|
||||||
.end()
|
|
||||||
|
|
||||||
return cleanUpReqFiles(req)
|
return cleanUpReqFiles(req)
|
||||||
}
|
}
|
||||||
|
@ -120,7 +118,6 @@ const videosUpdateValidator = getCommonVideoAttributes().concat([
|
||||||
cleanUpReqFiles(req)
|
cleanUpReqFiles(req)
|
||||||
return res.status(409)
|
return res.status(409)
|
||||||
.json({ error: 'Cannot set "private" a video that was not private.' })
|
.json({ error: 'Cannot set "private" a video that was not private.' })
|
||||||
.end()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.body.channelId && !await isVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req)
|
if (req.body.channelId && !await isVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req)
|
||||||
|
@ -150,7 +147,6 @@ const videosCustomGetValidator = (fetchType: VideoFetchType) => {
|
||||||
if (video.VideoChannel.Account.userId !== user.id && !user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST)) {
|
if (video.VideoChannel.Account.userId !== user.id && !user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST)) {
|
||||||
return res.status(403)
|
return res.status(403)
|
||||||
.json({ error: 'Cannot get this private or blacklisted video.' })
|
.json({ error: 'Cannot get this private or blacklisted video.' })
|
||||||
.end()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return next()
|
return next()
|
||||||
|
@ -239,8 +235,8 @@ const videosChangeOwnershipValidator = [
|
||||||
const nextOwner = await AccountModel.loadLocalByName(req.body.username)
|
const nextOwner = await AccountModel.loadLocalByName(req.body.username)
|
||||||
if (!nextOwner) {
|
if (!nextOwner) {
|
||||||
res.status(400)
|
res.status(400)
|
||||||
.type('json')
|
.json({ error: 'Changing video ownership to a remote account is not supported yet' })
|
||||||
.end()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
res.locals.nextOwner = nextOwner
|
res.locals.nextOwner = nextOwner
|
||||||
|
@ -271,7 +267,7 @@ const videosTerminateChangeOwnershipValidator = [
|
||||||
} else {
|
} else {
|
||||||
res.status(403)
|
res.status(403)
|
||||||
.json({ error: 'Ownership already accepted or refused' })
|
.json({ error: 'Ownership already accepted or refused' })
|
||||||
.end()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -288,7 +284,7 @@ const videosAcceptChangeOwnershipValidator = [
|
||||||
if (isAble === false) {
|
if (isAble === false) {
|
||||||
res.status(403)
|
res.status(403)
|
||||||
.json({ error: 'The user video quota is exceeded with this video.' })
|
.json({ error: 'The user video quota is exceeded with this video.' })
|
||||||
.end()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,7 +385,6 @@ function areErrorsInScheduleUpdate (req: express.Request, res: express.Response)
|
||||||
if (!req.body.scheduleUpdate.updateAt) {
|
if (!req.body.scheduleUpdate.updateAt) {
|
||||||
res.status(400)
|
res.status(400)
|
||||||
.json({ error: 'Schedule update at is mandatory.' })
|
.json({ error: 'Schedule update at is mandatory.' })
|
||||||
.end()
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue