diff options
author | Chocobozzz <me@florianbigard.com> | 2020-05-07 14:58:24 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-05-07 15:07:01 +0200 |
commit | 80fdaf064562aff968f4c9cea1cf220bc12a70da (patch) | |
tree | a0ec49f433b828660f741b394dfd87056cd2c6ef /server/controllers/api | |
parent | 3cc665f48fd233d09f778d7e887488dde6f03ef6 (diff) | |
download | PeerTube-80fdaf064562aff968f4c9cea1cf220bc12a70da.tar.gz PeerTube-80fdaf064562aff968f4c9cea1cf220bc12a70da.tar.zst PeerTube-80fdaf064562aff968f4c9cea1cf220bc12a70da.zip |
Add moderation helpers to plugins
Diffstat (limited to 'server/controllers/api')
-rw-r--r-- | server/controllers/api/users/my-history.ts | 2 | ||||
-rw-r--r-- | server/controllers/api/videos/abuse.ts | 2 | ||||
-rw-r--r-- | server/controllers/api/videos/blacklist.ts | 60 | ||||
-rw-r--r-- | server/controllers/api/videos/comment.ts | 2 | ||||
-rw-r--r-- | server/controllers/api/videos/ownership.ts | 2 |
5 files changed, 14 insertions, 54 deletions
diff --git a/server/controllers/api/users/my-history.ts b/server/controllers/api/users/my-history.ts index 4da1f3496..77a15e5fc 100644 --- a/server/controllers/api/users/my-history.ts +++ b/server/controllers/api/users/my-history.ts | |||
@@ -9,7 +9,7 @@ import { | |||
9 | } from '../../../middlewares' | 9 | } from '../../../middlewares' |
10 | import { getFormattedObjects } from '../../../helpers/utils' | 10 | import { getFormattedObjects } from '../../../helpers/utils' |
11 | import { UserVideoHistoryModel } from '../../../models/account/user-video-history' | 11 | import { UserVideoHistoryModel } from '../../../models/account/user-video-history' |
12 | import { sequelizeTypescript } from '../../../initializers' | 12 | import { sequelizeTypescript } from '../../../initializers/database' |
13 | 13 | ||
14 | const myVideosHistoryRouter = express.Router() | 14 | const myVideosHistoryRouter = express.Router() |
15 | 15 | ||
diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts index 3fe7f7e51..bce50aefb 100644 --- a/server/controllers/api/videos/abuse.ts +++ b/server/controllers/api/videos/abuse.ts | |||
@@ -2,7 +2,7 @@ import * as express from 'express' | |||
2 | import { UserRight, VideoAbuseCreate, VideoAbuseState } from '../../../../shared' | 2 | import { UserRight, VideoAbuseCreate, VideoAbuseState } from '../../../../shared' |
3 | import { logger } from '../../../helpers/logger' | 3 | import { logger } from '../../../helpers/logger' |
4 | import { getFormattedObjects } from '../../../helpers/utils' | 4 | import { getFormattedObjects } from '../../../helpers/utils' |
5 | import { sequelizeTypescript } from '../../../initializers' | 5 | import { sequelizeTypescript } from '../../../initializers/database' |
6 | import { | 6 | import { |
7 | asyncMiddleware, | 7 | asyncMiddleware, |
8 | asyncRetryTransactionMiddleware, | 8 | asyncRetryTransactionMiddleware, |
diff --git a/server/controllers/api/videos/blacklist.ts b/server/controllers/api/videos/blacklist.ts index abd09387c..3b25ceea2 100644 --- a/server/controllers/api/videos/blacklist.ts +++ b/server/controllers/api/videos/blacklist.ts | |||
@@ -1,7 +1,9 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { UserRight, VideoBlacklistCreate, VideoBlacklistType } from '../../../../shared' | 2 | import { blacklistVideo, unblacklistVideo } from '@server/lib/video-blacklist' |
3 | import { UserRight, VideoBlacklistCreate } from '../../../../shared' | ||
3 | import { logger } from '../../../helpers/logger' | 4 | import { logger } from '../../../helpers/logger' |
4 | import { getFormattedObjects } from '../../../helpers/utils' | 5 | import { getFormattedObjects } from '../../../helpers/utils' |
6 | import { sequelizeTypescript } from '../../../initializers/database' | ||
5 | import { | 7 | import { |
6 | asyncMiddleware, | 8 | asyncMiddleware, |
7 | authenticate, | 9 | authenticate, |
@@ -16,11 +18,6 @@ import { | |||
16 | videosBlacklistUpdateValidator | 18 | videosBlacklistUpdateValidator |
17 | } from '../../../middlewares' | 19 | } from '../../../middlewares' |
18 | import { VideoBlacklistModel } from '../../../models/video/video-blacklist' | 20 | import { VideoBlacklistModel } from '../../../models/video/video-blacklist' |
19 | import { sequelizeTypescript } from '../../../initializers' | ||
20 | import { Notifier } from '../../../lib/notifier' | ||
21 | import { sendDeleteVideo } from '../../../lib/activitypub/send' | ||
22 | import { federateVideoIfNeeded } from '../../../lib/activitypub/videos' | ||
23 | import { MVideoBlacklistVideo } from '@server/typings/models' | ||
24 | 21 | ||
25 | const blacklistRouter = express.Router() | 22 | const blacklistRouter = express.Router() |
26 | 23 | ||
@@ -28,7 +25,7 @@ blacklistRouter.post('/:videoId/blacklist', | |||
28 | authenticate, | 25 | authenticate, |
29 | ensureUserHasRight(UserRight.MANAGE_VIDEO_BLACKLIST), | 26 | ensureUserHasRight(UserRight.MANAGE_VIDEO_BLACKLIST), |
30 | asyncMiddleware(videosBlacklistAddValidator), | 27 | asyncMiddleware(videosBlacklistAddValidator), |
31 | asyncMiddleware(addVideoToBlacklist) | 28 | asyncMiddleware(addVideoToBlacklistController) |
32 | ) | 29 | ) |
33 | 30 | ||
34 | blacklistRouter.get('/blacklist', | 31 | blacklistRouter.get('/blacklist', |
@@ -64,29 +61,15 @@ export { | |||
64 | 61 | ||
65 | // --------------------------------------------------------------------------- | 62 | // --------------------------------------------------------------------------- |
66 | 63 | ||
67 | async function addVideoToBlacklist (req: express.Request, res: express.Response) { | 64 | async function addVideoToBlacklistController (req: express.Request, res: express.Response) { |
68 | const videoInstance = res.locals.videoAll | 65 | const videoInstance = res.locals.videoAll |
69 | const body: VideoBlacklistCreate = req.body | 66 | const body: VideoBlacklistCreate = req.body |
70 | 67 | ||
71 | const toCreate = { | 68 | await blacklistVideo(videoInstance, body) |
72 | videoId: videoInstance.id, | ||
73 | unfederated: body.unfederate === true, | ||
74 | reason: body.reason, | ||
75 | type: VideoBlacklistType.MANUAL | ||
76 | } | ||
77 | |||
78 | const blacklist: MVideoBlacklistVideo = await VideoBlacklistModel.create(toCreate) | ||
79 | blacklist.Video = videoInstance | ||
80 | |||
81 | if (body.unfederate === true) { | ||
82 | await sendDeleteVideo(videoInstance, undefined) | ||
83 | } | ||
84 | |||
85 | Notifier.Instance.notifyOnVideoBlacklist(blacklist) | ||
86 | 69 | ||
87 | logger.info('Video %s blacklisted.', videoInstance.uuid) | 70 | logger.info('Video %s blacklisted.', videoInstance.uuid) |
88 | 71 | ||
89 | return res.type('json').status(204).end() | 72 | return res.type('json').sendStatus(204) |
90 | } | 73 | } |
91 | 74 | ||
92 | async function updateVideoBlacklistController (req: express.Request, res: express.Response) { | 75 | async function updateVideoBlacklistController (req: express.Request, res: express.Response) { |
@@ -98,7 +81,7 @@ async function updateVideoBlacklistController (req: express.Request, res: expres | |||
98 | return videoBlacklist.save({ transaction: t }) | 81 | return videoBlacklist.save({ transaction: t }) |
99 | }) | 82 | }) |
100 | 83 | ||
101 | return res.type('json').status(204).end() | 84 | return res.type('json').sendStatus(204) |
102 | } | 85 | } |
103 | 86 | ||
104 | async function listBlacklist (req: express.Request, res: express.Response) { | 87 | async function listBlacklist (req: express.Request, res: express.Response) { |
@@ -117,32 +100,9 @@ async function removeVideoFromBlacklistController (req: express.Request, res: ex | |||
117 | const videoBlacklist = res.locals.videoBlacklist | 100 | const videoBlacklist = res.locals.videoBlacklist |
118 | const video = res.locals.videoAll | 101 | const video = res.locals.videoAll |
119 | 102 | ||
120 | const videoBlacklistType = await sequelizeTypescript.transaction(async t => { | 103 | await unblacklistVideo(videoBlacklist, video) |
121 | const unfederated = videoBlacklist.unfederated | ||
122 | const videoBlacklistType = videoBlacklist.type | ||
123 | |||
124 | await videoBlacklist.destroy({ transaction: t }) | ||
125 | video.VideoBlacklist = undefined | ||
126 | |||
127 | // Re federate the video | ||
128 | if (unfederated === true) { | ||
129 | await federateVideoIfNeeded(video, true, t) | ||
130 | } | ||
131 | |||
132 | return videoBlacklistType | ||
133 | }) | ||
134 | |||
135 | Notifier.Instance.notifyOnVideoUnblacklist(video) | ||
136 | |||
137 | if (videoBlacklistType === VideoBlacklistType.AUTO_BEFORE_PUBLISHED) { | ||
138 | Notifier.Instance.notifyOnVideoPublishedAfterRemovedFromAutoBlacklist(video) | ||
139 | |||
140 | // Delete on object so new video notifications will send | ||
141 | delete video.VideoBlacklist | ||
142 | Notifier.Instance.notifyOnNewVideoIfNeeded(video) | ||
143 | } | ||
144 | 104 | ||
145 | logger.info('Video %s removed from blacklist.', video.uuid) | 105 | logger.info('Video %s removed from blacklist.', video.uuid) |
146 | 106 | ||
147 | return res.type('json').status(204).end() | 107 | return res.type('json').sendStatus(204) |
148 | } | 108 | } |
diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.ts index 5f3fed5c0..5070bb3c0 100644 --- a/server/controllers/api/videos/comment.ts +++ b/server/controllers/api/videos/comment.ts | |||
@@ -4,7 +4,7 @@ import { ResultList } from '../../../../shared/models' | |||
4 | import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model' | 4 | import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model' |
5 | import { logger } from '../../../helpers/logger' | 5 | import { logger } from '../../../helpers/logger' |
6 | import { getFormattedObjects } from '../../../helpers/utils' | 6 | import { getFormattedObjects } from '../../../helpers/utils' |
7 | import { sequelizeTypescript } from '../../../initializers' | 7 | import { sequelizeTypescript } from '../../../initializers/database' |
8 | import { buildFormattedCommentTree, createVideoComment, markCommentAsDeleted } from '../../../lib/video-comment' | 8 | import { buildFormattedCommentTree, createVideoComment, markCommentAsDeleted } from '../../../lib/video-comment' |
9 | import { | 9 | import { |
10 | asyncMiddleware, | 10 | asyncMiddleware, |
diff --git a/server/controllers/api/videos/ownership.ts b/server/controllers/api/videos/ownership.ts index 190036f85..540a49010 100644 --- a/server/controllers/api/videos/ownership.ts +++ b/server/controllers/api/videos/ownership.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { logger } from '../../../helpers/logger' | 2 | import { logger } from '../../../helpers/logger' |
3 | import { sequelizeTypescript } from '../../../initializers' | 3 | import { sequelizeTypescript } from '../../../initializers/database' |
4 | import { | 4 | import { |
5 | asyncMiddleware, | 5 | asyncMiddleware, |
6 | asyncRetryTransactionMiddleware, | 6 | asyncRetryTransactionMiddleware, |