diff options
author | Chocobozzz <me@florianbigard.com> | 2019-03-19 09:26:50 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-03-19 09:26:50 +0100 |
commit | 0f6acda11681de90d38dd18669863c6e270851ee (patch) | |
tree | b3b28e00d539645f5a810202dc8afada289e7b2e /server/middlewares/validators/blocklist.ts | |
parent | 9a18a6252071cf21b18f82a24bb63078abb75bc1 (diff) | |
download | PeerTube-0f6acda11681de90d38dd18669863c6e270851ee.tar.gz PeerTube-0f6acda11681de90d38dd18669863c6e270851ee.tar.zst PeerTube-0f6acda11681de90d38dd18669863c6e270851ee.zip |
Does exist
Diffstat (limited to 'server/middlewares/validators/blocklist.ts')
-rw-r--r-- | server/middlewares/validators/blocklist.ts | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/server/middlewares/validators/blocklist.ts b/server/middlewares/validators/blocklist.ts index 109276c63..d7ec649b6 100644 --- a/server/middlewares/validators/blocklist.ts +++ b/server/middlewares/validators/blocklist.ts | |||
@@ -2,7 +2,7 @@ import { body, param } from 'express-validator/check' | |||
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { logger } from '../../helpers/logger' | 3 | import { logger } from '../../helpers/logger' |
4 | import { areValidationErrors } from './utils' | 4 | import { areValidationErrors } from './utils' |
5 | import { isAccountNameWithHostExist } from '../../helpers/custom-validators/accounts' | 5 | import { doesAccountNameWithHostExist } from '../../helpers/custom-validators/accounts' |
6 | import { UserModel } from '../../models/account/user' | 6 | import { UserModel } from '../../models/account/user' |
7 | import { AccountBlocklistModel } from '../../models/account/account-blocklist' | 7 | import { AccountBlocklistModel } from '../../models/account/account-blocklist' |
8 | import { isHostValid } from '../../helpers/custom-validators/servers' | 8 | import { isHostValid } from '../../helpers/custom-validators/servers' |
@@ -18,7 +18,7 @@ const blockAccountValidator = [ | |||
18 | logger.debug('Checking blockAccountByAccountValidator parameters', { parameters: req.body }) | 18 | logger.debug('Checking blockAccountByAccountValidator parameters', { parameters: req.body }) |
19 | 19 | ||
20 | if (areValidationErrors(req, res)) return | 20 | if (areValidationErrors(req, res)) return |
21 | if (!await isAccountNameWithHostExist(req.body.accountName, res)) return | 21 | if (!await doesAccountNameWithHostExist(req.body.accountName, res)) return |
22 | 22 | ||
23 | const user = res.locals.oauth.token.User as UserModel | 23 | const user = res.locals.oauth.token.User as UserModel |
24 | const accountToBlock = res.locals.account | 24 | const accountToBlock = res.locals.account |
@@ -42,11 +42,11 @@ const unblockAccountByAccountValidator = [ | |||
42 | logger.debug('Checking unblockAccountByAccountValidator parameters', { parameters: req.params }) | 42 | logger.debug('Checking unblockAccountByAccountValidator parameters', { parameters: req.params }) |
43 | 43 | ||
44 | if (areValidationErrors(req, res)) return | 44 | if (areValidationErrors(req, res)) return |
45 | if (!await isAccountNameWithHostExist(req.params.accountName, res)) return | 45 | if (!await doesAccountNameWithHostExist(req.params.accountName, res)) return |
46 | 46 | ||
47 | const user = res.locals.oauth.token.User as UserModel | 47 | const user = res.locals.oauth.token.User as UserModel |
48 | const targetAccount = res.locals.account | 48 | const targetAccount = res.locals.account |
49 | if (!await isUnblockAccountExists(user.Account.id, targetAccount.id, res)) return | 49 | if (!await doesUnblockAccountExist(user.Account.id, targetAccount.id, res)) return |
50 | 50 | ||
51 | return next() | 51 | return next() |
52 | } | 52 | } |
@@ -59,11 +59,11 @@ const unblockAccountByServerValidator = [ | |||
59 | logger.debug('Checking unblockAccountByServerValidator parameters', { parameters: req.params }) | 59 | logger.debug('Checking unblockAccountByServerValidator parameters', { parameters: req.params }) |
60 | 60 | ||
61 | if (areValidationErrors(req, res)) return | 61 | if (areValidationErrors(req, res)) return |
62 | if (!await isAccountNameWithHostExist(req.params.accountName, res)) return | 62 | if (!await doesAccountNameWithHostExist(req.params.accountName, res)) return |
63 | 63 | ||
64 | const serverActor = await getServerActor() | 64 | const serverActor = await getServerActor() |
65 | const targetAccount = res.locals.account | 65 | const targetAccount = res.locals.account |
66 | if (!await isUnblockAccountExists(serverActor.Account.id, targetAccount.id, res)) return | 66 | if (!await doesUnblockAccountExist(serverActor.Account.id, targetAccount.id, res)) return |
67 | 67 | ||
68 | return next() | 68 | return next() |
69 | } | 69 | } |
@@ -107,7 +107,7 @@ const unblockServerByAccountValidator = [ | |||
107 | if (areValidationErrors(req, res)) return | 107 | if (areValidationErrors(req, res)) return |
108 | 108 | ||
109 | const user = res.locals.oauth.token.User as UserModel | 109 | const user = res.locals.oauth.token.User as UserModel |
110 | if (!await isUnblockServerExists(user.Account.id, req.params.host, res)) return | 110 | if (!await doesUnblockServerExist(user.Account.id, req.params.host, res)) return |
111 | 111 | ||
112 | return next() | 112 | return next() |
113 | } | 113 | } |
@@ -122,7 +122,7 @@ const unblockServerByServerValidator = [ | |||
122 | if (areValidationErrors(req, res)) return | 122 | if (areValidationErrors(req, res)) return |
123 | 123 | ||
124 | const serverActor = await getServerActor() | 124 | const serverActor = await getServerActor() |
125 | if (!await isUnblockServerExists(serverActor.Account.id, req.params.host, res)) return | 125 | if (!await doesUnblockServerExist(serverActor.Account.id, req.params.host, res)) return |
126 | 126 | ||
127 | return next() | 127 | return next() |
128 | } | 128 | } |
@@ -141,7 +141,7 @@ export { | |||
141 | 141 | ||
142 | // --------------------------------------------------------------------------- | 142 | // --------------------------------------------------------------------------- |
143 | 143 | ||
144 | async function isUnblockAccountExists (accountId: number, targetAccountId: number, res: express.Response) { | 144 | async function doesUnblockAccountExist (accountId: number, targetAccountId: number, res: express.Response) { |
145 | const accountBlock = await AccountBlocklistModel.loadByAccountAndTarget(accountId, targetAccountId) | 145 | const accountBlock = await AccountBlocklistModel.loadByAccountAndTarget(accountId, targetAccountId) |
146 | if (!accountBlock) { | 146 | if (!accountBlock) { |
147 | res.status(404) | 147 | res.status(404) |
@@ -156,7 +156,7 @@ async function isUnblockAccountExists (accountId: number, targetAccountId: numbe | |||
156 | return true | 156 | return true |
157 | } | 157 | } |
158 | 158 | ||
159 | async function isUnblockServerExists (accountId: number, host: string, res: express.Response) { | 159 | async function doesUnblockServerExist (accountId: number, host: string, res: express.Response) { |
160 | const serverBlock = await ServerBlocklistModel.loadByAccountAndHost(accountId, host) | 160 | const serverBlock = await ServerBlocklistModel.loadByAccountAndHost(accountId, host) |
161 | if (!serverBlock) { | 161 | if (!serverBlock) { |
162 | res.status(404) | 162 | res.status(404) |