diff options
author | Chocobozzz <me@florianbigard.com> | 2020-07-07 10:57:04 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-07-10 14:02:41 +0200 |
commit | 57f6896f67cfc570cf3605dd94b0778101b2d9b9 (patch) | |
tree | b82d879c46868ce75ff76c3e4d4eed590a87f6c4 /shared | |
parent | d95d15598847c7f020aa056e7e6e0c02d2bbf732 (diff) | |
download | PeerTube-57f6896f67cfc570cf3605dd94b0778101b2d9b9.tar.gz PeerTube-57f6896f67cfc570cf3605dd94b0778101b2d9b9.tar.zst PeerTube-57f6896f67cfc570cf3605dd94b0778101b2d9b9.zip |
Implement abuses check params
Diffstat (limited to 'shared')
-rw-r--r-- | shared/extra-utils/moderation/abuses.ts | 88 | ||||
-rw-r--r-- | shared/models/moderation/abuse/abuse-create.model.ts | 7 | ||||
-rw-r--r-- | shared/models/moderation/abuse/abuse-filter.ts | 1 | ||||
-rw-r--r-- | shared/models/moderation/abuse/abuse-filter.type.ts | 1 | ||||
-rw-r--r-- | shared/models/moderation/abuse/abuse.model.ts | 10 | ||||
-rw-r--r-- | shared/models/moderation/abuse/index.ts | 1 |
6 files changed, 77 insertions, 31 deletions
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 @@ | |||
1 | import * as request from 'supertest' | ||
2 | import { AbusePredefinedReasonsString, AbuseState, AbuseUpdate, AbuseVideoIs } from '@shared/models' | ||
3 | import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests' | ||
4 | 1 | ||
5 | function reportAbuse ( | 2 | import { AbuseFilter, AbusePredefinedReasonsString, AbuseState, AbuseUpdate, AbuseVideoIs } from '@shared/models' |
6 | url: string, | 3 | import { makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' |
7 | token: string, | 4 | |
8 | videoId: number | string, | 5 | function reportAbuse (options: { |
9 | reason: string, | 6 | url: string |
10 | predefinedReasons?: AbusePredefinedReasonsString[], | 7 | token: string |
11 | startAt?: number, | 8 | |
12 | endAt?: number, | 9 | reason: string |
13 | specialStatus = 200 | 10 | |
14 | ) { | 11 | accountId?: number |
15 | const path = '/api/v1/videos/' + videoId + '/abuse' | 12 | videoId?: number |
16 | 13 | commentId?: number | |
17 | return request(url) | 14 | |
18 | .post(path) | 15 | predefinedReasons?: AbusePredefinedReasonsString[] |
19 | .set('Accept', 'application/json') | 16 | |
20 | .set('Authorization', 'Bearer ' + token) | 17 | startAt?: number |
21 | .send({ reason, predefinedReasons, startAt, endAt }) | 18 | endAt?: number |
22 | .expect(specialStatus) | 19 | |
20 | statusCodeExpected?: number | ||
21 | }) { | ||
22 | const path = '/api/v1/abuses' | ||
23 | |||
24 | const video = options.videoId ? { | ||
25 | id: options.videoId, | ||
26 | startAt: options.startAt, | ||
27 | endAt: options.endAt | ||
28 | } : undefined | ||
29 | |||
30 | const comment = options.commentId ? { | ||
31 | id: options.commentId | ||
32 | } : undefined | ||
33 | |||
34 | const account = options.accountId ? { | ||
35 | id: options.accountId | ||
36 | } : undefined | ||
37 | |||
38 | const body = { | ||
39 | account, | ||
40 | video, | ||
41 | comment, | ||
42 | |||
43 | reason: options.reason, | ||
44 | predefinedReasons: options.predefinedReasons | ||
45 | } | ||
46 | |||
47 | return makePostBodyRequest({ | ||
48 | url: options.url, | ||
49 | path, | ||
50 | token: options.token, | ||
51 | |||
52 | fields: body, | ||
53 | statusCodeExpected: options.statusCodeExpected || 200 | ||
54 | }) | ||
23 | } | 55 | } |
24 | 56 | ||
25 | function getAbusesList (options: { | 57 | function getAbusesList (options: { |
@@ -28,6 +60,7 @@ function getAbusesList (options: { | |||
28 | id?: number | 60 | id?: number |
29 | predefinedReason?: AbusePredefinedReasonsString | 61 | predefinedReason?: AbusePredefinedReasonsString |
30 | search?: string | 62 | search?: string |
63 | filter?: AbuseFilter, | ||
31 | state?: AbuseState | 64 | state?: AbuseState |
32 | videoIs?: AbuseVideoIs | 65 | videoIs?: AbuseVideoIs |
33 | searchReporter?: string | 66 | searchReporter?: string |
@@ -41,6 +74,7 @@ function getAbusesList (options: { | |||
41 | id, | 74 | id, |
42 | predefinedReason, | 75 | predefinedReason, |
43 | search, | 76 | search, |
77 | filter, | ||
44 | state, | 78 | state, |
45 | videoIs, | 79 | videoIs, |
46 | searchReporter, | 80 | searchReporter, |
@@ -48,7 +82,7 @@ function getAbusesList (options: { | |||
48 | searchVideo, | 82 | searchVideo, |
49 | searchVideoChannel | 83 | searchVideoChannel |
50 | } = options | 84 | } = options |
51 | const path = '/api/v1/videos/abuse' | 85 | const path = '/api/v1/abuses' |
52 | 86 | ||
53 | const query = { | 87 | const query = { |
54 | sort: 'createdAt', | 88 | sort: 'createdAt', |
@@ -56,6 +90,7 @@ function getAbusesList (options: { | |||
56 | predefinedReason, | 90 | predefinedReason, |
57 | search, | 91 | search, |
58 | state, | 92 | state, |
93 | filter, | ||
59 | videoIs, | 94 | videoIs, |
60 | searchReporter, | 95 | searchReporter, |
61 | searchReportee, | 96 | searchReportee, |
@@ -75,12 +110,11 @@ function getAbusesList (options: { | |||
75 | function updateAbuse ( | 110 | function updateAbuse ( |
76 | url: string, | 111 | url: string, |
77 | token: string, | 112 | token: string, |
78 | videoId: string | number, | 113 | abuseId: number, |
79 | videoAbuseId: number, | ||
80 | body: AbuseUpdate, | 114 | body: AbuseUpdate, |
81 | statusCodeExpected = 204 | 115 | statusCodeExpected = 204 |
82 | ) { | 116 | ) { |
83 | const path = '/api/v1/videos/' + videoId + '/abuse/' + videoAbuseId | 117 | const path = '/api/v1/abuses/' + abuseId |
84 | 118 | ||
85 | return makePutBodyRequest({ | 119 | return makePutBodyRequest({ |
86 | url, | 120 | url, |
@@ -91,8 +125,8 @@ function updateAbuse ( | |||
91 | }) | 125 | }) |
92 | } | 126 | } |
93 | 127 | ||
94 | function deleteAbuse (url: string, token: string, videoId: string | number, videoAbuseId: number, statusCodeExpected = 204) { | 128 | function deleteAbuse (url: string, token: string, abuseId: number, statusCodeExpected = 204) { |
95 | const path = '/api/v1/videos/' + videoId + '/abuse/' + videoAbuseId | 129 | const path = '/api/v1/abuses/' + abuseId |
96 | 130 | ||
97 | return makeDeleteRequest({ | 131 | return makeDeleteRequest({ |
98 | url, | 132 | 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 @@ | |||
1 | import { AbusePredefinedReasonsString } from './abuse-reason.model' | 1 | import { AbusePredefinedReasonsString } from './abuse-reason.model' |
2 | 2 | ||
3 | export interface AbuseCreate { | 3 | export interface AbuseCreate { |
4 | accountId: number | ||
5 | |||
6 | reason: string | 4 | reason: string |
5 | |||
7 | predefinedReasons?: AbusePredefinedReasonsString[] | 6 | predefinedReasons?: AbusePredefinedReasonsString[] |
8 | 7 | ||
8 | account?: { | ||
9 | id: number | ||
10 | } | ||
11 | |||
9 | video?: { | 12 | video?: { |
10 | id: number | 13 | id: number |
11 | startAt?: number | 14 | 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 @@ | |||
1 | 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 { | |||
9 | name: string | 9 | name: string |
10 | uuid: string | 10 | uuid: string |
11 | nsfw: boolean | 11 | nsfw: boolean |
12 | |||
12 | deleted: boolean | 13 | deleted: boolean |
13 | blacklisted: boolean | 14 | blacklisted: boolean |
14 | 15 | ||
@@ -21,8 +22,15 @@ export interface VideoAbuse { | |||
21 | 22 | ||
22 | export interface VideoCommentAbuse { | 23 | export interface VideoCommentAbuse { |
23 | id: number | 24 | id: number |
24 | account?: Account | 25 | |
26 | video: { | ||
27 | id: number | ||
28 | name: string | ||
29 | uuid: string | ||
30 | } | ||
31 | |||
25 | text: string | 32 | text: string |
33 | |||
26 | deleted: boolean | 34 | deleted: boolean |
27 | } | 35 | } |
28 | 36 | ||
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 @@ | |||
1 | export * from './abuse-create.model' | 1 | export * from './abuse-create.model' |
2 | export * from './abuse-filter.type' | ||
2 | export * from './abuse-reason.model' | 3 | export * from './abuse-reason.model' |
3 | export * from './abuse-state.model' | 4 | export * from './abuse-state.model' |
4 | export * from './abuse-update.model' | 5 | export * from './abuse-update.model' |