From 7ccddd7b5250bd25a917a6e77e58b87b9484a2a4 Mon Sep 17 00:00:00 2001 From: Josh Morel Date: Tue, 2 Apr 2019 05:26:47 -0400 Subject: add quarantine videos feature (#1637) * add quarantine videos feature * increase Notification settings test timeout to 20000ms. was completing 7000 locally but timing out after 10000 on travis * fix quarantine video test issues -propagate misspelling -remove skip from server/tests/client.ts * WIP use blacklist for moderator video approval instead of video.quarantine boolean * finish auto-blacklist feature --- shared/models/server/custom-config.model.ts | 9 ++++++ shared/models/server/server-config.model.ts | 8 +++++ .../users/user-notification-setting.model.ts | 1 + shared/models/users/user-notification.model.ts | 4 ++- .../videos/blacklist/video-blacklist.model.ts | 20 ++++++------- shared/utils/server/config.ts | 7 +++++ shared/utils/users/user-notifications.ts | 35 ++++++++++++++++++++-- shared/utils/videos/video-blacklist.ts | 13 ++++++++ shared/utils/videos/video-change-ownership.ts | 4 +-- 9 files changed, 84 insertions(+), 17 deletions(-) (limited to 'shared') diff --git a/shared/models/server/custom-config.model.ts b/shared/models/server/custom-config.model.ts index 20b261426..1607b40a8 100644 --- a/shared/models/server/custom-config.model.ts +++ b/shared/models/server/custom-config.model.ts @@ -77,4 +77,13 @@ export interface CustomConfig { } } } + + autoBlacklist: { + videos: { + ofUsers: { + enabled: boolean + } + } + } + } diff --git a/shared/models/server/server-config.model.ts b/shared/models/server/server-config.model.ts index 0200d88ca..dcc45be8a 100644 --- a/shared/models/server/server-config.model.ts +++ b/shared/models/server/server-config.model.ts @@ -49,6 +49,14 @@ export interface ServerConfig { } } + autoBlacklist: { + videos: { + ofUsers: { + enabled: boolean + } + } + } + avatar: { file: { size: { diff --git a/shared/models/users/user-notification-setting.model.ts b/shared/models/users/user-notification-setting.model.ts index 531e12bba..57b33e4b8 100644 --- a/shared/models/users/user-notification-setting.model.ts +++ b/shared/models/users/user-notification-setting.model.ts @@ -8,6 +8,7 @@ export interface UserNotificationSetting { newVideoFromSubscription: UserNotificationSettingValue newCommentOnMyVideo: UserNotificationSettingValue videoAbuseAsModerator: UserNotificationSettingValue + videoAutoBlacklistAsModerator: UserNotificationSettingValue blacklistOnMyVideo: UserNotificationSettingValue myVideoPublished: UserNotificationSettingValue myVideoImportFinished: UserNotificationSettingValue diff --git a/shared/models/users/user-notification.model.ts b/shared/models/users/user-notification.model.ts index 186b62612..19892b61a 100644 --- a/shared/models/users/user-notification.model.ts +++ b/shared/models/users/user-notification.model.ts @@ -13,7 +13,9 @@ export enum UserNotificationType { NEW_USER_REGISTRATION = 9, NEW_FOLLOW = 10, - COMMENT_MENTION = 11 + COMMENT_MENTION = 11, + + VIDEO_AUTO_BLACKLIST_FOR_MODERATORS = 12 } export interface VideoInfo { diff --git a/shared/models/videos/blacklist/video-blacklist.model.ts b/shared/models/videos/blacklist/video-blacklist.model.ts index 4bd976190..68d59e489 100644 --- a/shared/models/videos/blacklist/video-blacklist.model.ts +++ b/shared/models/videos/blacklist/video-blacklist.model.ts @@ -1,19 +1,17 @@ +import { Video } from '../video.model' + +export enum VideoBlacklistType { + MANUAL = 1, + AUTO_BEFORE_PUBLISHED = 2 +} + export interface VideoBlacklist { id: number createdAt: Date updatedAt: Date unfederated: boolean reason?: string + type: VideoBlacklistType - video: { - id: number - name: string - uuid: string - description: string - duration: number - views: number - likes: number - dislikes: number - nsfw: boolean - } + video: Video } diff --git a/shared/utils/server/config.ts b/shared/utils/server/config.ts index 0e16af0f2..eaa493a93 100644 --- a/shared/utils/server/config.ts +++ b/shared/utils/server/config.ts @@ -112,6 +112,13 @@ function updateCustomSubConfig (url: string, token: string, newConfig: any) { enabled: false } } + }, + autoBlacklist: { + videos: { + ofUsers: { + enabled: false + } + } } } diff --git a/shared/utils/users/user-notifications.ts b/shared/utils/users/user-notifications.ts index c8ed7df30..e3a79f523 100644 --- a/shared/utils/users/user-notifications.ts +++ b/shared/utils/users/user-notifications.ts @@ -18,7 +18,7 @@ function updateMyNotificationSettings (url: string, token: string, settings: Use }) } -function getUserNotifications ( +async function getUserNotifications ( url: string, token: string, start: number, @@ -165,12 +165,15 @@ async function checkNewVideoFromSubscription (base: CheckerBaseParams, videoName checkVideo(notification.video, videoName, videoUUID) checkActor(notification.video.channel) } else { - expect(notification.video).to.satisfy(v => v === undefined || v.name !== videoName) + expect(notification).to.satisfy((n: UserNotification) => { + return n === undefined || n.type !== UserNotificationType.NEW_VIDEO_FROM_SUBSCRIPTION || n.video.name !== videoName + }) } } function emailFinder (email: object) { - return email[ 'text' ].indexOf(videoUUID) !== -1 + const text = email[ 'text' ] + return text.indexOf(videoUUID) !== -1 && text.indexOf('Your subscription') !== -1 } await checkNotification(base, notificationChecker, emailFinder, type) @@ -387,6 +390,31 @@ async function checkNewVideoAbuseForModerators (base: CheckerBaseParams, videoUU await checkNotification(base, notificationChecker, emailFinder, type) } +async function checkVideoAutoBlacklistForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) { + const notificationType = UserNotificationType.VIDEO_AUTO_BLACKLIST_FOR_MODERATORS + + function notificationChecker (notification: UserNotification, type: CheckerType) { + if (type === 'presence') { + expect(notification).to.not.be.undefined + expect(notification.type).to.equal(notificationType) + + expect(notification.video.id).to.be.a('number') + checkVideo(notification.video, videoName, videoUUID) + } else { + expect(notification).to.satisfy((n: UserNotification) => { + return n === undefined || n.video === undefined || n.video.uuid !== videoUUID + }) + } + } + + function emailFinder (email: object) { + const text = email[ 'text' ] + return text.indexOf(videoUUID) !== -1 && email[ 'text' ].indexOf('video-auto-blacklist/list') !== -1 + } + + await checkNotification(base, notificationChecker, emailFinder, type) +} + async function checkNewBlacklistOnMyVideo ( base: CheckerBaseParams, videoUUID: string, @@ -431,6 +459,7 @@ export { checkCommentMention, updateMyNotificationSettings, checkNewVideoAbuseForModerators, + checkVideoAutoBlacklistForModerators, getUserNotifications, markAsReadNotifications, getLastNotification diff --git a/shared/utils/videos/video-blacklist.ts b/shared/utils/videos/video-blacklist.ts index f2ae0ed26..82d5b7e31 100644 --- a/shared/utils/videos/video-blacklist.ts +++ b/shared/utils/videos/video-blacklist.ts @@ -51,6 +51,18 @@ function getBlacklistedVideosList (url: string, token: string, specialStatus = 2 .expect('Content-Type', /json/) } +function getBlacklistedVideosListWithTypeFilter (url: string, token: string, type: number, specialStatus = 200) { + const path = '/api/v1/videos/blacklist/' + + return request(url) + .get(path) + .query({ sort: 'createdAt', type }) + .set('Accept', 'application/json') + .set('Authorization', 'Bearer ' + token) + .expect(specialStatus) + .expect('Content-Type', /json/) +} + function getSortedBlacklistedVideosList (url: string, token: string, sort: string, specialStatus = 200) { const path = '/api/v1/videos/blacklist/' @@ -69,6 +81,7 @@ export { addVideoToBlacklist, removeVideoFromBlacklist, getBlacklistedVideosList, + getBlacklistedVideosListWithTypeFilter, getSortedBlacklistedVideosList, updateVideoBlacklist } diff --git a/shared/utils/videos/video-change-ownership.ts b/shared/utils/videos/video-change-ownership.ts index f288692ea..371d02000 100644 --- a/shared/utils/videos/video-change-ownership.ts +++ b/shared/utils/videos/video-change-ownership.ts @@ -1,6 +1,6 @@ import * as request from 'supertest' -function changeVideoOwnership (url: string, token: string, videoId: number | string, username) { +function changeVideoOwnership (url: string, token: string, videoId: number | string, username, expectedStatus = 204) { const path = '/api/v1/videos/' + videoId + '/give-ownership' return request(url) @@ -8,7 +8,7 @@ function changeVideoOwnership (url: string, token: string, videoId: number | str .set('Accept', 'application/json') .set('Authorization', 'Bearer ' + token) .send({ username }) - .expect(204) + .expect(expectedStatus) } function getVideoChangeOwnershipList (url: string, token: string) { -- cgit v1.2.3