video-blacklist.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. import * as sequelize from 'sequelize'
  2. import { CONFIG } from '../initializers/config'
  3. import { UserRight, VideoBlacklistType } from '../../shared/models'
  4. import { VideoBlacklistModel } from '../models/video/video-blacklist'
  5. import { UserModel } from '../models/account/user'
  6. import { VideoModel } from '../models/video/video'
  7. import { logger } from '../helpers/logger'
  8. import { UserAdminFlag } from '../../shared/models/users/user-flag.model'
  9. async function autoBlacklistVideoIfNeeded (video: VideoModel, user: UserModel, transaction: sequelize.Transaction) {
  10. if (!CONFIG.AUTO_BLACKLIST.VIDEOS.OF_USERS.ENABLED) return false
  11. if (user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) || user.hasAdminFlag(UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST)) return false
  12. const sequelizeOptions = { transaction }
  13. const videoBlacklistToCreate = {
  14. videoId: video.id,
  15. unfederated: true,
  16. reason: 'Auto-blacklisted. Moderator review required.',
  17. type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
  18. }
  19. await VideoBlacklistModel.create(videoBlacklistToCreate, sequelizeOptions)
  20. logger.info('Video %s auto-blacklisted.', video.uuid)
  21. return true
  22. }
  23. // ---------------------------------------------------------------------------
  24. export {
  25. autoBlacklistVideoIfNeeded
  26. }