]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/abuse/abuse-query-builder.ts
Prevent video import on non unicast ips
[github/Chocobozzz/PeerTube.git] / server / models / abuse / abuse-query-builder.ts
index 5fddcf3c439d451b4b8267fc11d7ad600c4f75c6..53245914441c534c39a14b3022901ecdacb59097 100644 (file)
@@ -26,8 +26,10 @@ export type BuildAbusesQueryOptions = {
   state?: AbuseState
 
   // accountIds
-  serverAccountId: number
-  userAccountId: number
+  serverAccountId?: number
+  userAccountId?: number
+
+  reporterAccountId?: number
 }
 
 function buildAbuseListQuery (options: BuildAbusesQueryOptions, type: 'count' | 'id') {
@@ -40,12 +42,19 @@ function buildAbuseListQuery (options: BuildAbusesQueryOptions, type: 'count' |
     'LEFT JOIN "videoBlacklist" ON "videoBlacklist"."videoId" = "video"."id"',
     'LEFT JOIN "videoChannel" ON "video"."channelId" = "videoChannel"."id"',
     'LEFT JOIN "account" "reporterAccount" ON "reporterAccount"."id" = "abuse"."reporterAccountId"',
-    'LEFT JOIN "account" "flaggedAccount" ON "flaggedAccount"."id" = "abuse"."reporterAccountId"',
+    'LEFT JOIN "account" "flaggedAccount" ON "flaggedAccount"."id" = "abuse"."flaggedAccountId"',
     'LEFT JOIN "commentAbuse" ON "commentAbuse"."abuseId" = "abuse"."id"',
     'LEFT JOIN "videoComment" ON "commentAbuse"."videoCommentId" = "videoComment"."id"'
   ]
 
-  whereAnd.push('"abuse"."reporterAccountId" NOT IN (' + buildBlockedAccountSQL([ options.serverAccountId, options.userAccountId ]) + ')')
+  if (options.serverAccountId || options.userAccountId) {
+    whereAnd.push('"abuse"."reporterAccountId" NOT IN (' + buildBlockedAccountSQL([ options.serverAccountId, options.userAccountId ]) + ')')
+  }
+
+  if (options.reporterAccountId) {
+    whereAnd.push('"abuse"."reporterAccountId" = :reporterAccountId')
+    replacements.reporterAccountId = options.reporterAccountId
+  }
 
   if (options.search) {
     const searchWhereOr = [