根据Parse Relation字段设置对象的ACL
Setting ACL of objects based on Parse Relation field
我有两个 Parse 类 Group 和 Post。
Group 有一个解析关系字段 people (用户,在这个组中)和 Post有一个指针字段组(哪个组,这个post属于)。
当有人创建群组时,he/she 将他的好友添加到此群组,这些好友正在 "people" 字段中保存。
人际关系中的每个人都可以post加入群组。
我有一些关于在 post 和组对象上设置 ACL 的问题。
- 保存组对象时。如何根据beforeSave中的"people"(解析关系字段)设置其acl(我不想在客户端设置ACL)?
- 当组中的某个post post 对象的acl 也应该基于"Group" [=50= 的解析关系字段"people" ]. **请注意,我希望 post 对象的 acl 应该是动态的,当有人稍后加入组时,he/she 应该能够看到来自 [=49] 的以前的 post =] 加入日期
Parse.Cloud.beforeSave(POST, function(request, response){
Parse.Cloud.useMasterKey();
var post = request.object;
var owner = post.get("owner");
var community = post.get("group")
var draft = post.get("draft");
if (!owner || !draft || !community) return response.error(PARAMETERS_NOT_FOUND);
if (draft.length <1) return response.error(FIELD_SIZE_LIMIT_NOT_ENOUGH)
var community = validateCommunity(community.id);
if (!community) return response.error(FAKE_COMMUNITY);
var people_to_share = community.relation("people");
var acl = new Parse.ACL();
acl.setWriteAccess(owner, true);
acl.setReadAccess(owner, true);
// Now here i want to set the acl of post for all people_to_share .... And that is working good ... but the problem is when i add new person in community (people field) .... I have to do set acl for him in every post of community.
post.setACL(acl);
response.success();
});
是的。我已经使用普通角色解决了这个问题。
我为每个组创建了一个角色,并将其作为指针保存在组 Class 中。每当有新人加入组时。我授予他读取该组角色的权限。并从该组中删除人员。我删除了他的读取权限。
同样,当创建新的 post 时,我只是将 post 的 acl 设置为该组的角色。这是很好的动态方式。
我有两个 Parse 类 Group 和 Post。 Group 有一个解析关系字段 people (用户,在这个组中)和 Post有一个指针字段组(哪个组,这个post属于)。
当有人创建群组时,he/she 将他的好友添加到此群组,这些好友正在 "people" 字段中保存。
人际关系中的每个人都可以post加入群组。
我有一些关于在 post 和组对象上设置 ACL 的问题。
- 保存组对象时。如何根据beforeSave中的"people"(解析关系字段)设置其acl(我不想在客户端设置ACL)?
- 当组中的某个post post 对象的acl 也应该基于"Group" [=50= 的解析关系字段"people" ]. **请注意,我希望 post 对象的 acl 应该是动态的,当有人稍后加入组时,he/she 应该能够看到来自 [=49] 的以前的 post =] 加入日期
Parse.Cloud.beforeSave(POST, function(request, response){
Parse.Cloud.useMasterKey();
var post = request.object;
var owner = post.get("owner");
var community = post.get("group")
var draft = post.get("draft");
if (!owner || !draft || !community) return response.error(PARAMETERS_NOT_FOUND);
if (draft.length <1) return response.error(FIELD_SIZE_LIMIT_NOT_ENOUGH)
var community = validateCommunity(community.id);
if (!community) return response.error(FAKE_COMMUNITY);
var people_to_share = community.relation("people");
var acl = new Parse.ACL();
acl.setWriteAccess(owner, true);
acl.setReadAccess(owner, true);
// Now here i want to set the acl of post for all people_to_share .... And that is working good ... but the problem is when i add new person in community (people field) .... I have to do set acl for him in every post of community.
post.setACL(acl);
response.success();
});
是的。我已经使用普通角色解决了这个问题。 我为每个组创建了一个角色,并将其作为指针保存在组 Class 中。每当有新人加入组时。我授予他读取该组角色的权限。并从该组中删除人员。我删除了他的读取权限。
同样,当创建新的 post 时,我只是将 post 的 acl 设置为该组的角色。这是很好的动态方式。