From 57f6896f67cfc570cf3605dd94b0778101b2d9b9 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 7 Jul 2020 10:57:04 +0200 Subject: Implement abuses check params --- shared/extra-utils/moderation/abuses.ts | 88 +++++++++++++++------- .../models/moderation/abuse/abuse-create.model.ts | 7 +- shared/models/moderation/abuse/abuse-filter.ts | 1 - .../models/moderation/abuse/abuse-filter.type.ts | 1 + shared/models/moderation/abuse/abuse.model.ts | 10 ++- shared/models/moderation/abuse/index.ts | 1 + 6 files changed, 77 insertions(+), 31 deletions(-) delete mode 100644 shared/models/moderation/abuse/abuse-filter.ts create mode 100644 shared/models/moderation/abuse/abuse-filter.type.ts (limited to 'shared') diff --git a/shared/extra-utils/moderation/abuses.ts b/shared/extra-utils/moderation/abuses.ts index 48a51e2b8..1af703f92 100644 --- a/shared/extra-utils/moderation/abuses.ts +++ b/shared/extra-utils/moderation/abuses.ts @@ -1,25 +1,57 @@ -import * as request from 'supertest' -import { AbusePredefinedReasonsString, AbuseState, AbuseUpdate, AbuseVideoIs } from '@shared/models' -import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests' -function reportAbuse ( - url: string, - token: string, - videoId: number | string, - reason: string, - predefinedReasons?: AbusePredefinedReasonsString[], - startAt?: number, - endAt?: number, - specialStatus = 200 -) { - const path = '/api/v1/videos/' + videoId + '/abuse' - - return request(url) - .post(path) - .set('Accept', 'application/json') - .set('Authorization', 'Bearer ' + token) - .send({ reason, predefinedReasons, startAt, endAt }) - .expect(specialStatus) +import { AbuseFilter, AbusePredefinedReasonsString, AbuseState, AbuseUpdate, AbuseVideoIs } from '@shared/models' +import { makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' + +function reportAbuse (options: { + url: string + token: string + + reason: string + + accountId?: number + videoId?: number + commentId?: number + + predefinedReasons?: AbusePredefinedReasonsString[] + + startAt?: number + endAt?: number + + statusCodeExpected?: number +}) { + const path = '/api/v1/abuses' + + const video = options.videoId ? { + id: options.videoId, + startAt: options.startAt, + endAt: options.endAt + } : undefined + + const comment = options.commentId ? { + id: options.commentId + } : undefined + + const account = options.accountId ? { + id: options.accountId + } : undefined + + const body = { + account, + video, + comment, + + reason: options.reason, + predefinedReasons: options.predefinedReasons + } + + return makePostBodyRequest({ + url: options.url, + path, + token: options.token, + + fields: body, + statusCodeExpected: options.statusCodeExpected || 200 + }) } function getAbusesList (options: { @@ -28,6 +60,7 @@ function getAbusesList (options: { id?: number predefinedReason?: AbusePredefinedReasonsString search?: string + filter?: AbuseFilter, state?: AbuseState videoIs?: AbuseVideoIs searchReporter?: string @@ -41,6 +74,7 @@ function getAbusesList (options: { id, predefinedReason, search, + filter, state, videoIs, searchReporter, @@ -48,7 +82,7 @@ function getAbusesList (options: { searchVideo, searchVideoChannel } = options - const path = '/api/v1/videos/abuse' + const path = '/api/v1/abuses' const query = { sort: 'createdAt', @@ -56,6 +90,7 @@ function getAbusesList (options: { predefinedReason, search, state, + filter, videoIs, searchReporter, searchReportee, @@ -75,12 +110,11 @@ function getAbusesList (options: { function updateAbuse ( url: string, token: string, - videoId: string | number, - videoAbuseId: number, + abuseId: number, body: AbuseUpdate, statusCodeExpected = 204 ) { - const path = '/api/v1/videos/' + videoId + '/abuse/' + videoAbuseId + const path = '/api/v1/abuses/' + abuseId return makePutBodyRequest({ url, @@ -91,8 +125,8 @@ function updateAbuse ( }) } -function deleteAbuse (url: string, token: string, videoId: string | number, videoAbuseId: number, statusCodeExpected = 204) { - const path = '/api/v1/videos/' + videoId + '/abuse/' + videoAbuseId +function deleteAbuse (url: string, token: string, abuseId: number, statusCodeExpected = 204) { + const path = '/api/v1/abuses/' + abuseId return makeDeleteRequest({ url, diff --git a/shared/models/moderation/abuse/abuse-create.model.ts b/shared/models/moderation/abuse/abuse-create.model.ts index c0d04e46d..b0358dbb9 100644 --- a/shared/models/moderation/abuse/abuse-create.model.ts +++ b/shared/models/moderation/abuse/abuse-create.model.ts @@ -1,11 +1,14 @@ import { AbusePredefinedReasonsString } from './abuse-reason.model' export interface AbuseCreate { - accountId: number - reason: string + predefinedReasons?: AbusePredefinedReasonsString[] + account?: { + id: number + } + video?: { id: number startAt?: number diff --git a/shared/models/moderation/abuse/abuse-filter.ts b/shared/models/moderation/abuse/abuse-filter.ts deleted file mode 100644 index 03303bbab..000000000 --- a/shared/models/moderation/abuse/abuse-filter.ts +++ /dev/null @@ -1 +0,0 @@ -export type AbuseFilter = 'video' | 'comment' diff --git a/shared/models/moderation/abuse/abuse-filter.type.ts b/shared/models/moderation/abuse/abuse-filter.type.ts new file mode 100644 index 000000000..7dafc6d77 --- /dev/null +++ b/shared/models/moderation/abuse/abuse-filter.type.ts @@ -0,0 +1 @@ +export type AbuseFilter = 'video' | 'comment' | 'account' diff --git a/shared/models/moderation/abuse/abuse.model.ts b/shared/models/moderation/abuse/abuse.model.ts index 9ff150c4a..a120803e6 100644 --- a/shared/models/moderation/abuse/abuse.model.ts +++ b/shared/models/moderation/abuse/abuse.model.ts @@ -9,6 +9,7 @@ export interface VideoAbuse { name: string uuid: string nsfw: boolean + deleted: boolean blacklisted: boolean @@ -21,8 +22,15 @@ export interface VideoAbuse { export interface VideoCommentAbuse { id: number - account?: Account + + video: { + id: number + name: string + uuid: string + } + text: string + deleted: boolean } diff --git a/shared/models/moderation/abuse/index.ts b/shared/models/moderation/abuse/index.ts index 32a6b4e6c..55046426a 100644 --- a/shared/models/moderation/abuse/index.ts +++ b/shared/models/moderation/abuse/index.ts @@ -1,4 +1,5 @@ export * from './abuse-create.model' +export * from './abuse-filter.type' export * from './abuse-reason.model' export * from './abuse-state.model' export * from './abuse-update.model' -- cgit v1.2.3