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/lib/video-blacklist.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 server/lib/video-blacklist.ts (limited to 'server/lib/video-blacklist.ts') diff --git a/server/lib/video-blacklist.ts b/server/lib/video-blacklist.ts new file mode 100644 index 000000000..dc4e0aed9 --- /dev/null +++ b/server/lib/video-blacklist.ts @@ -0,0 +1,31 @@ +import * as sequelize from 'sequelize' +import { CONFIG } from '../initializers/constants' +import { VideoBlacklistType, UserRight } from '../../shared/models' +import { VideoBlacklistModel } from '../models/video/video-blacklist' +import { UserModel } from '../models/account/user' +import { VideoModel } from '../models/video/video' +import { logger } from '../helpers/logger' + +async function autoBlacklistVideoIfNeeded (video: VideoModel, user: UserModel, transaction: sequelize.Transaction) { + if (!CONFIG.AUTO_BLACKLIST.VIDEOS.OF_USERS.ENABLED) return false + + if (user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST)) return false + + const sequelizeOptions = { transaction } + const videoBlacklistToCreate = { + videoId: video.id, + unfederated: true, + reason: 'Auto-blacklisted. Moderator review required.', + type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED + } + await VideoBlacklistModel.create(videoBlacklistToCreate, sequelizeOptions) + logger.info('Video %s auto-blacklisted.', video.uuid) + + return true +} + +// --------------------------------------------------------------------------- + +export { + autoBlacklistVideoIfNeeded +} -- cgit v1.2.3