]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
fix(server): delete another users channel
authorkontrollanten <6680299+kontrollanten@users.noreply.github.com>
Thu, 9 Dec 2021 21:21:03 +0000 (22:21 +0100)
committerkontrollanten <6680299+kontrollanten@users.noreply.github.com>
Thu, 9 Dec 2021 22:18:39 +0000 (23:18 +0100)
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.

server/middlewares/validators/videos/video-channels.ts

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