简体   繁体   English

如何随着时间的推移正确使用Parse.Roles关系为多个Parse.Objects和Users?

[英]How do I correctly use Parse.Roles relationships for multiple Parse.Objects and Users over time?

Most of the following is done with the parse-dashboard so it's a bit wordy, but I understand the code just not the relationships. 以下大部分都是使用parse-dashboard完成的,所以它有点罗嗦,但我理解代码不是关系。

I'm setting Parse.Roles and it seems like each individual Parse.Object needs to have the Role set to have access to a given Parse.Object. 我正在设置Parse.Roles,似乎每个Parse.Object都需要将Role设置为可以访问给定的Parse.Object。 For example, an Object ACL needs to contain both "Admin" and "Moderator" (with respective permissions) for Admins or Moderators to have access. 例如,对象ACL需要包含“管理员”和“主持人”(具有相应的权限),供管理员或主持人才能访问。

Since parent and child roles are possible, it would make sense to set a Parse.Object's ACL with the "Organization" Role, which is then further modified by the child Role. 由于父角色和子角色是可能的,因此使用“组织”角色设置Parse.Object的ACL是有意义的,然后由子角色进一步修改。 So, a "Viewer" within an "Organization" cannot Write, but an "Admin" within the "Organization" can Read/Write. 因此,“组织”中的“查看者”不能写,但“组织”中的“管理员”可以读/写。 I've tried multiple ways of doing this - associating one user to a "Viewer" and one to an "Admin" within an "Organization" but this does not seem to work. 我尝试了多种方法 - 将一个用户与“查看者”关联,将一个用户关联到“组织”中的“管理员”,但这似乎不起作用。

My Current Solution: To manually/programmatically set each Parse.Object ACL with multiple pre-set Roles. 我当前的解决方案:手动/编程设置具有多个预设角色的每个Parse.Object ACL。 Eg Parse Class "Person" with ACL Roles "Viewer" & "Admin". 例如,使用ACL角色“查看器”和“管理员”解析类“人员”。

Question: If I want to create a different Role in the future for this same Organization, will I need to loop through each Parse.Object and manually set the new Role for each of the past Objects? 问题:如果我想在将来为同一个组织创建一个不同的角色,我是否需要遍历每个Parse.Object并为每个过去的对象手动设置新角色?

It would make sense that these relationships should be managed by the parent Organization so that this doesn't need to be done manually, but this doesn't seem to work. 有意义的是,这些关系应该由父组织管理,这样就不需要手动完成,但这似乎不起作用。

Any answers, thoughts, or links are appreciated. 任何答案,想法或链接都表示赞赏。

As you have mentioned, roles can have roles and inherit the privileges of their parent role. 如您所述,角色可以拥有角色并继承其父角色的特权。

Hence, if the new role applies to all objects of a class or a group of them, you don't need to loop through all parse objects. 因此,如果新角色适用于类的所有对象或其中的一组,则不需要遍历所有解析对象。

I will give you an example: 我会举个例子:

Let's say you have a class named Posts. 假设您有一个名为Posts的类。

  • you have a role name viewer , and you have a role named editor . 你有一个角色名称viewer ,并且你有一个名为editor的角色。

  • when you create a new post object, you add both roles viewer and editor as the ACL of the post object. 在创建新的post对象时,可以将角色viewereditor都添加为post对象的ACL。 For instance, the viewer role can only have read access and editor may have both read and write access. 例如,查看者角色只能具有读访问权限,编辑器可以具有读写访问权限。

For each organization: 对于每个组织:

  • First you create a role name uniqueOrganizationName 首先,创建角色名称uniqueOrganizationName
  • Then you add all users belong to that organization to uniqueOrganizationName users (relation). 然后,将属于该组织的所有用户添加到uniqueOrganizationName用户(关系)。

Now, in the future, if you want to add all users of that organization to for instance editorRole , instead of adding editorRole to all user objects, you can add uniqueOrganizationName to editorRole roles. 现在,将来,如果要将该组织的所有用户添加到例如editorRole ,而不是将editorRole添加到所有用户对象,则可以将uniqueOrganizationName添加到editorRole角色。 Now, all users of that organization can modify all posts. 现在,该组织的所有用户都可以修改所有帖子。 If you want some users of the organization to be able to edit the post, the you add those users to editorRole users. 如果您希望组织的某些用户能够编辑帖子,则将这些用户添加到editorRole用户。

Note: this approach is global . 注意:这种方法是全球性的 so the organization editors may edit all posts objects. 所以组织编辑可以编辑所有帖子对象。 If you want to limit the editors of an organization to only be able to edit posts belong that that organization: 如果要限制组织的编辑者只能编辑属于该组织的帖子:

  • create two unique role for each organization viewUniqueOrganizationRole & editUniqueOrganizationRole . 为每个组织创建两个唯一角色viewUniqueOrganizationRoleeditUniqueOrganizationRole

Now, when you create a new post, depending on what organization that post belongs to, you add viewUniqueOrganizationRole && editUniqueOrganizationRole to the ACL of the post object. 现在,当您创建新帖子时,根据帖子所属的组织,将viewUniqueOrganizationRole && editUniqueOrganizationRole添加到帖子对象的ACL中。

  • After this, you can add users' to viewUniqueOrganizationRole to be able to view posts belongs to that organization or you can add users to editUniqueOrganizationRole so they can edit your post. 在此之后,您可以将用户添加到viewUniqueOrganizationRole ,以便能够查看属于该组织的帖子,或者您可以将用户添加到editUniqueOrganizationRole以便他们可以编辑您的帖子。

I hope I could answer your question. 我希望我能回答你的问题。 This is a complex design. 这是一个复杂的设计。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM