1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 19:42:24 +02:00

Fix video channel update with an admin account

This commit is contained in:
Chocobozzz 2018-05-16 11:33:11 +02:00
parent a14d3b6b23
commit 6200d8d917
No known key found for this signature in database
GPG key ID: 583A612D890159BE
6 changed files with 38 additions and 16 deletions

View file

@ -3,7 +3,7 @@ import 'express-validator'
import { values } from 'lodash'
import 'multer'
import * as validator from 'validator'
import { VideoRateType } from '../../../shared'
import { UserRight, VideoRateType } from '../../../shared'
import {
CONSTRAINTS_FIELDS,
VIDEO_CATEGORIES,
@ -15,6 +15,7 @@ import {
import { VideoModel } from '../../models/video/video'
import { exists, isArray, isFileValid } from './misc'
import { VideoChannelModel } from '../../models/video/video-channel'
import { UserModel } from '../../models/account/user'
const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS
const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES
@ -127,8 +128,22 @@ async function isVideoExist (id: string, res: Response) {
return true
}
async function isVideoChannelOfAccountExist (channelId: number, accountId: number, res: Response) {
const videoChannel = await VideoChannelModel.loadByIdAndAccount(channelId, accountId)
async function isVideoChannelOfAccountExist (channelId: number, user: UserModel, res: Response) {
if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) {
const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId)
if (!videoChannel) {
res.status(400)
.json({ error: 'Unknown video video channel on this instance.' })
.end()
return false
}
res.locals.videoChannel = videoChannel
return true
}
const videoChannel = await VideoChannelModel.loadByIdAndAccount(channelId, user.Account.id)
if (!videoChannel) {
res.status(400)
.json({ error: 'Unknown video video channel for this account.' })