fix(server): delete another users channel

Since the channel owner isn't necessary the auth user we need to check
the right account whether it's the last video or not.
pull/4608/head
kontrollanten 2021-12-09 22:21:03 +01:00
parent 952881aaf6
commit 416a7f4f35
1 changed files with 3 additions and 3 deletions

View File

@ -80,7 +80,7 @@ const videoChannelsRemoveValidator = [
if (!await doesVideoChannelNameWithHostExist(req.params.nameWithHost, res)) return if (!await doesVideoChannelNameWithHostExist(req.params.nameWithHost, res)) return
if (!checkUserCanDeleteVideoChannel(res.locals.oauth.token.User, res.locals.videoChannel, res)) return if (!checkUserCanDeleteVideoChannel(res.locals.oauth.token.User, res.locals.videoChannel, res)) return
if (!await checkVideoChannelIsNotTheLastOne(res)) return if (!await checkVideoChannelIsNotTheLastOne(res.locals.videoChannel, res)) return
return next() return next()
} }
@ -174,8 +174,8 @@ function checkUserCanDeleteVideoChannel (user: MUser, videoChannel: MChannelAcco
return true return true
} }
async function checkVideoChannelIsNotTheLastOne (res: express.Response) { async function checkVideoChannelIsNotTheLastOne (videoChannel: MChannelAccountDefault, res: express.Response) {
const count = await VideoChannelModel.countByAccount(res.locals.oauth.token.User.Account.id) const count = await VideoChannelModel.countByAccount(videoChannel.Account.id)
if (count <= 1) { if (count <= 1) {
res.fail({ res.fail({