2019-04-02 04:26:47 -05:00
|
|
|
import * as sequelize from 'sequelize'
|
2019-04-11 04:33:44 -05:00
|
|
|
import { CONFIG } from '../initializers/config'
|
2019-04-15 03:49:46 -05:00
|
|
|
import { UserRight, VideoBlacklistType } from '../../shared/models'
|
2019-04-02 04:26:47 -05:00
|
|
|
import { VideoBlacklistModel } from '../models/video/video-blacklist'
|
|
|
|
import { UserModel } from '../models/account/user'
|
|
|
|
import { VideoModel } from '../models/video/video'
|
|
|
|
import { logger } from '../helpers/logger'
|
2019-04-15 03:49:46 -05:00
|
|
|
import { UserAdminFlag } from '../../shared/models/users/user-flag.model'
|
2019-04-02 04:26:47 -05:00
|
|
|
|
|
|
|
async function autoBlacklistVideoIfNeeded (video: VideoModel, user: UserModel, transaction: sequelize.Transaction) {
|
|
|
|
if (!CONFIG.AUTO_BLACKLIST.VIDEOS.OF_USERS.ENABLED) return false
|
|
|
|
|
2019-04-15 03:49:46 -05:00
|
|
|
if (user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) || user.hasAdminFlag(UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST)) return false
|
2019-04-02 04:26:47 -05:00
|
|
|
|
|
|
|
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)
|
2019-04-15 03:49:46 -05:00
|
|
|
|
2019-04-02 04:26:47 -05:00
|
|
|
logger.info('Video %s auto-blacklisted.', video.uuid)
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
autoBlacklistVideoIfNeeded
|
|
|
|
}
|