问题
I try to set the ACLs with the code below, but in my mongolab database I do not see the ACL settings. Am I doing something wrong in the code? I could not find any good tutorial for the cloud code examples.
Parse.Cloud.afterSave('_User', function(req) {
var user = req.user;
var acl = new Parse.ACL();
acl.setReadAccess(req.user, true);
acl.setWriteAccess(req.user, true);
user.setACL(acl);
user.save();
});
Parse.Cloud.afterSave('userSetting', function(req) {
var userSet = req.object;
var acl = new Parse.ACL();
acl.setReadAccess(Parse.User.current().id, true);
acl.setWriteAccess(Parse.User.current().id, true);
userSet.setACL(acl);
userSet.save();
});
回答1:
I figured it out with the code below. The problem was that I was trying to use the "afterSave" method while trying to adding the ACL to the requested object, however, the ACL should be added before saving, or if it should be done after saving, the object should be retrieved again and then the ACL should be added.
Parse.Cloud.beforeSave('userSetting', function(req, res) {
var acl = new Parse.ACL();
acl.setReadAccess(req.user, true);
acl.setWriteAccess(req.user, true);
req.object.setACL(acl);
res.success();
});
来源:https://stackoverflow.com/questions/35662409/parse-server-cloud-code-setting-acl