New: allow options to be async on Cloud Validator (#7155)
* new: allow options to be async on Cloud Validator * Update CHANGELOG.md * Ensure pushStatus is properly running (#7213) * Ensure pushStatus is properly running * remove duplicate test * new: allow options to be async on Cloud Validator * Update CHANGELOG.md * Update CloudCode.Validator.spec.js Co-authored-by: Diamond Lewis <findlewis@gmail.com>
This commit is contained in:
@@ -662,11 +662,11 @@ async function builtInTriggerValidator(options, request, auth) {
|
||||
}
|
||||
};
|
||||
|
||||
const validateOptions = (opt, key, val) => {
|
||||
const validateOptions = async (opt, key, val) => {
|
||||
let opts = opt.options;
|
||||
if (typeof opts === 'function') {
|
||||
try {
|
||||
const result = opts(val);
|
||||
const result = await opts(val);
|
||||
if (!result && result != null) {
|
||||
throw opt.error || `Validation failed. Invalid value for ${key}.`;
|
||||
}
|
||||
@@ -699,6 +699,7 @@ async function builtInTriggerValidator(options, request, auth) {
|
||||
requiredParam(key);
|
||||
}
|
||||
} else {
|
||||
const optionPromises = [];
|
||||
for (const key in options.fields) {
|
||||
const opt = options.fields[key];
|
||||
let val = params[key];
|
||||
@@ -731,10 +732,11 @@ async function builtInTriggerValidator(options, request, auth) {
|
||||
}
|
||||
}
|
||||
if (opt.options) {
|
||||
validateOptions(opt, key, val);
|
||||
optionPromises.push(validateOptions(opt, key, val));
|
||||
}
|
||||
}
|
||||
}
|
||||
await Promise.all(optionPromises);
|
||||
}
|
||||
let userRoles = options.requireAnyUserRoles;
|
||||
let requireAllRoles = options.requireAllUserRoles;
|
||||
@@ -780,12 +782,14 @@ async function builtInTriggerValidator(options, request, auth) {
|
||||
}
|
||||
}
|
||||
} else if (typeof userKeys === 'object') {
|
||||
const optionPromises = [];
|
||||
for (const key in options.requireUserKeys) {
|
||||
const opt = options.requireUserKeys[key];
|
||||
if (opt.options) {
|
||||
validateOptions(opt, key, reqUser.get(key));
|
||||
optionPromises.push(validateOptions(opt, key, reqUser.get(key)));
|
||||
}
|
||||
}
|
||||
await Promise.all(optionPromises);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user