aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-10-12 17:26:40 +0200
committerChocobozzz <me@florianbigard.com>2018-10-16 16:41:36 +0200
commitaf5767ffae41b2d5604e41ba9a7225c623dd6735 (patch)
treeb96787bd134fe04d3d042795636df4bf17b5991f /server/middlewares
parent7ad9b9846c44d198a736183fb186c2039f5236b5 (diff)
downloadPeerTube-af5767ffae41b2d5604e41ba9a7225c623dd6735.tar.gz
PeerTube-af5767ffae41b2d5604e41ba9a7225c623dd6735.tar.zst
PeerTube-af5767ffae41b2d5604e41ba9a7225c623dd6735.zip
Add user/instance block by users in the client
Diffstat (limited to 'server/middlewares')
-rw-r--r--server/middlewares/validators/blocklist.ts45
1 files changed, 44 insertions, 1 deletions
diff --git a/server/middlewares/validators/blocklist.ts b/server/middlewares/validators/blocklist.ts
index 9dbd5e512..25c054d6b 100644
--- a/server/middlewares/validators/blocklist.ts
+++ b/server/middlewares/validators/blocklist.ts
@@ -1,4 +1,4 @@
1import { param, body } from 'express-validator/check' 1import { body, param } from 'express-validator/check'
2import * as express from 'express' 2import * as express from 'express'
3import { logger } from '../../helpers/logger' 3import { logger } from '../../helpers/logger'
4import { areValidationErrors } from './utils' 4import { areValidationErrors } from './utils'
@@ -7,6 +7,8 @@ import { UserModel } from '../../models/account/user'
7import { AccountBlocklistModel } from '../../models/account/account-blocklist' 7import { AccountBlocklistModel } from '../../models/account/account-blocklist'
8import { isHostValid } from '../../helpers/custom-validators/servers' 8import { isHostValid } from '../../helpers/custom-validators/servers'
9import { ServerBlocklistModel } from '../../models/server/server-blocklist' 9import { ServerBlocklistModel } from '../../models/server/server-blocklist'
10import { ServerModel } from '../../models/server/server'
11import { CONFIG } from '../../initializers'
10 12
11const blockAccountByAccountValidator = [ 13const blockAccountByAccountValidator = [
12 body('accountName').exists().withMessage('Should have an account name with host'), 14 body('accountName').exists().withMessage('Should have an account name with host'),
@@ -17,6 +19,17 @@ const blockAccountByAccountValidator = [
17 if (areValidationErrors(req, res)) return 19 if (areValidationErrors(req, res)) return
18 if (!await isAccountNameWithHostExist(req.body.accountName, res)) return 20 if (!await isAccountNameWithHostExist(req.body.accountName, res)) return
19 21
22 const user = res.locals.oauth.token.User as UserModel
23 const accountToBlock = res.locals.account
24
25 if (user.Account.id === accountToBlock.id) {
26 res.status(409)
27 .send({ error: 'You cannot block yourself.' })
28 .end()
29
30 return
31 }
32
20 return next() 33 return next()
21 } 34 }
22] 35]
@@ -38,6 +51,35 @@ const unblockAccountByAccountValidator = [
38 } 51 }
39] 52]
40 53
54const blockServerByAccountValidator = [
55 body('host').custom(isHostValid).withMessage('Should have a valid host'),
56
57 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
58 logger.debug('Checking serverGetValidator parameters', { parameters: req.body })
59
60 if (areValidationErrors(req, res)) return
61
62 const host: string = req.body.host
63
64 if (host === CONFIG.WEBSERVER.HOST) {
65 return res.status(409)
66 .send({ error: 'You cannot block your own server.' })
67 .end()
68 }
69
70 const server = await ServerModel.loadByHost(host)
71 if (!server) {
72 return res.status(404)
73 .send({ error: 'Server host not found.' })
74 .end()
75 }
76
77 res.locals.server = server
78
79 return next()
80 }
81]
82
41const unblockServerByAccountValidator = [ 83const unblockServerByAccountValidator = [
42 param('host').custom(isHostValid).withMessage('Should have an account name with host'), 84 param('host').custom(isHostValid).withMessage('Should have an account name with host'),
43 85
@@ -56,6 +98,7 @@ const unblockServerByAccountValidator = [
56// --------------------------------------------------------------------------- 98// ---------------------------------------------------------------------------
57 99
58export { 100export {
101 blockServerByAccountValidator,
59 blockAccountByAccountValidator, 102 blockAccountByAccountValidator,
60 unblockAccountByAccountValidator, 103 unblockAccountByAccountValidator,
61 unblockServerByAccountValidator 104 unblockServerByAccountValidator