aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-13 16:57:13 +0200
committerChocobozzz <me@florianbigard.com>2018-08-14 09:27:18 +0200
commit26b7305a232e547709f433a6edf700bf495935d8 (patch)
treeb5676090c61df72f864735bcc881d5ee256cffbd /server/controllers/api
parentefc9e8450a8bbeeef9cd18e3ad6037abc0f815c3 (diff)
downloadPeerTube-26b7305a232e547709f433a6edf700bf495935d8.tar.gz
PeerTube-26b7305a232e547709f433a6edf700bf495935d8.tar.zst
PeerTube-26b7305a232e547709f433a6edf700bf495935d8.zip
Add blacklist reason field
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/users.ts6
-rw-r--r--server/controllers/api/videos/blacklist.ts56
2 files changed, 45 insertions, 17 deletions
diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts
index 0e2be7123..543b20baa 100644
--- a/server/controllers/api/users.ts
+++ b/server/controllers/api/users.ts
@@ -201,14 +201,14 @@ async function getUserVideos (req: express.Request, res: express.Response, next:
201 user.Account.id, 201 user.Account.id,
202 req.query.start as number, 202 req.query.start as number,
203 req.query.count as number, 203 req.query.count as number,
204 req.query.sort as VideoSortField, 204 req.query.sort as VideoSortField
205 false // Display my NSFW videos
206 ) 205 )
207 206
208 const additionalAttributes = { 207 const additionalAttributes = {
209 waitTranscoding: true, 208 waitTranscoding: true,
210 state: true, 209 state: true,
211 scheduledUpdate: true 210 scheduledUpdate: true,
211 blacklistInfo: true
212 } 212 }
213 return res.json(getFormattedObjects(resultList.data, resultList.total, { additionalAttributes })) 213 return res.json(getFormattedObjects(resultList.data, resultList.total, { additionalAttributes }))
214} 214}
diff --git a/server/controllers/api/videos/blacklist.ts b/server/controllers/api/videos/blacklist.ts
index 8112b59b8..358f339ed 100644
--- a/server/controllers/api/videos/blacklist.ts
+++ b/server/controllers/api/videos/blacklist.ts
@@ -1,12 +1,21 @@
1import * as express from 'express' 1import * as express from 'express'
2import { BlacklistedVideo, UserRight } from '../../../../shared' 2import { BlacklistedVideo, UserRight, VideoBlacklistCreate } from '../../../../shared'
3import { logger } from '../../../helpers/logger' 3import { logger } from '../../../helpers/logger'
4import { getFormattedObjects } from '../../../helpers/utils' 4import { getFormattedObjects } from '../../../helpers/utils'
5import { 5import {
6 asyncMiddleware, authenticate, blacklistSortValidator, ensureUserHasRight, paginationValidator, setBlacklistSort, setDefaultPagination, 6 asyncMiddleware,
7 videosBlacklistAddValidator, videosBlacklistRemoveValidator 7 authenticate,
8 blacklistSortValidator,
9 ensureUserHasRight,
10 paginationValidator,
11 setBlacklistSort,
12 setDefaultPagination,
13 videosBlacklistAddValidator,
14 videosBlacklistRemoveValidator,
15 videosBlacklistUpdateValidator
8} from '../../../middlewares' 16} from '../../../middlewares'
9import { VideoBlacklistModel } from '../../../models/video/video-blacklist' 17import { VideoBlacklistModel } from '../../../models/video/video-blacklist'
18import { sequelizeTypescript } from '../../../initializers'
10 19
11const blacklistRouter = express.Router() 20const blacklistRouter = express.Router()
12 21
@@ -27,6 +36,13 @@ blacklistRouter.get('/blacklist',
27 asyncMiddleware(listBlacklist) 36 asyncMiddleware(listBlacklist)
28) 37)
29 38
39blacklistRouter.put('/:videoId/blacklist',
40 authenticate,
41 ensureUserHasRight(UserRight.MANAGE_VIDEO_BLACKLIST),
42 asyncMiddleware(videosBlacklistUpdateValidator),
43 asyncMiddleware(updateVideoBlacklistController)
44)
45
30blacklistRouter.delete('/:videoId/blacklist', 46blacklistRouter.delete('/:videoId/blacklist',
31 authenticate, 47 authenticate,
32 ensureUserHasRight(UserRight.MANAGE_VIDEO_BLACKLIST), 48 ensureUserHasRight(UserRight.MANAGE_VIDEO_BLACKLIST),
@@ -42,17 +58,32 @@ export {
42 58
43// --------------------------------------------------------------------------- 59// ---------------------------------------------------------------------------
44 60
45async function addVideoToBlacklist (req: express.Request, res: express.Response, next: express.NextFunction) { 61async function addVideoToBlacklist (req: express.Request, res: express.Response) {
46 const videoInstance = res.locals.video 62 const videoInstance = res.locals.video
63 const body: VideoBlacklistCreate = req.body
47 64
48 const toCreate = { 65 const toCreate = {
49 videoId: videoInstance.id 66 videoId: videoInstance.id,
67 reason: body.reason
50 } 68 }
51 69
52 await VideoBlacklistModel.create(toCreate) 70 await VideoBlacklistModel.create(toCreate)
53 return res.type('json').status(204).end() 71 return res.type('json').status(204).end()
54} 72}
55 73
74async function updateVideoBlacklistController (req: express.Request, res: express.Response) {
75 const videoBlacklist = res.locals.videoBlacklist as VideoBlacklistModel
76 logger.info(videoBlacklist)
77
78 if (req.body.reason !== undefined) videoBlacklist.reason = req.body.reason
79
80 await sequelizeTypescript.transaction(t => {
81 return videoBlacklist.save({ transaction: t })
82 })
83
84 return res.type('json').status(204).end()
85}
86
56async function listBlacklist (req: express.Request, res: express.Response, next: express.NextFunction) { 87async function listBlacklist (req: express.Request, res: express.Response, next: express.NextFunction) {
57 const resultList = await VideoBlacklistModel.listForApi(req.query.start, req.query.count, req.query.sort) 88 const resultList = await VideoBlacklistModel.listForApi(req.query.start, req.query.count, req.query.sort)
58 89
@@ -60,16 +91,13 @@ async function listBlacklist (req: express.Request, res: express.Response, next:
60} 91}
61 92
62async function removeVideoFromBlacklistController (req: express.Request, res: express.Response, next: express.NextFunction) { 93async function removeVideoFromBlacklistController (req: express.Request, res: express.Response, next: express.NextFunction) {
63 const blacklistedVideo = res.locals.blacklistedVideo as VideoBlacklistModel 94 const videoBlacklist = res.locals.videoBlacklist as VideoBlacklistModel
64 95
65 try { 96 await sequelizeTypescript.transaction(t => {
66 await blacklistedVideo.destroy() 97 return videoBlacklist.destroy({ transaction: t })
98 })
67 99
68 logger.info('Video %s removed from blacklist.', res.locals.video.uuid) 100 logger.info('Video %s removed from blacklist.', res.locals.video.uuid)
69 101
70 return res.sendStatus(204) 102 return res.type('json').status(204).end()
71 } catch (err) {
72 logger.error('Some error while removing video %s from blacklist.', res.locals.video.uuid, { err })
73 throw err
74 }
75} 103}