Parse Server Cloud Code Setting ACL

独自空忆成欢 提交于 2020-01-23 03:43:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!