]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/abuse.ts
Add Podcast RSS feeds (#5487)
[github/Chocobozzz/PeerTube.git] / server / controllers / api / abuse.ts
index ba5b948405480708a50e7f24b1017e29fdc5ca94..d6211cc83e807a0c7591b61564f841c9fbf062ee 100644 (file)
@@ -1,4 +1,4 @@
-import * as express from 'express'
+import express from 'express'
 import { logger } from '@server/helpers/logger'
 import { createAccountAbuse, createVideoAbuse, createVideoCommentAbuse } from '@server/lib/moderation'
 import { Notifier } from '@server/lib/notifier'
@@ -6,8 +6,7 @@ import { AbuseModel } from '@server/models/abuse/abuse'
 import { AbuseMessageModel } from '@server/models/abuse/abuse-message'
 import { getServerActor } from '@server/models/application/application'
 import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse'
-import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
-import { AbuseCreate, AbuseState, UserRight } from '../../../shared'
+import { AbuseCreate, AbuseState, HttpStatusCode, UserRight } from '@shared/models'
 import { getFormattedObjects } from '../../helpers/utils'
 import { sequelizeTypescript } from '../../initializers/database'
 import {
@@ -167,7 +166,11 @@ async function reportAbuse (req: express.Request, res: express.Response) {
   const body: AbuseCreate = req.body
 
   const { id } = await sequelizeTypescript.transaction(async t => {
-    const reporterAccount = await AccountModel.load(res.locals.oauth.token.User.Account.id, t)
+    const user = res.locals.oauth.token.User
+    // Don't send abuse notification if reporter is an admin/moderator
+    const skipNotification = user.hasRight(UserRight.MANAGE_ABUSES)
+
+    const reporterAccount = await AccountModel.load(user.Account.id, t)
     const predefinedReasons = body.predefinedReasons?.map(r => abusePredefinedReasonsMap[r])
 
     const baseAbuse = {
@@ -184,7 +187,8 @@ async function reportAbuse (req: express.Request, res: express.Response) {
         reporterAccount,
         transaction: t,
         startAt: body.video.startAt,
-        endAt: body.video.endAt
+        endAt: body.video.endAt,
+        skipNotification
       })
     }
 
@@ -193,7 +197,8 @@ async function reportAbuse (req: express.Request, res: express.Response) {
         baseAbuse,
         commentInstance,
         reporterAccount,
-        transaction: t
+        transaction: t,
+        skipNotification
       })
     }
 
@@ -202,7 +207,8 @@ async function reportAbuse (req: express.Request, res: express.Response) {
       baseAbuse,
       accountInstance,
       reporterAccount,
-      transaction: t
+      transaction: t,
+      skipNotification
     })
   })