aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/video-blacklist.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-22 11:14:58 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-07-24 10:58:16 +0200
commit6691c52280363fc42f7865230ebb3741f02fff23 (patch)
tree071f9a4d7814c46dcfec100268cb0a0cc76e5204 /server/lib/video-blacklist.ts
parent89cd12756035a146bbcc4db78cd3cd64f2f3d88d (diff)
downloadPeerTube-6691c52280363fc42f7865230ebb3741f02fff23.tar.gz
PeerTube-6691c52280363fc42f7865230ebb3741f02fff23.tar.zst
PeerTube-6691c52280363fc42f7865230ebb3741f02fff23.zip
Add filter hooks tests
Diffstat (limited to 'server/lib/video-blacklist.ts')
-rw-r--r--server/lib/video-blacklist.ts33
1 files changed, 28 insertions, 5 deletions
diff --git a/server/lib/video-blacklist.ts b/server/lib/video-blacklist.ts
index 9bc996f5a..9749ce2f6 100644
--- a/server/lib/video-blacklist.ts
+++ b/server/lib/video-blacklist.ts
@@ -8,10 +8,17 @@ import { logger } from '../helpers/logger'
8import { UserAdminFlag } from '../../shared/models/users/user-flag.model' 8import { UserAdminFlag } from '../../shared/models/users/user-flag.model'
9import { Hooks } from './plugins/hooks' 9import { Hooks } from './plugins/hooks'
10 10
11async function autoBlacklistVideoIfNeeded (video: VideoModel, user?: UserModel, transaction?: Transaction) { 11async function autoBlacklistVideoIfNeeded (parameters: {
12 video: VideoModel,
13 user?: UserModel,
14 isRemote: boolean,
15 isNew: boolean,
16 transaction?: Transaction
17}) {
18 const { video, user, isRemote, isNew, transaction } = parameters
12 const doAutoBlacklist = await Hooks.wrapPromiseFun( 19 const doAutoBlacklist = await Hooks.wrapPromiseFun(
13 autoBlacklistNeeded, 20 autoBlacklistNeeded,
14 { video, user }, 21 { video, user, isRemote, isNew },
15 'filter:video.auto-blacklist.result' 22 'filter:video.auto-blacklist.result'
16 ) 23 )
17 24
@@ -23,17 +30,33 @@ async function autoBlacklistVideoIfNeeded (video: VideoModel, user?: UserModel,
23 reason: 'Auto-blacklisted. Moderator review required.', 30 reason: 'Auto-blacklisted. Moderator review required.',
24 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED 31 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
25 } 32 }
26 await VideoBlacklistModel.create(videoBlacklistToCreate, { transaction }) 33 const [ videoBlacklist ] = await VideoBlacklistModel.findOrCreate({
34 where: {
35 videoId: video.id
36 },
37 defaults: videoBlacklistToCreate,
38 transaction
39 })
40
41 video.VideoBlacklist = videoBlacklist
27 42
28 logger.info('Video %s auto-blacklisted.', video.uuid) 43 logger.info('Video %s auto-blacklisted.', video.uuid)
29 44
30 return true 45 return true
31} 46}
32 47
33async function autoBlacklistNeeded (parameters: { video: VideoModel, user?: UserModel }) { 48async function autoBlacklistNeeded (parameters: {
34 const { user } = parameters 49 video: VideoModel,
50 isRemote: boolean,
51 isNew: boolean,
52 user?: UserModel
53}) {
54 const { user, video, isRemote, isNew } = parameters
35 55
56 // Already blacklisted
57 if (video.VideoBlacklist) return false
36 if (!CONFIG.AUTO_BLACKLIST.VIDEOS.OF_USERS.ENABLED || !user) return false 58 if (!CONFIG.AUTO_BLACKLIST.VIDEOS.OF_USERS.ENABLED || !user) return false
59 if (isRemote || isNew) return false
37 60
38 if (user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) || user.hasAdminFlag(UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST)) return false 61 if (user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) || user.hasAdminFlag(UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST)) return false
39 62