From e0a929179a9dc76e035ca7fda2b61d5ff46afbc5 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Sun, 19 Apr 2020 14:11:40 +0200 Subject: Add filter inputs for blacklisted videos and muted accounts/servers --- server/models/video/video-abuse.ts | 18 ++++++------------ server/models/video/video-blacklist.ts | 13 +++++++++++-- 2 files changed, 17 insertions(+), 14 deletions(-) (limited to 'server/models/video') diff --git a/server/models/video/video-abuse.ts b/server/models/video/video-abuse.ts index d68608ca6..e8c3bd823 100644 --- a/server/models/video/video-abuse.ts +++ b/server/models/video/video-abuse.ts @@ -9,7 +9,7 @@ import { isVideoAbuseStateValid } from '../../helpers/custom-validators/video-abuses' import { AccountModel } from '../account/account' -import { buildBlockedAccountSQL, getSort, throwIfNotValid } from '../utils' +import { buildBlockedAccountSQL, getSort, throwIfNotValid, searchAttribute } from '../utils' import { VideoModel } from './video' import { VideoAbuseState, VideoDetails } from '../../../shared' import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers/constants' @@ -17,8 +17,8 @@ import { MUserAccountId, MVideoAbuse, MVideoAbuseFormattable, MVideoAbuseVideo } import * as Bluebird from 'bluebird' import { literal, Op } from 'sequelize' import { ThumbnailModel } from './thumbnail' -import { VideoChannelModel } from './video-channel' import { VideoBlacklistModel } from './video-blacklist' +import { ScopeNames as VideoChannelScopeNames, SummaryOptions, VideoChannelModel } from './video-channel' export enum ScopeNames { FOR_API = 'FOR_API' @@ -33,12 +33,6 @@ export enum ScopeNames { serverAccountId: number userAccountId: any }) => { - const search = (sourceField, targetField) => sourceField ? ({ - [targetField]: { - [Op.iLike]: `%${sourceField}%` - } - }) : {} - let where = { reporterAccountId: { [Op.notIn]: literal('(' + buildBlockedAccountSQL(options.serverAccountId, options.userAccountId) + ')') @@ -148,19 +142,19 @@ export enum ScopeNames { { model: AccountModel, required: true, - where: { ...search(options.searchReporter, 'name') } + where: { ...searchAttribute(options.searchReporter, 'name') } }, { model: VideoModel, required: false, - where: { ...search(options.searchVideo, 'name') }, + where: { ...searchAttribute(options.searchVideo, 'name') }, include: [ { model: ThumbnailModel }, { - model: VideoChannelModel.scope([ 'WITH_ACTOR', 'WITH_ACCOUNT' ]), - where: { ...search(options.searchVideoChannel, 'name') } + model: VideoChannelModel.scope({ method: [ VideoChannelScopeNames.SUMMARY, { withAccount: true } as SummaryOptions ] }), + where: { ...searchAttribute(options.searchVideoChannel, 'name') } }, { attributes: [ 'id', 'reason', 'unfederated' ], diff --git a/server/models/video/video-blacklist.ts b/server/models/video/video-blacklist.ts index 694983cb3..680eba471 100644 --- a/server/models/video/video-blacklist.ts +++ b/server/models/video/video-blacklist.ts @@ -1,5 +1,5 @@ import { AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' -import { getBlacklistSort, SortType, throwIfNotValid } from '../utils' +import { getBlacklistSort, SortType, throwIfNotValid, searchAttribute } from '../utils' import { VideoModel } from './video' import { ScopeNames as VideoChannelScopeNames, SummaryOptions, VideoChannelModel } from './video-channel' import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../helpers/custom-validators/video-blacklist' @@ -54,7 +54,15 @@ export class VideoBlacklistModel extends Model { }) Video: VideoModel - static listForApi (start: number, count: number, sort: SortType, type?: VideoBlacklistType) { + static listForApi (parameters: { + start: number + count: number + sort: SortType + search?: string + type?: VideoBlacklistType + }) { + const { start, count, sort, search, type } = parameters + function buildBaseQuery (): FindOptions { return { offset: start, @@ -70,6 +78,7 @@ export class VideoBlacklistModel extends Model { { model: VideoModel, required: true, + where: { ...searchAttribute(search, 'name') }, include: [ { model: VideoChannelModel.scope({ method: [ VideoChannelScopeNames.SUMMARY, { withAccount: true } as SummaryOptions ] }), -- cgit v1.2.3