diff options
author | Chocobozzz <me@florianbigard.com> | 2018-10-15 13:03:04 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-10-16 16:41:36 +0200 |
commit | b44164bb567fe7c9f65f1ac2908d44990a8ccc8e (patch) | |
tree | 37baa0346293e1ed30f8a43270dfd54a4791c6f0 /server/middlewares | |
parent | af5767ffae41b2d5604e41ba9a7225c623dd6735 (diff) | |
download | PeerTube-b44164bb567fe7c9f65f1ac2908d44990a8ccc8e.tar.gz PeerTube-b44164bb567fe7c9f65f1ac2908d44990a8ccc8e.tar.zst PeerTube-b44164bb567fe7c9f65f1ac2908d44990a8ccc8e.zip |
Add ability to mute a user/instance by server in server api
Diffstat (limited to 'server/middlewares')
-rw-r--r-- | server/middlewares/validators/blocklist.ts | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/server/middlewares/validators/blocklist.ts b/server/middlewares/validators/blocklist.ts index 25c054d6b..109276c63 100644 --- a/server/middlewares/validators/blocklist.ts +++ b/server/middlewares/validators/blocklist.ts | |||
@@ -9,8 +9,9 @@ import { isHostValid } from '../../helpers/custom-validators/servers' | |||
9 | import { ServerBlocklistModel } from '../../models/server/server-blocklist' | 9 | import { ServerBlocklistModel } from '../../models/server/server-blocklist' |
10 | import { ServerModel } from '../../models/server/server' | 10 | import { ServerModel } from '../../models/server/server' |
11 | import { CONFIG } from '../../initializers' | 11 | import { CONFIG } from '../../initializers' |
12 | import { getServerActor } from '../../helpers/utils' | ||
12 | 13 | ||
13 | const blockAccountByAccountValidator = [ | 14 | const blockAccountValidator = [ |
14 | body('accountName').exists().withMessage('Should have an account name with host'), | 15 | body('accountName').exists().withMessage('Should have an account name with host'), |
15 | 16 | ||
16 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 17 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
@@ -51,7 +52,24 @@ const unblockAccountByAccountValidator = [ | |||
51 | } | 52 | } |
52 | ] | 53 | ] |
53 | 54 | ||
54 | const blockServerByAccountValidator = [ | 55 | const unblockAccountByServerValidator = [ |
56 | param('accountName').exists().withMessage('Should have an account name with host'), | ||
57 | |||
58 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
59 | logger.debug('Checking unblockAccountByServerValidator parameters', { parameters: req.params }) | ||
60 | |||
61 | if (areValidationErrors(req, res)) return | ||
62 | if (!await isAccountNameWithHostExist(req.params.accountName, res)) return | ||
63 | |||
64 | const serverActor = await getServerActor() | ||
65 | const targetAccount = res.locals.account | ||
66 | if (!await isUnblockAccountExists(serverActor.Account.id, targetAccount.id, res)) return | ||
67 | |||
68 | return next() | ||
69 | } | ||
70 | ] | ||
71 | |||
72 | const blockServerValidator = [ | ||
55 | body('host').custom(isHostValid).withMessage('Should have a valid host'), | 73 | body('host').custom(isHostValid).withMessage('Should have a valid host'), |
56 | 74 | ||
57 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 75 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
@@ -95,13 +113,30 @@ const unblockServerByAccountValidator = [ | |||
95 | } | 113 | } |
96 | ] | 114 | ] |
97 | 115 | ||
116 | const unblockServerByServerValidator = [ | ||
117 | param('host').custom(isHostValid).withMessage('Should have an account name with host'), | ||
118 | |||
119 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
120 | logger.debug('Checking unblockServerByServerValidator parameters', { parameters: req.params }) | ||
121 | |||
122 | if (areValidationErrors(req, res)) return | ||
123 | |||
124 | const serverActor = await getServerActor() | ||
125 | if (!await isUnblockServerExists(serverActor.Account.id, req.params.host, res)) return | ||
126 | |||
127 | return next() | ||
128 | } | ||
129 | ] | ||
130 | |||
98 | // --------------------------------------------------------------------------- | 131 | // --------------------------------------------------------------------------- |
99 | 132 | ||
100 | export { | 133 | export { |
101 | blockServerByAccountValidator, | 134 | blockServerValidator, |
102 | blockAccountByAccountValidator, | 135 | blockAccountValidator, |
103 | unblockAccountByAccountValidator, | 136 | unblockAccountByAccountValidator, |
104 | unblockServerByAccountValidator | 137 | unblockServerByAccountValidator, |
138 | unblockAccountByServerValidator, | ||
139 | unblockServerByServerValidator | ||
105 | } | 140 | } |
106 | 141 | ||
107 | // --------------------------------------------------------------------------- | 142 | // --------------------------------------------------------------------------- |