|
|
|
@ -3,6 +3,7 @@ |
|
|
|
|
const removeBans = require(__dirname+'/../../models/forms/removebans.js') |
|
|
|
|
, dynamicResponse = require(__dirname+'/../../helpers/dynamic.js') |
|
|
|
|
, denyAppeals = require(__dirname+'/../../models/forms/denybanappeals.js') |
|
|
|
|
, editBans = require(__dirname+'/../../models/forms/editbans.js') |
|
|
|
|
, paramConverter = require(__dirname+'/../../helpers/paramconverter.js') |
|
|
|
|
, { checkSchema, lengthBody, numberBody, minmaxBody, numberBodyVariable, |
|
|
|
|
inArrayBody, arrayInBody, existsBody } = require(__dirname+'/../../helpers/schema.js'); |
|
|
|
@ -10,6 +11,7 @@ const removeBans = require(__dirname+'/../../models/forms/removebans.js') |
|
|
|
|
module.exports = { |
|
|
|
|
|
|
|
|
|
paramConverter: paramConverter({ |
|
|
|
|
timeFields: ['ban_duration'], |
|
|
|
|
trimFields: ['option'], |
|
|
|
|
allowedArrays: ['checkedbans'], |
|
|
|
|
objectIdArrays: ['checkedbans'] |
|
|
|
@ -19,7 +21,8 @@ module.exports = { |
|
|
|
|
|
|
|
|
|
const errors = await checkSchema([ |
|
|
|
|
{ result: lengthBody(req.body.checkedbans, 1), expected: false, error: 'Must select at least one ban' }, |
|
|
|
|
{ result: inArrayBody(req.body.option, ['unban', 'deny_appeal']), expected: true, error: 'Invalid ban action' }, |
|
|
|
|
{ result: inArrayBody(req.body.option, ['unban', 'edit', 'deny_appeal']), expected: true, error: 'Invalid ban action' }, |
|
|
|
|
{ result: req.body.option !== 'edit' || numberBody(req.body.ban_duration, 0), expected: true, error: 'Invalid filter auto ban duration' }, |
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
const redirect = req.params.board ? `/${req.params.board}/manage/bans.html` : '/globalmanage/bans.html'; |
|
|
|
@ -35,12 +38,21 @@ module.exports = { |
|
|
|
|
let amount = 0; |
|
|
|
|
let message; |
|
|
|
|
try { |
|
|
|
|
if (req.body.option === 'unban') { |
|
|
|
|
amount = await removeBans(req, res, next); |
|
|
|
|
message = `Removed ${amount} bans`; |
|
|
|
|
} else { |
|
|
|
|
amount = await denyAppeals(req, res, next); |
|
|
|
|
message = `Denied ${amount} appeals`; |
|
|
|
|
switch(req.body.option) { |
|
|
|
|
case 'unban': |
|
|
|
|
amount = await removeBans(req, res, next); |
|
|
|
|
message = `Removed ${amount} bans`; |
|
|
|
|
break; |
|
|
|
|
case 'deny_appeal': |
|
|
|
|
amount = await denyAppeals(req, res, next); |
|
|
|
|
message = `Denied ${amount} appeals`; |
|
|
|
|
break; |
|
|
|
|
case 'edit': //could do other properties in future
|
|
|
|
|
amount = await editBans(req, res, next); |
|
|
|
|
message = `Edited ${amount} bans`; |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
throw 'Invalid ban action'; //should never happen anyway
|
|
|
|
|
} |
|
|
|
|
} catch (err) { |
|
|
|
|
return next(err); |
|
|
|
|