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 --- server/models/video/schedule-video-update.ts | 3 +- server/models/video/video-blacklist.ts | 56 ++++++++++++++++++---------- 2 files changed, 39 insertions(+), 20 deletions(-) (limited to 'server/models/video') diff --git a/server/models/video/schedule-video-update.ts b/server/models/video/schedule-video-update.ts index 1e56562e1..abddc1111 100644 --- a/server/models/video/schedule-video-update.ts +++ b/server/models/video/schedule-video-update.ts @@ -72,7 +72,8 @@ export class ScheduleVideoUpdateModel extends Model { model: VideoModel.scope( [ VideoScopeNames.WITH_FILES, - VideoScopeNames.WITH_ACCOUNT_DETAILS + VideoScopeNames.WITH_ACCOUNT_DETAILS, + VideoScopeNames.WITH_BLACKLISTED ] ) } diff --git a/server/models/video/video-blacklist.ts b/server/models/video/video-blacklist.ts index 3b567e488..86b1f6acb 100644 --- a/server/models/video/video-blacklist.ts +++ b/server/models/video/video-blacklist.ts @@ -1,8 +1,21 @@ -import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' +import { + AllowNull, + BelongsTo, + Column, + CreatedAt, + DataType, + Default, + ForeignKey, + Is, Model, + Table, + UpdatedAt, + IFindOptions +} from 'sequelize-typescript' import { getSortOnModel, SortType, throwIfNotValid } from '../utils' import { VideoModel } from './video' -import { isVideoBlacklistReasonValid } from '../../helpers/custom-validators/video-blacklist' -import { VideoBlacklist } from '../../../shared/models/videos' +import { VideoChannelModel, ScopeNames as VideoChannelScopeNames } from './video-channel' +import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../helpers/custom-validators/video-blacklist' +import { VideoBlacklist, VideoBlacklistType } from '../../../shared/models/videos' import { CONSTRAINTS_FIELDS } from '../../initializers' @Table({ @@ -25,6 +38,12 @@ export class VideoBlacklistModel extends Model { @Column unfederated: boolean + @AllowNull(false) + @Default(null) + @Is('VideoBlacklistType', value => throwIfNotValid(value, isVideoBlacklistTypeValid, 'type')) + @Column + type: VideoBlacklistType + @CreatedAt createdAt: Date @@ -43,19 +62,29 @@ export class VideoBlacklistModel extends Model { }) Video: VideoModel - static listForApi (start: number, count: number, sort: SortType) { - const query = { + static listForApi (start: number, count: number, sort: SortType, type?: VideoBlacklistType) { + const query: IFindOptions = { offset: start, limit: count, order: getSortOnModel(sort.sortModel, sort.sortValue), include: [ { model: VideoModel, - required: true + required: true, + include: [ + { + model: VideoChannelModel.scope({ method: [ VideoChannelScopeNames.SUMMARY, true ] }), + required: true + } + ] } ] } + if (type) { + query.where = { type } + } + return VideoBlacklistModel.findAndCountAll(query) .then(({ rows, count }) => { return { @@ -76,26 +105,15 @@ export class VideoBlacklistModel extends Model { } toFormattedJSON (): VideoBlacklist { - const video = this.Video - return { id: this.id, createdAt: this.createdAt, updatedAt: this.updatedAt, reason: this.reason, unfederated: this.unfederated, + type: this.type, - video: { - id: video.id, - name: video.name, - uuid: video.uuid, - description: video.description, - duration: video.duration, - views: video.views, - likes: video.likes, - dislikes: video.dislikes, - nsfw: video.nsfw - } + video: this.Video.toFormattedJSON() } } } -- cgit v1.2.3