Created channel perms schema and api routes.
This commit is contained in:
parent
9dbbc4e924
commit
8384e732f3
21 changed files with 250 additions and 20 deletions
|
|
@ -20,13 +20,13 @@ const { check, body, checkSchema, checkExact} = require('express-validator');
|
|||
//local imports
|
||||
const {isRank} = require('./permissionsValidator');
|
||||
|
||||
module.exports = {
|
||||
module.exports.accountValidator = {
|
||||
user: (field = 'user') => body(field).escape().trim().isLength({min: 1, max: 22}),
|
||||
|
||||
//Password security requirements may change over time, therefore we should only validate against strongPassword() when creating new accounts
|
||||
//that way we don't break old ones upon change
|
||||
pass: (field = 'pass') => body(field).notEmpty().escape().trim(),
|
||||
securePass: (field) => module.exports.pass(field).isStrongPassword({minLength: 8, minLowercase: 1, minUppercase: 1, minNumbers: 1, minSymbols: 1}),
|
||||
securePass: (field) => module.exports.accountValidator.pass(field).isStrongPassword({minLength: 8, minLowercase: 1, minUppercase: 1, minNumbers: 1, minSymbols: 1}),
|
||||
|
||||
email: (field = 'email') => body(field).optional().isEmail().normalizeEmail(),
|
||||
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
|||
const { check, body, checkSchema, checkExact} = require('express-validator');
|
||||
|
||||
//local imports
|
||||
const accountValidator = require('./accountValidator');
|
||||
const {accountValidator} = require('./accountValidator');
|
||||
|
||||
module.exports = {
|
||||
module.exports.channelValidator = {
|
||||
name: (field = 'name') => check(field).escape().trim().isLength({min: 1, max: 50}),
|
||||
|
||||
description: (field = 'description') => body(field).escape().trim().isLength({min: 1, max: 1000}),
|
||||
|
|
|
|||
|
|
@ -59,4 +59,23 @@ module.exports.permissionsValidator = {
|
|||
},
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
module.exports.channelPermissionValidatorSchema = {
|
||||
'channelPermissionsMap.manageChannel': {
|
||||
optional: true,
|
||||
custom: {
|
||||
options: module.exports.isRank
|
||||
},
|
||||
},
|
||||
'channelPermissionsMap.deleteChannel': {
|
||||
optional: true,
|
||||
custom: {
|
||||
options: module.exports.isRank
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.channelPermissionValidator = {
|
||||
channelPermissionsMap: () => checkExact(checkSchema(module.exports.channelPermissionValidatorSchema))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue