From 191764f30b0a812bf3a9dbdc7daf1d5afe25e12a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 14 Aug 2018 09:08:47 +0200 Subject: Improve blacklist management --- server/models/video/video-abuse.ts | 1 - server/models/video/video-blacklist.ts | 11 ++++++++--- server/models/video/video.ts | 31 +++++++++++++++++++++++++++---- 3 files changed, 35 insertions(+), 8 deletions(-) (limited to 'server/models') diff --git a/server/models/video/video-abuse.ts b/server/models/video/video-abuse.ts index 10a191372..dbb88ca45 100644 --- a/server/models/video/video-abuse.ts +++ b/server/models/video/video-abuse.ts @@ -137,7 +137,6 @@ export class VideoAbuseModel extends Model { video: { id: this.Video.id, uuid: this.Video.uuid, - url: this.Video.url, name: this.Video.name }, createdAt: this.createdAt diff --git a/server/models/video/video-blacklist.ts b/server/models/video/video-blacklist.ts index 1b8a338cb..eabc37ef0 100644 --- a/server/models/video/video-blacklist.ts +++ b/server/models/video/video-blacklist.ts @@ -16,7 +16,7 @@ import { getSortOnModel, throwIfNotValid } from '../utils' import { VideoModel } from './video' import { isVideoBlacklistReasonValid } from '../../helpers/custom-validators/video-blacklist' import { Emailer } from '../../lib/emailer' -import { BlacklistedVideo } from '../../../shared/models/videos' +import { VideoBlacklist } from '../../../shared/models/videos' import { CONSTRAINTS_FIELDS } from '../../initializers' @Table({ @@ -68,7 +68,12 @@ export class VideoBlacklistModel extends Model { offset: start, limit: count, order: getSortOnModel(sort.sortModel, sort.sortValue), - include: [ { model: VideoModel } ] + include: [ + { + model: VideoModel, + required: true + } + ] } return VideoBlacklistModel.findAndCountAll(query) @@ -90,7 +95,7 @@ export class VideoBlacklistModel extends Model { return VideoBlacklistModel.findOne(query) } - toFormattedJSON (): BlacklistedVideo { + toFormattedJSON (): VideoBlacklist { const video = this.Video return { diff --git a/server/models/video/video.ts b/server/models/video/video.ts index f3a900bc9..b13dee403 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -127,7 +127,8 @@ export enum ScopeNames { WITH_ACCOUNT_DETAILS = 'WITH_ACCOUNT_DETAILS', WITH_TAGS = 'WITH_TAGS', WITH_FILES = 'WITH_FILES', - WITH_SCHEDULED_UPDATE = 'WITH_SCHEDULED_UPDATE' + WITH_SCHEDULED_UPDATE = 'WITH_SCHEDULED_UPDATE', + WITH_BLACKLISTED = 'WITH_BLACKLISTED' } type AvailableForListOptions = { @@ -374,6 +375,15 @@ type AvailableForListOptions = { [ScopeNames.WITH_TAGS]: { include: [ () => TagModel ] }, + [ScopeNames.WITH_BLACKLISTED]: { + include: [ + { + attributes: [ 'id', 'reason' ], + model: () => VideoBlacklistModel, + required: false + } + ] + }, [ScopeNames.WITH_FILES]: { include: [ { @@ -1004,7 +1014,13 @@ export class VideoModel extends Model { } return VideoModel - .scope([ ScopeNames.WITH_TAGS, ScopeNames.WITH_FILES, ScopeNames.WITH_ACCOUNT_DETAILS, ScopeNames.WITH_SCHEDULED_UPDATE ]) + .scope([ + ScopeNames.WITH_TAGS, + ScopeNames.WITH_BLACKLISTED, + ScopeNames.WITH_FILES, + ScopeNames.WITH_ACCOUNT_DETAILS, + ScopeNames.WITH_SCHEDULED_UPDATE + ]) .findById(id, options) } @@ -1030,7 +1046,13 @@ export class VideoModel extends Model { } return VideoModel - .scope([ ScopeNames.WITH_TAGS, ScopeNames.WITH_FILES, ScopeNames.WITH_ACCOUNT_DETAILS, ScopeNames.WITH_SCHEDULED_UPDATE ]) + .scope([ + ScopeNames.WITH_TAGS, + ScopeNames.WITH_BLACKLISTED, + ScopeNames.WITH_FILES, + ScopeNames.WITH_ACCOUNT_DETAILS, + ScopeNames.WITH_SCHEDULED_UPDATE + ]) .findOne(options) } @@ -1276,7 +1298,8 @@ export class VideoModel extends Model { toFormattedDetailsJSON (): VideoDetails { const formattedJson = this.toFormattedJSON({ additionalAttributes: { - scheduledUpdate: true + scheduledUpdate: true, + blacklistInfo: true } }) -- cgit v1.2.3