aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/moderation
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-07-01 16:05:30 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-07-10 14:02:41 +0200
commitd95d15598847c7f020aa056e7e6e0c02d2bbf732 (patch)
treea8a593f1269688caf9e5f99559996f346290fec5 /shared/extra-utils/moderation
parent72493e44e9b455a04c4f093ed6c6ffa300b98d8b (diff)
downloadPeerTube-d95d15598847c7f020aa056e7e6e0c02d2bbf732.tar.gz
PeerTube-d95d15598847c7f020aa056e7e6e0c02d2bbf732.tar.zst
PeerTube-d95d15598847c7f020aa056e7e6e0c02d2bbf732.zip
Use 3 tables to represent abuses
Diffstat (limited to 'shared/extra-utils/moderation')
-rw-r--r--shared/extra-utils/moderation/abuses.ts112
1 files changed, 112 insertions, 0 deletions
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 @@
1import * as request from 'supertest'
2import { AbusePredefinedReasonsString, AbuseState, AbuseUpdate, AbuseVideoIs } from '@shared/models'
3import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests'
4
5function reportAbuse (
6 url: string,
7 token: string,
8 videoId: number | string,
9 reason: string,
10 predefinedReasons?: AbusePredefinedReasonsString[],
11 startAt?: number,
12 endAt?: number,
13 specialStatus = 200
14) {
15 const path = '/api/v1/videos/' + videoId + '/abuse'
16
17 return request(url)
18 .post(path)
19 .set('Accept', 'application/json')
20 .set('Authorization', 'Bearer ' + token)
21 .send({ reason, predefinedReasons, startAt, endAt })
22 .expect(specialStatus)
23}
24
25function getAbusesList (options: {
26 url: string
27 token: string
28 id?: number
29 predefinedReason?: AbusePredefinedReasonsString
30 search?: string
31 state?: AbuseState
32 videoIs?: AbuseVideoIs
33 searchReporter?: string
34 searchReportee?: string
35 searchVideo?: string
36 searchVideoChannel?: string
37}) {
38 const {
39 url,
40 token,
41 id,
42 predefinedReason,
43 search,
44 state,
45 videoIs,
46 searchReporter,
47 searchReportee,
48 searchVideo,
49 searchVideoChannel
50 } = options
51 const path = '/api/v1/videos/abuse'
52
53 const query = {
54 sort: 'createdAt',
55 id,
56 predefinedReason,
57 search,
58 state,
59 videoIs,
60 searchReporter,
61 searchReportee,
62 searchVideo,
63 searchVideoChannel
64 }
65
66 return makeGetRequest({
67 url,
68 path,
69 token,
70 query,
71 statusCodeExpected: 200
72 })
73}
74
75function updateAbuse (
76 url: string,
77 token: string,
78 videoId: string | number,
79 videoAbuseId: number,
80 body: AbuseUpdate,
81 statusCodeExpected = 204
82) {
83 const path = '/api/v1/videos/' + videoId + '/abuse/' + videoAbuseId
84
85 return makePutBodyRequest({
86 url,
87 token,
88 path,
89 fields: body,
90 statusCodeExpected
91 })
92}
93
94function deleteAbuse (url: string, token: string, videoId: string | number, videoAbuseId: number, statusCodeExpected = 204) {
95 const path = '/api/v1/videos/' + videoId + '/abuse/' + videoAbuseId
96
97 return makeDeleteRequest({
98 url,
99 token,
100 path,
101 statusCodeExpected
102 })
103}
104
105// ---------------------------------------------------------------------------
106
107export {
108 reportAbuse,
109 getAbusesList,
110 updateAbuse,
111 deleteAbuse
112}