diff options
Diffstat (limited to 'shared/extra-utils')
-rw-r--r-- | shared/extra-utils/index.ts | 1 | ||||
-rw-r--r-- | shared/extra-utils/moderation/abuses.ts | 112 | ||||
-rw-r--r-- | shared/extra-utils/users/user-notifications.ts | 6 | ||||
-rw-r--r-- | shared/extra-utils/videos/video-abuses.ts | 18 |
4 files changed, 125 insertions, 12 deletions
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' | |||
17 | export * from './videos/video-playlists' | 17 | export * from './videos/video-playlists' |
18 | export * from './users/users' | 18 | export * from './users/users' |
19 | export * from './users/accounts' | 19 | export * from './users/accounts' |
20 | export * from './moderation/abuses' | ||
20 | export * from './videos/video-abuses' | 21 | export * from './videos/video-abuses' |
21 | export * from './videos/video-blacklist' | 22 | export * from './videos/video-blacklist' |
22 | export * from './videos/video-captions' | 23 | 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 @@ | |||
1 | import * as request from 'supertest' | ||
2 | import { AbusePredefinedReasonsString, AbuseState, AbuseUpdate, AbuseVideoIs } from '@shared/models' | ||
3 | import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests' | ||
4 | |||
5 | function 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 | |||
25 | function 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 | |||
75 | function 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 | |||
94 | function 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 | |||
107 | export { | ||
108 | reportAbuse, | ||
109 | getAbusesList, | ||
110 | updateAbuse, | ||
111 | deleteAbuse | ||
112 | } | ||
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 | |||
443 | expect(notification).to.not.be.undefined | 443 | expect(notification).to.not.be.undefined |
444 | expect(notification.type).to.equal(notificationType) | 444 | expect(notification.type).to.equal(notificationType) |
445 | 445 | ||
446 | expect(notification.videoAbuse.id).to.be.a('number') | 446 | expect(notification.abuse.id).to.be.a('number') |
447 | checkVideo(notification.videoAbuse.video, videoName, videoUUID) | 447 | checkVideo(notification.abuse.video, videoName, videoUUID) |
448 | } else { | 448 | } else { |
449 | expect(notification).to.satisfy((n: UserNotification) => { | 449 | expect(notification).to.satisfy((n: UserNotification) => { |
450 | return n === undefined || n.videoAbuse === undefined || n.videoAbuse.video.uuid !== videoUUID | 450 | return n === undefined || n.abuse === undefined || n.abuse.video.uuid !== videoUUID |
451 | }) | 451 | }) |
452 | } | 452 | } |
453 | } | 453 | } |
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 @@ | |||
1 | import * as request from 'supertest' | 1 | import * as request from 'supertest' |
2 | import { VideoAbuseUpdate } from '../../models/videos/abuse/video-abuse-update.model' | 2 | import { AbusePredefinedReasonsString, AbuseState, AbuseUpdate, AbuseVideoIs } from '@shared/models' |
3 | import { makeDeleteRequest, makePutBodyRequest, makeGetRequest } from '../requests/requests' | 3 | import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests' |
4 | import { VideoAbuseState, VideoAbusePredefinedReasonsString } from '@shared/models' | 4 | |
5 | import { VideoAbuseVideoIs } from '@shared/models/videos/abuse/video-abuse-video-is.type' | 5 | // FIXME: deprecated in 2.3. Remove this file |
6 | 6 | ||
7 | function reportVideoAbuse ( | 7 | function reportVideoAbuse ( |
8 | url: string, | 8 | url: string, |
9 | token: string, | 9 | token: string, |
10 | videoId: number | string, | 10 | videoId: number | string, |
11 | reason: string, | 11 | reason: string, |
12 | predefinedReasons?: VideoAbusePredefinedReasonsString[], | 12 | predefinedReasons?: AbusePredefinedReasonsString[], |
13 | startAt?: number, | 13 | startAt?: number, |
14 | endAt?: number, | 14 | endAt?: number, |
15 | specialStatus = 200 | 15 | specialStatus = 200 |
@@ -28,10 +28,10 @@ function getVideoAbusesList (options: { | |||
28 | url: string | 28 | url: string |
29 | token: string | 29 | token: string |
30 | id?: number | 30 | id?: number |
31 | predefinedReason?: VideoAbusePredefinedReasonsString | 31 | predefinedReason?: AbusePredefinedReasonsString |
32 | search?: string | 32 | search?: string |
33 | state?: VideoAbuseState | 33 | state?: AbuseState |
34 | videoIs?: VideoAbuseVideoIs | 34 | videoIs?: AbuseVideoIs |
35 | searchReporter?: string | 35 | searchReporter?: string |
36 | searchReportee?: string | 36 | searchReportee?: string |
37 | searchVideo?: string | 37 | searchVideo?: string |
@@ -79,7 +79,7 @@ function updateVideoAbuse ( | |||
79 | token: string, | 79 | token: string, |
80 | videoId: string | number, | 80 | videoId: string | number, |
81 | videoAbuseId: number, | 81 | videoAbuseId: number, |
82 | body: VideoAbuseUpdate, | 82 | body: AbuseUpdate, |
83 | statusCodeExpected = 204 | 83 | statusCodeExpected = 204 |
84 | ) { | 84 | ) { |
85 | const path = '/api/v1/videos/' + videoId + '/abuse/' + videoAbuseId | 85 | const path = '/api/v1/videos/' + videoId + '/abuse/' + videoAbuseId |