Parse-Server cloud code can't create Role

2019-09-10 05:41发布

问题:

I have a class called Project for which I create a Parse.Role for read/write permissions.

Here's how I create my Role:

var roleName = "hasSound_" + ident;
var projectRole = new Parse.Role(roleName, new Parse.ACL());
projectRole.getUsers().add(creator); 

return projectRole.save().then(function(role) {

var acl = new Parse.ACL();
acl.setReadAccess(role, true); //give read access to Role
acl.setWriteAccess(role, true); //give write access to Role

project.setACL(acl);            
project.save();

});

And here's the bad request I'm getting when trying to create the Parse.Role:

Mar 04 14:39:32 ancient-lake-41070 heroku/router:  at=info method=POST path="/parse/classes/_Role" host=ancient-lake-41070.herokuapp.com request_id=82af3849-842a-406f-8a4b-5f573e08a1e1 fwd="54.145.36.110" dyno=web.1 connect=0ms service=6ms status=400 bytes=578

回答1:

So apparently I needed to add useMasterKey to all my save functions. In a .save() function it is the second parameter, like so: obj.save(null, {useMasterKey: true})

Once I did that, the Role was created, all my relations are working again, etc.

See here for more info: https://github.com/ParsePlatform/parse-server/issues/37