From d95d15598847c7f020aa056e7e6e0c02d2bbf732 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 1 Jul 2020 16:05:30 +0200 Subject: Use 3 tables to represent abuses --- shared/extra-utils/index.ts | 1 + shared/extra-utils/moderation/abuses.ts | 112 +++++++++++++++++++++++++ shared/extra-utils/users/user-notifications.ts | 6 +- shared/extra-utils/videos/video-abuses.ts | 18 ++-- 4 files changed, 125 insertions(+), 12 deletions(-) create mode 100644 shared/extra-utils/moderation/abuses.ts (limited to 'shared/extra-utils') diff --git a/shared/extra-utils/index.ts b/shared/extra-utils/index.ts index 2ac0c6338..af4d23856 100644 --- a/shared/extra-utils/index.ts +++ b/shared/extra-utils/index.ts @@ -17,6 +17,7 @@ export * from './videos/services' export * from './videos/video-playlists' export * from './users/users' export * from './users/accounts' +export * from './moderation/abuses' export * from './videos/video-abuses' export * from './videos/video-blacklist' export * from './videos/video-captions' diff --git a/shared/extra-utils/moderation/abuses.ts b/shared/extra-utils/moderation/abuses.ts new file mode 100644 index 000000000..48a51e2b8 --- /dev/null +++ b/shared/extra-utils/moderation/abuses.ts @@ -0,0 +1,112 @@ +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) +} + +function getAbusesList (options: { + url: string + token: string + id?: number + predefinedReason?: AbusePredefinedReasonsString + search?: string + state?: AbuseState + videoIs?: AbuseVideoIs + searchReporter?: string + searchReportee?: string + searchVideo?: string + searchVideoChannel?: string +}) { + const { + url, + token, + id, + predefinedReason, + search, + state, + videoIs, + searchReporter, + searchReportee, + searchVideo, + searchVideoChannel + } = options + const path = '/api/v1/videos/abuse' + + const query = { + sort: 'createdAt', + id, + predefinedReason, + search, + state, + videoIs, + searchReporter, + searchReportee, + searchVideo, + searchVideoChannel + } + + return makeGetRequest({ + url, + path, + token, + query, + statusCodeExpected: 200 + }) +} + +function updateAbuse ( + url: string, + token: string, + videoId: string | number, + videoAbuseId: number, + body: AbuseUpdate, + statusCodeExpected = 204 +) { + const path = '/api/v1/videos/' + videoId + '/abuse/' + videoAbuseId + + return makePutBodyRequest({ + url, + token, + path, + fields: body, + statusCodeExpected + }) +} + +function deleteAbuse (url: string, token: string, videoId: string | number, videoAbuseId: number, statusCodeExpected = 204) { + const path = '/api/v1/videos/' + videoId + '/abuse/' + videoAbuseId + + return makeDeleteRequest({ + url, + token, + path, + statusCodeExpected + }) +} + +// --------------------------------------------------------------------------- + +export { + reportAbuse, + getAbusesList, + updateAbuse, + deleteAbuse +} diff --git a/shared/extra-utils/users/user-notifications.ts b/shared/extra-utils/users/user-notifications.ts index a17a39de9..62f3418c5 100644 --- a/shared/extra-utils/users/user-notifications.ts +++ b/shared/extra-utils/users/user-notifications.ts @@ -443,11 +443,11 @@ async function checkNewVideoAbuseForModerators (base: CheckerBaseParams, videoUU expect(notification).to.not.be.undefined expect(notification.type).to.equal(notificationType) - expect(notification.videoAbuse.id).to.be.a('number') - checkVideo(notification.videoAbuse.video, videoName, videoUUID) + expect(notification.abuse.id).to.be.a('number') + checkVideo(notification.abuse.video, videoName, videoUUID) } else { expect(notification).to.satisfy((n: UserNotification) => { - return n === undefined || n.videoAbuse === undefined || n.videoAbuse.video.uuid !== videoUUID + return n === undefined || n.abuse === undefined || n.abuse.video.uuid !== videoUUID }) } } diff --git a/shared/extra-utils/videos/video-abuses.ts b/shared/extra-utils/videos/video-abuses.ts index ff006672a..8827b8196 100644 --- a/shared/extra-utils/videos/video-abuses.ts +++ b/shared/extra-utils/videos/video-abuses.ts @@ -1,15 +1,15 @@ import * as request from 'supertest' -import { VideoAbuseUpdate } from '../../models/videos/abuse/video-abuse-update.model' -import { makeDeleteRequest, makePutBodyRequest, makeGetRequest } from '../requests/requests' -import { VideoAbuseState, VideoAbusePredefinedReasonsString } from '@shared/models' -import { VideoAbuseVideoIs } from '@shared/models/videos/abuse/video-abuse-video-is.type' +import { AbusePredefinedReasonsString, AbuseState, AbuseUpdate, AbuseVideoIs } from '@shared/models' +import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests' + +// FIXME: deprecated in 2.3. Remove this file function reportVideoAbuse ( url: string, token: string, videoId: number | string, reason: string, - predefinedReasons?: VideoAbusePredefinedReasonsString[], + predefinedReasons?: AbusePredefinedReasonsString[], startAt?: number, endAt?: number, specialStatus = 200 @@ -28,10 +28,10 @@ function getVideoAbusesList (options: { url: string token: string id?: number - predefinedReason?: VideoAbusePredefinedReasonsString + predefinedReason?: AbusePredefinedReasonsString search?: string - state?: VideoAbuseState - videoIs?: VideoAbuseVideoIs + state?: AbuseState + videoIs?: AbuseVideoIs searchReporter?: string searchReportee?: string searchVideo?: string @@ -79,7 +79,7 @@ function updateVideoAbuse ( token: string, videoId: string | number, videoAbuseId: number, - body: VideoAbuseUpdate, + body: AbuseUpdate, statusCodeExpected = 204 ) { const path = '/api/v1/videos/' + videoId + '/abuse/' + videoAbuseId -- cgit v1.2.3