aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils
diff options
context:
space:
mode:
Diffstat (limited to 'shared/extra-utils')
-rw-r--r--shared/extra-utils/index.ts1
-rw-r--r--shared/extra-utils/moderation/abuses.ts156
-rw-r--r--shared/extra-utils/server/servers.ts4
-rw-r--r--shared/extra-utils/users/user-notifications.ts83
-rw-r--r--shared/extra-utils/videos/video-abuses.ts18
5 files changed, 239 insertions, 23 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'
17export * from './videos/video-playlists' 17export * from './videos/video-playlists'
18export * from './users/users' 18export * from './users/users'
19export * from './users/accounts' 19export * from './users/accounts'
20export * from './moderation/abuses'
20export * from './videos/video-abuses' 21export * from './videos/video-abuses'
21export * from './videos/video-blacklist' 22export * from './videos/video-blacklist'
22export * from './videos/video-captions' 23export * 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..62af9556e
--- /dev/null
+++ b/shared/extra-utils/moderation/abuses.ts
@@ -0,0 +1,156 @@
1
2import { AbuseFilter, AbusePredefinedReasonsString, AbuseState, AbuseUpdate, AbuseVideoIs } from '@shared/models'
3import { makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests'
4
5function reportAbuse (options: {
6 url: string
7 token: string
8
9 reason: string
10
11 accountId?: number
12 videoId?: number
13 commentId?: number
14
15 predefinedReasons?: AbusePredefinedReasonsString[]
16
17 startAt?: number
18 endAt?: number
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 })
55}
56
57function getAbusesList (options: {
58 url: string
59 token: string
60
61 start?: number
62 count?: number
63 sort?: string
64
65 id?: number
66 predefinedReason?: AbusePredefinedReasonsString
67 search?: string
68 filter?: AbuseFilter
69 state?: AbuseState
70 videoIs?: AbuseVideoIs
71 searchReporter?: string
72 searchReportee?: string
73 searchVideo?: string
74 searchVideoChannel?: string
75}) {
76 const {
77 url,
78 token,
79 start,
80 count,
81 sort,
82 id,
83 predefinedReason,
84 search,
85 filter,
86 state,
87 videoIs,
88 searchReporter,
89 searchReportee,
90 searchVideo,
91 searchVideoChannel
92 } = options
93 const path = '/api/v1/abuses'
94
95 const query = {
96 id,
97 predefinedReason,
98 search,
99 state,
100 filter,
101 videoIs,
102 start,
103 count,
104 sort: sort || 'createdAt',
105 searchReporter,
106 searchReportee,
107 searchVideo,
108 searchVideoChannel
109 }
110
111 return makeGetRequest({
112 url,
113 path,
114 token,
115 query,
116 statusCodeExpected: 200
117 })
118}
119
120function updateAbuse (
121 url: string,
122 token: string,
123 abuseId: number,
124 body: AbuseUpdate,
125 statusCodeExpected = 204
126) {
127 const path = '/api/v1/abuses/' + abuseId
128
129 return makePutBodyRequest({
130 url,
131 token,
132 path,
133 fields: body,
134 statusCodeExpected
135 })
136}
137
138function deleteAbuse (url: string, token: string, abuseId: number, statusCodeExpected = 204) {
139 const path = '/api/v1/abuses/' + abuseId
140
141 return makeDeleteRequest({
142 url,
143 token,
144 path,
145 statusCodeExpected
146 })
147}
148
149// ---------------------------------------------------------------------------
150
151export {
152 reportAbuse,
153 getAbusesList,
154 updateAbuse,
155 deleteAbuse
156}
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts
index 0f883d839..994aac628 100644
--- a/shared/extra-utils/server/servers.ts
+++ b/shared/extra-utils/server/servers.ts
@@ -37,8 +37,8 @@ interface ServerInfo {
37 video?: { 37 video?: {
38 id: number 38 id: number
39 uuid: string 39 uuid: string
40 name: string 40 name?: string
41 account: { 41 account?: {
42 name: string 42 name: string
43 } 43 }
44 } 44 }
diff --git a/shared/extra-utils/users/user-notifications.ts b/shared/extra-utils/users/user-notifications.ts
index a17a39de9..2061e3353 100644
--- a/shared/extra-utils/users/user-notifications.ts
+++ b/shared/extra-utils/users/user-notifications.ts
@@ -139,13 +139,17 @@ async function checkNotification (
139} 139}
140 140
141function checkVideo (video: any, videoName?: string, videoUUID?: string) { 141function checkVideo (video: any, videoName?: string, videoUUID?: string) {
142 expect(video.name).to.be.a('string') 142 if (videoName) {
143 expect(video.name).to.not.be.empty 143 expect(video.name).to.be.a('string')
144 if (videoName) expect(video.name).to.equal(videoName) 144 expect(video.name).to.not.be.empty
145 expect(video.name).to.equal(videoName)
146 }
145 147
146 expect(video.uuid).to.be.a('string') 148 if (videoUUID) {
147 expect(video.uuid).to.not.be.empty 149 expect(video.uuid).to.be.a('string')
148 if (videoUUID) expect(video.uuid).to.equal(videoUUID) 150 expect(video.uuid).to.not.be.empty
151 expect(video.uuid).to.equal(videoUUID)
152 }
149 153
150 expect(video.id).to.be.a('number') 154 expect(video.id).to.be.a('number')
151} 155}
@@ -436,18 +440,43 @@ async function checkNewCommentOnMyVideo (base: CheckerBaseParams, uuid: string,
436} 440}
437 441
438async function checkNewVideoAbuseForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) { 442async function checkNewVideoAbuseForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) {
439 const notificationType = UserNotificationType.NEW_VIDEO_ABUSE_FOR_MODERATORS 443 const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS
444
445 function notificationChecker (notification: UserNotification, type: CheckerType) {
446 if (type === 'presence') {
447 expect(notification).to.not.be.undefined
448 expect(notification.type).to.equal(notificationType)
449
450 expect(notification.abuse.id).to.be.a('number')
451 checkVideo(notification.abuse.video, videoName, videoUUID)
452 } else {
453 expect(notification).to.satisfy((n: UserNotification) => {
454 return n === undefined || n.abuse === undefined || n.abuse.video.uuid !== videoUUID
455 })
456 }
457 }
458
459 function emailNotificationFinder (email: object) {
460 const text = email['text']
461 return text.indexOf(videoUUID) !== -1 && text.indexOf('abuse') !== -1
462 }
463
464 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
465}
466
467async function checkNewCommentAbuseForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) {
468 const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS
440 469
441 function notificationChecker (notification: UserNotification, type: CheckerType) { 470 function notificationChecker (notification: UserNotification, type: CheckerType) {
442 if (type === 'presence') { 471 if (type === 'presence') {
443 expect(notification).to.not.be.undefined 472 expect(notification).to.not.be.undefined
444 expect(notification.type).to.equal(notificationType) 473 expect(notification.type).to.equal(notificationType)
445 474
446 expect(notification.videoAbuse.id).to.be.a('number') 475 expect(notification.abuse.id).to.be.a('number')
447 checkVideo(notification.videoAbuse.video, videoName, videoUUID) 476 checkVideo(notification.abuse.comment.video, videoName, videoUUID)
448 } else { 477 } else {
449 expect(notification).to.satisfy((n: UserNotification) => { 478 expect(notification).to.satisfy((n: UserNotification) => {
450 return n === undefined || n.videoAbuse === undefined || n.videoAbuse.video.uuid !== videoUUID 479 return n === undefined || n.abuse === undefined || n.abuse.comment.video.uuid !== videoUUID
451 }) 480 })
452 } 481 }
453 } 482 }
@@ -460,6 +489,31 @@ async function checkNewVideoAbuseForModerators (base: CheckerBaseParams, videoUU
460 await checkNotification(base, notificationChecker, emailNotificationFinder, type) 489 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
461} 490}
462 491
492async function checkNewAccountAbuseForModerators (base: CheckerBaseParams, displayName: string, type: CheckerType) {
493 const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS
494
495 function notificationChecker (notification: UserNotification, type: CheckerType) {
496 if (type === 'presence') {
497 expect(notification).to.not.be.undefined
498 expect(notification.type).to.equal(notificationType)
499
500 expect(notification.abuse.id).to.be.a('number')
501 expect(notification.abuse.account.displayName).to.equal(displayName)
502 } else {
503 expect(notification).to.satisfy((n: UserNotification) => {
504 return n === undefined || n.abuse === undefined || n.abuse.account.displayName !== displayName
505 })
506 }
507 }
508
509 function emailNotificationFinder (email: object) {
510 const text = email['text']
511 return text.indexOf(displayName) !== -1 && text.indexOf('abuse') !== -1
512 }
513
514 await checkNotification(base, notificationChecker, emailNotificationFinder, type)
515}
516
463async function checkVideoAutoBlacklistForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) { 517async function checkVideoAutoBlacklistForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) {
464 const notificationType = UserNotificationType.VIDEO_AUTO_BLACKLIST_FOR_MODERATORS 518 const notificationType = UserNotificationType.VIDEO_AUTO_BLACKLIST_FOR_MODERATORS
465 519
@@ -516,7 +570,7 @@ function getAllNotificationsSettings () {
516 return { 570 return {
517 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, 571 newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
518 newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, 572 newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
519 videoAbuseAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, 573 abuseAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
520 videoAutoBlacklistAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, 574 videoAutoBlacklistAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
521 blacklistOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, 575 blacklistOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
522 myVideoImportFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, 576 myVideoImportFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL,
@@ -541,6 +595,9 @@ async function prepareNotificationsTest (serversCount = 3) {
541 smtp: { 595 smtp: {
542 hostname: 'localhost', 596 hostname: 'localhost',
543 port 597 port
598 },
599 signup: {
600 limit: 20
544 } 601 }
545 } 602 }
546 const servers = await flushAndRunMultipleServers(serversCount, overrideConfig) 603 const servers = await flushAndRunMultipleServers(serversCount, overrideConfig)
@@ -623,5 +680,7 @@ export {
623 markAsReadNotifications, 680 markAsReadNotifications,
624 getLastNotification, 681 getLastNotification,
625 checkNewInstanceFollower, 682 checkNewInstanceFollower,
626 prepareNotificationsTest 683 prepareNotificationsTest,
684 checkNewCommentAbuseForModerators,
685 checkNewAccountAbuseForModerators
627} 686}
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 @@
1import * as request from 'supertest' 1import * as request from 'supertest'
2import { VideoAbuseUpdate } from '../../models/videos/abuse/video-abuse-update.model' 2import { AbusePredefinedReasonsString, AbuseState, AbuseUpdate, AbuseVideoIs } from '@shared/models'
3import { makeDeleteRequest, makePutBodyRequest, makeGetRequest } from '../requests/requests' 3import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests'
4import { VideoAbuseState, VideoAbusePredefinedReasonsString } from '@shared/models' 4
5import { VideoAbuseVideoIs } from '@shared/models/videos/abuse/video-abuse-video-is.type' 5// FIXME: deprecated in 2.3. Remove this file
6 6
7function reportVideoAbuse ( 7function 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