diff options
author | Chocobozzz <me@florianbigard.com> | 2019-07-18 14:28:37 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-07-24 10:58:16 +0200 |
commit | b4055e1c23eeefb0c8a85a77f312b2827d98f483 (patch) | |
tree | 51b6b04c1ad10897047817d2eaaa037d1331fa6a /server/lib/video-blacklist.ts | |
parent | 66e001c848c009412c65cbce41be344d8985fd83 (diff) | |
download | PeerTube-b4055e1c23eeefb0c8a85a77f312b2827d98f483.tar.gz PeerTube-b4055e1c23eeefb0c8a85a77f312b2827d98f483.tar.zst PeerTube-b4055e1c23eeefb0c8a85a77f312b2827d98f483.zip |
Add server hooks
Diffstat (limited to 'server/lib/video-blacklist.ts')
-rw-r--r-- | server/lib/video-blacklist.ts | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/server/lib/video-blacklist.ts b/server/lib/video-blacklist.ts index 985b89e31..32b1a28fa 100644 --- a/server/lib/video-blacklist.ts +++ b/server/lib/video-blacklist.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import * as sequelize from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { CONFIG } from '../initializers/config' | 2 | import { CONFIG } from '../initializers/config' |
3 | import { UserRight, VideoBlacklistType } from '../../shared/models' | 3 | import { UserRight, VideoBlacklistType } from '../../shared/models' |
4 | import { VideoBlacklistModel } from '../models/video/video-blacklist' | 4 | import { VideoBlacklistModel } from '../models/video/video-blacklist' |
@@ -6,26 +6,39 @@ import { UserModel } from '../models/account/user' | |||
6 | import { VideoModel } from '../models/video/video' | 6 | import { VideoModel } from '../models/video/video' |
7 | import { logger } from '../helpers/logger' | 7 | import { logger } from '../helpers/logger' |
8 | import { UserAdminFlag } from '../../shared/models/users/user-flag.model' | 8 | import { UserAdminFlag } from '../../shared/models/users/user-flag.model' |
9 | import { Hooks } from './plugins/hooks' | ||
9 | 10 | ||
10 | async function autoBlacklistVideoIfNeeded (video: VideoModel, user: UserModel, transaction: sequelize.Transaction) { | 11 | async function autoBlacklistVideoIfNeeded (video: VideoModel, user?: UserModel, transaction?: Transaction) { |
11 | if (!CONFIG.AUTO_BLACKLIST.VIDEOS.OF_USERS.ENABLED) return false | 12 | const doAutoBlacklist = await Hooks.wrapPromise( |
13 | autoBlacklistNeeded({ video, user }), | ||
14 | 'filter:video.auto-blacklist.result' | ||
15 | ) | ||
12 | 16 | ||
13 | if (user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) || user.hasAdminFlag(UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST)) return false | 17 | if (!doAutoBlacklist) return false |
14 | 18 | ||
15 | const sequelizeOptions = { transaction } | ||
16 | const videoBlacklistToCreate = { | 19 | const videoBlacklistToCreate = { |
17 | videoId: video.id, | 20 | videoId: video.id, |
18 | unfederated: true, | 21 | unfederated: true, |
19 | reason: 'Auto-blacklisted. Moderator review required.', | 22 | reason: 'Auto-blacklisted. Moderator review required.', |
20 | type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED | 23 | type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED |
21 | } | 24 | } |
22 | await VideoBlacklistModel.create(videoBlacklistToCreate, sequelizeOptions) | 25 | await VideoBlacklistModel.create(videoBlacklistToCreate, { transaction }) |
23 | 26 | ||
24 | logger.info('Video %s auto-blacklisted.', video.uuid) | 27 | logger.info('Video %s auto-blacklisted.', video.uuid) |
25 | 28 | ||
26 | return true | 29 | return true |
27 | } | 30 | } |
28 | 31 | ||
32 | async function autoBlacklistNeeded (parameters: { video: VideoModel, user?: UserModel }) { | ||
33 | const { user } = parameters | ||
34 | |||
35 | if (!CONFIG.AUTO_BLACKLIST.VIDEOS.OF_USERS.ENABLED || !user) return false | ||
36 | |||
37 | if (user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) || user.hasAdminFlag(UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST)) return false | ||
38 | |||
39 | return true | ||
40 | } | ||
41 | |||
29 | // --------------------------------------------------------------------------- | 42 | // --------------------------------------------------------------------------- |
30 | 43 | ||
31 | export { | 44 | export { |