aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares
diff options
context:
space:
mode:
authorGreen-Star <Green-Star@users.noreply.github.com>2017-09-22 09:13:43 +0200
committerBigard Florian <florian.bigard@gmail.com>2017-09-22 09:13:43 +0200
commit792dbaf07f83fbe3f1d209cd9edf190442c7d2f3 (patch)
treef7edf9caf17baaaf95c219c3ac73d598e3fd3df8 /server/middlewares
parentc9d6d155c397d0da0cb2d50064264fc1716f0501 (diff)
downloadPeerTube-792dbaf07f83fbe3f1d209cd9edf190442c7d2f3.tar.gz
PeerTube-792dbaf07f83fbe3f1d209cd9edf190442c7d2f3.tar.zst
PeerTube-792dbaf07f83fbe3f1d209cd9edf190442c7d2f3.zip
Handle blacklist (#84)
* Client: Add list blacklist feature * Server: Add list blacklist feature * Client: Add videoId column * Server: Add some video infos in the REST api * Client: Add video information in the blacklist list * Fix sortable columns :) * Client: Add removeFromBlacklist feature * Server: Add removeFromBlacklist feature * Move to TypeScript * Move to TypeScript and Promises * Server: Fix blacklist list sort * Server: Fetch videos informations * Use common shared interface for client and server * Add check-params remove blacklisted video tests * Add check-params list blacklisted videos tests * Add list blacklist tests * Add remove from blacklist tests * Add video blacklist management tests * Fix rebase onto develop issues * Server: Add sort on blacklist id column * Server: Add blacklists library * Add blacklist id sort test * Add check-params tests for blacklist list pagination, count and sort * Fix coding style * Increase Remote API tests timeout * Increase Request scheduler API tests timeout * Fix typo * Increase video transcoding API tests timeout * Move tests to Typescript * Use lodash orderBy method * Fix typos * Client: Remove optional tests in blacklist model attributes * Move blacklist routes from 'blacklists' to 'blacklist' * CLient: Remove blacklist-list.component.scss * Rename 'blacklists' files to 'blacklist' * Use only BlacklistedVideo interface * Server: Use getFormattedObjects method in listBlacklist method * Client: Use new coding style * Server: Use new sort validator methods * Server: Use new checkParams methods * Client: Fix sortable columns
Diffstat (limited to 'server/middlewares')
-rw-r--r--server/middlewares/sort.ts27
-rw-r--r--server/middlewares/validators/blacklist.ts35
-rw-r--r--server/middlewares/validators/index.ts1
-rw-r--r--server/middlewares/validators/sort.ts5
4 files changed, 66 insertions, 2 deletions
diff --git a/server/middlewares/sort.ts b/server/middlewares/sort.ts
index 632b2fae4..687ce097b 100644
--- a/server/middlewares/sort.ts
+++ b/server/middlewares/sort.ts
@@ -1,6 +1,9 @@
1import 'express-validator' 1import 'express-validator'
2import * as express from 'express' 2import * as express from 'express'
3 3
4import { SortType } from '../helpers'
5import { database } from '../initializers'
6
4function setUsersSort (req: express.Request, res: express.Response, next: express.NextFunction) { 7function setUsersSort (req: express.Request, res: express.Response, next: express.NextFunction) {
5 if (!req.query.sort) req.query.sort = '-createdAt' 8 if (!req.query.sort) req.query.sort = '-createdAt'
6 9
@@ -19,10 +22,32 @@ function setVideosSort (req: express.Request, res: express.Response, next: expre
19 return next() 22 return next()
20} 23}
21 24
25function setBlacklistSort (req: express.Request, res: express.Response, next: express.NextFunction) {
26 let newSort: SortType = { sortModel: undefined, sortValue: undefined }
27
28 if (!req.query.sort) req.query.sort = '-createdAt'
29
30 // Set model we want to sort onto
31 if (req.query.sort === '-createdAt' || req.query.sort === 'createdAt' ||
32 req.query.sort === '-id' || req.query.sort === 'id') {
33 // If we want to sort onto the BlacklistedVideos relation, we won't specify it in the query parameter ...
34 newSort.sortModel = undefined
35 } else {
36 newSort.sortModel = database.Video
37 }
38
39 newSort.sortValue = req.query.sort
40
41 req.query.sort = newSort
42
43 return next()
44}
45
22// --------------------------------------------------------------------------- 46// ---------------------------------------------------------------------------
23 47
24export { 48export {
25 setUsersSort, 49 setUsersSort,
26 setVideoAbusesSort, 50 setVideoAbusesSort,
27 setVideosSort 51 setVideosSort,
52 setBlacklistSort
28} 53}
diff --git a/server/middlewares/validators/blacklist.ts b/server/middlewares/validators/blacklist.ts
new file mode 100644
index 000000000..fe8fa40a4
--- /dev/null
+++ b/server/middlewares/validators/blacklist.ts
@@ -0,0 +1,35 @@
1import { param } from 'express-validator/check'
2import * as express from 'express'
3
4import { database as db } from '../../initializers/database'
5import { checkErrors } from './utils'
6import { logger } from '../../helpers'
7
8const blacklistRemoveValidator = [
9 param('id').isNumeric().not().isEmpty().withMessage('Should have a valid id'),
10
11 (req: express.Request, res: express.Response, next: express.NextFunction) => {
12 logger.debug('Checking blacklistRemove parameters.', { parameters: req.params })
13
14 checkErrors(req, res, () => {
15 db.BlacklistedVideo.loadById(req.params.id)
16 .then(entry => {
17 if (!entry) return res.status(404).send('Blacklisted video not found')
18
19 res.locals.blacklistEntryToRemove = entry
20
21 next()
22 })
23 .catch(err => {
24 logger.error('Error in blacklistRemove request validator', { error: err })
25 return res.sendStatus(500)
26 })
27 })
28 }
29]
30
31// ---------------------------------------------------------------------------
32
33export {
34 blacklistRemoveValidator
35}
diff --git a/server/middlewares/validators/index.ts b/server/middlewares/validators/index.ts
index 42ba465ec..a6198e22c 100644
--- a/server/middlewares/validators/index.ts
+++ b/server/middlewares/validators/index.ts
@@ -4,3 +4,4 @@ export * from './pods'
4export * from './sort' 4export * from './sort'
5export * from './users' 5export * from './users'
6export * from './videos' 6export * from './videos'
7export * from './blacklist'
diff --git a/server/middlewares/validators/sort.ts b/server/middlewares/validators/sort.ts
index 71b18acb0..a6f5ccb6b 100644
--- a/server/middlewares/validators/sort.ts
+++ b/server/middlewares/validators/sort.ts
@@ -9,17 +9,20 @@ import { SORTABLE_COLUMNS } from '../../initializers'
9const SORTABLE_USERS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.USERS) 9const SORTABLE_USERS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.USERS)
10const SORTABLE_VIDEO_ABUSES_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_ABUSES) 10const SORTABLE_VIDEO_ABUSES_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_ABUSES)
11const SORTABLE_VIDEOS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS) 11const SORTABLE_VIDEOS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS)
12const SORTABLE_BLACKLISTS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.BLACKLISTS)
12 13
13const usersSortValidator = checkSort(SORTABLE_USERS_COLUMNS) 14const usersSortValidator = checkSort(SORTABLE_USERS_COLUMNS)
14const videoAbusesSortValidator = checkSort(SORTABLE_VIDEO_ABUSES_COLUMNS) 15const videoAbusesSortValidator = checkSort(SORTABLE_VIDEO_ABUSES_COLUMNS)
15const videosSortValidator = checkSort(SORTABLE_VIDEOS_COLUMNS) 16const videosSortValidator = checkSort(SORTABLE_VIDEOS_COLUMNS)
17const blacklistSortValidator = checkSort(SORTABLE_BLACKLISTS_COLUMNS)
16 18
17// --------------------------------------------------------------------------- 19// ---------------------------------------------------------------------------
18 20
19export { 21export {
20 usersSortValidator, 22 usersSortValidator,
21 videoAbusesSortValidator, 23 videoAbusesSortValidator,
22 videosSortValidator 24 videosSortValidator,
25 blacklistSortValidator
23} 26}
24 27
25// --------------------------------------------------------------------------- 28// ---------------------------------------------------------------------------