【问题标题】:Property-Level Access Control in ParseParse 中的属性级访问控制
【发布时间】:2014-11-07 02:08:27
【问题描述】:

Data & Security guide at Parse.com 描述了如何控制类和对象级别的访问。我正在寻找一种方法来限制所有用户对某个类的某些 properties 的写入权限。如何实现?

我的想法是使用一对一的关系并限制对相关类的访问。但是,这感觉不像是规范的方式......

【问题讨论】:

    标签: security parse-platform acl


    【解决方案1】:

    最简单的方法是使用云代码。你可以这样做:

    Parse.Cloud.beforeSave("YourObject", function(request, response)
    {
        // Find a way to decide if writing is allowed.
        var writingForbidden = (request.master === false);
    
        if (writingForbidden)
        {
            var readOnlyProperties = ["property1", "property2", "property3", "..."];
    
            var dirtyProperties = request.object.dirtyKeys();
            for (i = 0 ; i < dirtyProperties.length ; i++) {
                var dirtyProperty = dirtyProperties[i];
                if (readOnlyProperties.indexOf(dirtyProperty) > -1) {
                    return response.error("Trying to change a readonly property : " + dirtyProperty);
                }
            }
        }
    
        return response.success();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 2014-09-07
      • 1970-01-01
      • 2016-03-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多