]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/middlewares/videos.ts
Add banners support
[github/Chocobozzz/PeerTube.git] / server / helpers / middlewares / videos.ts
index c5eb0607aca5de3addbf31328c3b8f3190668846..403cae0925585a4dacaec0e2a68810d4ee066c83 100644 (file)
@@ -66,25 +66,24 @@ async function doesVideoFileOfVideoExist (id: number, videoIdOrUUID: number | st
 }
 
 async function doesVideoChannelOfAccountExist (channelId: number, user: MUserAccountId, res: Response) {
-  if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) {
-    const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId)
-    if (videoChannel === null) {
-      res.status(HttpStatusCode.BAD_REQUEST_400)
-         .json({ error: 'Unknown video `video channel` on this instance.' })
-         .end()
+  const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId)
 
-      return false
-    }
+  if (videoChannel === null) {
+    res.status(HttpStatusCode.BAD_REQUEST_400)
+       .json({ error: 'Unknown video "video channel" for this instance.' })
 
+    return false
+  }
+
+  // Don't check account id if the user can update any video
+  if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) {
     res.locals.videoChannel = videoChannel
     return true
   }
 
-  const videoChannel = await VideoChannelModel.loadByIdAndAccount(channelId, user.Account.id)
-  if (videoChannel === null) {
+  if (videoChannel.Account.id !== user.Account.id) {
     res.status(HttpStatusCode.BAD_REQUEST_400)
-       .json({ error: 'Unknown video `video channel` for this account.' })
-       .end()
+      .json({ error: 'Unknown video "video channel" for this account.' })
 
     return false
   }