gpt4 book ai didi

javascript - 解析 : How to restrict access to only certain properties of an object in Parse?

转载 作者:行者123 更新时间:2023-11-29 21:40:58 25 4
gpt4 key购买 nike

我是 Parse 的初学者。我以前一直在使用 django 和 django rest 框架。我最近开始从事解析工作,我很喜欢它,但是我心中有一些困惑,我无法通过阅读文档来解决。

我想限制对对象的某些属性(/字段)的访问,而不是对整个对象的访问,如 Parse Documentation 中所述

比如我有

user1 = {
name: "a",
...
}

user2 = {
name: "b",
...
}

还有一个对象

pet = {
type: "Cat",
name: "abc",
hungry: true,
}

现在我想要一个设置,其中“user1”对象只能访问对象“pet”的“type”和“name”属性,而“user2”可以访问“pet”的所有三个属性。

如何在Parse中添加这些属性级别的权限?我希望我表达清楚了。

最佳答案

ACL 是最具体的控制手段,它只到对象级别。在一个对象中,您可以通过应用程序逻辑强制执行,或将对象分解成多个部分...

Pet = { name: "Toonces",
type: "Cat",
restrictedPet:<pointer to RestrictedPet>,
ACL: everyone }

RestrictedPet = { hungry: true,
canDriveACar: true,
ACL: user2 }

当查询 Pet 时(比如,在 JS 中),你可以无条件地这样说:

var petQuery = new Parse.Query("Pet");
petQuery.include("restrictedPet");
petQuery.first(then(function(pet) {
if (pet.restrictedPet) {
// when user2 is running, she will see restricted attributes here
console.log("Can my pet drive? " + pet.restrictedPet.canDriveACar);
}
// the remainder of the attributes are visible here, to all
});

关于javascript - 解析 : How to restrict access to only certain properties of an object in Parse?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32949804/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com