I am almost done migrating an Objective-C iOS app from Parse.com to a self-hosted Parse-Server.
But while doing some checking, I noticed that my cloud function Parse.Cloud.beforeSave
is not executed, or at least not doing all its job. Why is that?
The collection(MyCollection) I want to add a record to is updated as expected, but I have a second collection (for book keeping) that I update (to keep the number of the last inserted item) on the way and that is not done.
For reference, here is the function code:
Parse.Cloud.beforeSave
("MyCollection", function(request, response)
{
var queryConfig;
var queryConfig = new Parse.Query("BooKeep");
queryConfig.find({
success: function(resultConf) {
request.object.set("..", resultConf[0].get("...")+1); // This is done as expected.
resultConf[0].set("...", resultConf[0].get("...")+1); // Not done!
request.object.set("...", resultConf[0].get("...")+1); // This is done as expected.
resultConf[0].set("....", resultConf[0].get("...")+1); // Not done!
resultConf[0].save(null,{}); // Not done!
....
response.success();
},
error: function() {
var reptMsg="The BooKeep-UPDATE procedure failed for some reason.";
console.log(reptMsg);
response.error(reptMsg);
}
});
});
A bit more investigation further down the road, shows the following in the logs. At least now I know that Parse.Cloud.beforeSave is run, which I was not quite sure before.
app[web.1]: info: beforeSave triggered for MyCollection for user Yacb6CzuB9:
app[web.1]: Input: {....}
app[web.1]: Result: {"object":{....}} className=MyCollection, triggerType=beforeSave, user=Yacb6CzuB9
app[web.1]: error: Error generating response. { [Error: unauthorized: master key is required] status: 403, message: 'unauthorized: master key is required' } status=403, message=unauthorized: master key is required
app[web.1]: Error: unauthorized: master key is required
app[web.1]: at promiseEnforceMasterKeyAccess (/app/node_modules/parse-server/lib/middlewares.js:297:17)
app[web.1]: at /app/node_modules/parse-server/lib/PromiseRouter.js:137:22
app[web.1]: at process._tickDomainCallback (internal/process/next_tick.js:129:7)
app[web.1]: error: Error generating response. ParseError {
app[web.1]: code: 119,
app[web.1]: message: 'Permission denied for action update on class BooKeep.' } code=119, message=Permission denied for action update on class BooKeep.
app[web.1]: [object Object]
heroku[router]: at=info method=POST path="/parse/classes/BooKeep/JKKmaSzi8H" host=myapp.herokuapp.com request_id=1348711c-25df-4f6e-005b-70632776742d fwd="54.90.99.197" dyno=web.1 connect=0ms service=34ms status=400 bytes=573
2016-11-25T02:47:58.488404+00:00 heroku[router]: at=info method=POST path="/parse/logout" host=myapp.herokuapp.com request_id=dc3b12d1-5f54-11f0-a8cd-54ceca331a80 fwd="106.130.44.123" dyno=web.1 connect=0ms service=23ms status=200 bytes=483