Validation Handler Update (#6968)

* Initial Commit

* Update FunctionsRouter.js

* Update FunctionsRouter.js

* Change params to fields

* Changes requested

* Fix failing tests

* More tests

* More tests

* Remove existing functionality

* Remove legacy tests

* fix array typo

* Update triggers.js

* Docs

* Allow requireUserKeys to be object

* validateMasterKey

* Improve documentation

Co-authored-by: Diamond Lewis <findlewis@gmail.com>
This commit is contained in:
dblythy
2020-10-26 04:36:54 +11:00
committed by GitHub
parent e89cf25bc2
commit c2f2281e6d
8 changed files with 1752 additions and 176 deletions

View File

@@ -109,37 +109,17 @@ export class FunctionsRouter extends PromiseRouter {
});
},
error: function (message) {
// parse error, process away
if (message instanceof Parse.Error) {
return reject(message);
}
const code = Parse.Error.SCRIPT_FAILED;
// If it's an error, mark it as a script failed
if (typeof message === 'string') {
return reject(new Parse.Error(code, message));
}
const error = new Parse.Error(
code,
(message && message.message) || message
);
if (message instanceof Error) {
error.stack = message.stack;
}
const error = triggers.resolveError(message);
reject(error);
},
message: message,
};
}
static handleCloudFunction(req) {
const functionName = req.params.functionName;
const applicationId = req.config.applicationId;
const theFunction = triggers.getFunction(functionName, applicationId);
const theValidator = triggers.getValidator(
req.params.functionName,
applicationId
);
if (!theFunction) {
throw new Parse.Error(
Parse.Error.SCRIPT_FAILED,
@@ -160,16 +140,6 @@ export class FunctionsRouter extends PromiseRouter {
context: req.info.context,
};
if (theValidator && typeof theValidator === 'function') {
var result = theValidator(request);
if (!result) {
throw new Parse.Error(
Parse.Error.VALIDATION_ERROR,
'Validation failed.'
);
}
}
return new Promise(function (resolve, reject) {
const userString =
req.auth && req.auth.user ? req.auth.user.id : undefined;
@@ -212,6 +182,9 @@ export class FunctionsRouter extends PromiseRouter {
}
);
return Promise.resolve()
.then(() => {
return triggers.maybeRunValidator(request, functionName);
})
.then(() => {
return theFunction(request, { message });
})