X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Fabuse.ts;h=d6211cc83e807a0c7591b61564f841c9fbf062ee;hb=cde3d90ded5debb24281a444eabb720b721e5600;hp=25d6e2ab0205579b1757946de64201ca27e92ece;hpb=7a4ea932461f228ae44a173ddcd48ffb088aa023;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/api/abuse.ts b/server/controllers/api/abuse.ts index 25d6e2ab0..d6211cc83 100644 --- a/server/controllers/api/abuse.ts +++ b/server/controllers/api/abuse.ts @@ -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,7 +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 { AbuseCreate, AbuseState, UserRight } from '../../../shared' +import { AbuseCreate, AbuseState, HttpStatusCode, UserRight } from '@shared/models' import { getFormattedObjects } from '../../helpers/utils' import { sequelizeTypescript } from '../../initializers/database' import { @@ -23,6 +23,7 @@ import { deleteAbuseMessageValidator, ensureUserHasRight, getAbuseValidator, + openapiOperationDoc, paginationValidator, setDefaultPagination, setDefaultSort @@ -32,6 +33,7 @@ import { AccountModel } from '../../models/account/account' const abuseRouter = express.Router() abuseRouter.get('/', + openapiOperationDoc({ operationId: 'getAbuses' }), authenticate, ensureUserHasRight(UserRight.MANAGE_ABUSES), paginationValidator, @@ -141,7 +143,7 @@ async function updateAbuse (req: express.Request, res: express.Response) { // Do not send the delete to other instances, we updated OUR copy of this abuse - return res.sendStatus(204) + return res.status(HttpStatusCode.NO_CONTENT_204).end() } async function deleteAbuse (req: express.Request, res: express.Response) { @@ -153,7 +155,7 @@ async function deleteAbuse (req: express.Request, res: express.Response) { // Do not send the delete to other instances, we delete OUR copy of this abuse - return res.sendStatus(204) + return res.status(HttpStatusCode.NO_CONTENT_204).end() } async function reportAbuse (req: express.Request, res: express.Response) { @@ -164,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 = { @@ -181,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 }) } @@ -190,7 +197,8 @@ async function reportAbuse (req: express.Request, res: express.Response) { baseAbuse, commentInstance, reporterAccount, - transaction: t + transaction: t, + skipNotification }) } @@ -199,7 +207,8 @@ async function reportAbuse (req: express.Request, res: express.Response) { baseAbuse, accountInstance, reporterAccount, - transaction: t + transaction: t, + skipNotification }) }) @@ -243,5 +252,5 @@ async function deleteAbuseMessage (req: express.Request, res: express.Response) return abuseMessage.destroy({ transaction: t }) }) - return res.sendStatus(204) + return res.status(HttpStatusCode.NO_CONTENT_204).end() }