aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r--server/middlewares/validators/blocklist.ts45
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'
9import { ServerBlocklistModel } from '../../models/server/server-blocklist' 9import { ServerBlocklistModel } from '../../models/server/server-blocklist'
10import { ServerModel } from '../../models/server/server' 10import { ServerModel } from '../../models/server/server'
11import { CONFIG } from '../../initializers' 11import { CONFIG } from '../../initializers'
12import { getServerActor } from '../../helpers/utils'
12 13
13const blockAccountByAccountValidator = [ 14const 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
54const blockServerByAccountValidator = [ 55const 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
72const 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
116const 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
100export { 133export {
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// ---------------------------------------------------------------------------