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 --- .../app/shared/users/user-notification.model.ts | 6 +++ .../shared/users/user-notifications.component.html | 8 ++++ .../video-blacklist/video-blacklist.service.ts | 51 +++++++++++++++++----- 3 files changed, 55 insertions(+), 10 deletions(-) (limited to 'client/src/app/shared') diff --git a/client/src/app/shared/users/user-notification.model.ts b/client/src/app/shared/users/user-notification.model.ts index 097830752..7d0eb5ea2 100644 --- a/client/src/app/shared/users/user-notification.model.ts +++ b/client/src/app/shared/users/user-notification.model.ts @@ -54,6 +54,7 @@ export class UserNotification implements UserNotificationServer { videoUrl?: string commentUrl?: any[] videoAbuseUrl?: string + videoAutoBlacklistUrl?: string accountUrl?: string videoImportIdentifier?: string videoImportUrl?: string @@ -107,6 +108,11 @@ export class UserNotification implements UserNotificationServer { this.videoUrl = this.buildVideoUrl(this.videoAbuse.video) break + case UserNotificationType.VIDEO_AUTO_BLACKLIST_FOR_MODERATORS: + this.videoAutoBlacklistUrl = '/admin/moderation/video-auto-blacklist/list' + this.videoUrl = this.buildVideoUrl(this.video) + break + case UserNotificationType.BLACKLIST_ON_MY_VIDEO: this.videoUrl = this.buildVideoUrl(this.videoBlacklist.video) break diff --git a/client/src/app/shared/users/user-notifications.component.html b/client/src/app/shared/users/user-notifications.component.html index 1c0af1bb0..6d2f2750e 100644 --- a/client/src/app/shared/users/user-notifications.component.html +++ b/client/src/app/shared/users/user-notifications.component.html @@ -36,6 +36,14 @@ + + + +
+ The recently added video {{ notification.video.name }} has been auto-blacklisted +
+
+ diff --git a/client/src/app/shared/video-blacklist/video-blacklist.service.ts b/client/src/app/shared/video-blacklist/video-blacklist.service.ts index 94e46d7c2..a9eab9b6f 100644 --- a/client/src/app/shared/video-blacklist/video-blacklist.service.ts +++ b/client/src/app/shared/video-blacklist/video-blacklist.service.ts @@ -1,11 +1,13 @@ -import { catchError, map } from 'rxjs/operators' +import { catchError, map, concatMap, toArray } from 'rxjs/operators' import { HttpClient, HttpParams } from '@angular/common/http' import { Injectable } from '@angular/core' import { SortMeta } from 'primeng/components/common/sortmeta' -import { Observable } from 'rxjs' -import { VideoBlacklist, ResultList } from '../../../../../shared' +import { from as observableFrom, Observable } from 'rxjs' +import { VideoBlacklist, VideoBlacklistType, ResultList } from '../../../../../shared' +import { Video } from '../video/video.model' import { environment } from '../../../environments/environment' import { RestExtractor, RestPagination, RestService } from '../rest' +import { ComponentPagination } from '../rest/component-pagination.model' @Injectable() export class VideoBlacklistService { @@ -17,10 +19,14 @@ export class VideoBlacklistService { private restExtractor: RestExtractor ) {} - listBlacklist (pagination: RestPagination, sort: SortMeta): Observable> { + listBlacklist (pagination: RestPagination, sort: SortMeta, type?: VideoBlacklistType): Observable> { let params = new HttpParams() params = this.restService.addRestGetParams(params, pagination, sort) + if (type) { + params = params.set('type', type.toString()) + } + return this.authHttp.get>(VideoBlacklistService.BASE_VIDEOS_URL + 'blacklist', { params }) .pipe( map(res => this.restExtractor.convertResultListDateToHuman(res)), @@ -28,12 +34,37 @@ export class VideoBlacklistService { ) } - removeVideoFromBlacklist (videoId: number) { - return this.authHttp.delete(VideoBlacklistService.BASE_VIDEOS_URL + videoId + '/blacklist') - .pipe( - map(this.restExtractor.extractDataBool), - catchError(res => this.restExtractor.handleError(res)) - ) + getAutoBlacklistedAsVideoList (videoPagination: ComponentPagination): Observable<{ videos: Video[], totalVideos: number}> { + const pagination = this.restService.componentPaginationToRestPagination(videoPagination) + + // prioritize first created since waiting longest + const AUTO_BLACKLIST_SORT = 'createdAt' + + let params = new HttpParams() + params = this.restService.addRestGetParams(params, pagination, AUTO_BLACKLIST_SORT) + + params = params.set('type', VideoBlacklistType.AUTO_BEFORE_PUBLISHED.toString()) + + return this.authHttp.get>(VideoBlacklistService.BASE_VIDEOS_URL + 'blacklist', { params }) + .pipe( + map(res => { + const videos = res.data.map(videoBlacklist => new Video(videoBlacklist.video)) + const totalVideos = res.total + return { videos, totalVideos } + }), + catchError(res => this.restExtractor.handleError(res)) + ) + } + + removeVideoFromBlacklist (videoIdArgs: number | number[]) { + const videoIds = Array.isArray(videoIdArgs) ? videoIdArgs : [ videoIdArgs ] + + return observableFrom(videoIds) + .pipe( + concatMap(id => this.authHttp.delete(VideoBlacklistService.BASE_VIDEOS_URL + id + '/blacklist')), + toArray(), + catchError(err => this.restExtractor.handleError(err)) + ) } blacklistVideo (videoId: number, reason: string, unfederate: boolean) { -- cgit v1.2.3