update TODO and start on some kind of body checker/schema handler which should work for the new global settings, to avoid it being a million lines long. eventually all the other controllers will get refactored and the system expanded upon to handle all routes. will make code cleaner, more concise and easier to expand with new or updated checks.

merge-requests/218/head
Thomas Lynch 3 years ago
parent a966ea9c00
commit f6a1c02128
  1. 12
      TODO.txt
  2. 55
      helpers/schema.js

@ -1,9 +1,17 @@
big changes in globalmanagesettings model
update global manage settings pug template
update globalmanagesettings model
update globalmanagesettings controller
update global manage settings pug template (idea: show names of perm levels)
update paramconverter for mass of new number/trim/array fields, etc for the form
^^^ ok this is so fucking annoying, the controllers need refactoring. so im gonna make some generic handler for that, maybe it could even be made to a module
---
uhhh, need to make the defaults built into the db, i guess part of gulp reset,
AND a migration for existing sites to import from configs/main (since the options structure not changing yet)
go through every import/require of configs/main and replace with getconfig and destructures of the return
call gulp tasks for images, captcha, css, html, (e.g. change captcha type, clear html) etc from within chan or build-worker probs build worker
need to add update method to commit config and make it a getter, as hash could change

@ -0,0 +1,55 @@
'use strict';
/* planned schema would be array of smth like this:
{
func: <check function, either predefined, some other check like isAlphaNumeric, or a custom callback>,
expected: <true or false>
error: <error text>,
permLevel: [optional perm level],
}
*/
module.exports = {
//TODO: move some other checks here? like isAlphaNumeric would be a good example
//check length of string or array
lengthBody: (data, minlength=0, maxlength=Infinity) => {
return data && (data.length < minlength || data.length > maxlength);
},
//checks if data is a number and within a range
numberBody: (data, min=0, max=Infinity) => {
return typeof data === 'number' && (data < min || data > max);
},
//check 2 number values, that one is less than the other, usually for setings with a min and max that they dont violate eachother
minmaxBody: (minData, maxData) => {
return typeof minData === 'number' && typeof maxData === 'number' && minData < maxData;
},
//check if value is included in a set or array, usually for blacklist or whitelist
inArrayBody: (data, list) => {
return data && list[list.constructor.name === 'Array' ? 'includes' : 'has'](data);
},
//the opposite kinda, check if the data includes any of the values in the array
arrayInBody: (filters, data) => {
return filters.some(filter => data.includes(filter));
},
//check the actual schema
checkSchema: async (schema, permLevel) => {
const errors = [];
//filter check if my perm level is lower than the requirement. e.g. bypass filters checks
const filteredSchema = schema.filter(c => c.permLevel > permLevel);
for (check of filteredSchema) {
const result = await check.func();
if (result !== check.expected) {
errors.push(check.error);
}
}
return errors;
},
};
Loading…
Cancel
Save