解析服务器云代码设置ACL [英] Parse Server Cloud Code Setting ACL

查看:140
本文介绍了解析服务器云代码设置ACL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用以下代码设置ACL,但在我的mongolab数据库中,我看不到ACL设置。我在代码中做错了吗?我找不到关于云代码示例的任何好教程。

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();

  });


推荐答案

我用下面的代码弄清楚了。问题是我试图在尝试将ACL添加到请求的对象时尝试使用 afterSave方法,但是,应该在保存之前添加ACL,或者如果应该在保存之后执行ACL,则应该再次检索该对象

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();

});

这篇关于解析服务器云代码设置ACL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆