简体   繁体   English

Parse.com设置用户角色

[英]Parse.com set User Role

I am using parse.com as a backend for my android application. 我使用parse.com作为我的Android应用程序的后端。 I need help to solve the following scenario. 我需要帮助来解决以下场景。 I wanna do some access control. 我想做一些访问控制。 The app will consists of the following users say Super Admin, Admin, Moderator and Editors. 该应用程序将包含以下用户:超级管理员,管理员,主持人和编辑者。 The Super Admin can create a number of Admins(each admin has its own group), where as the Admin can create Moderator and Editors. 超级管理员可以创建许多管理员(每个管理员都有自己的组),管理员可以在其中创建主持人和编辑者。 Now i wanna set ACL to these users in which one group cannot be able to read or write data of another group. 现在我想为这些用户设置ACL,其中一个组无法读取或写入另一个组的数据。 Is there any simple example for this scenario available. 这个场景是否有任何简单的例子可用。

                                      SUPER ADMIN
                        |------------------|--------------------|
                        |                  |                    |
                 ADMIN(Group A)     ADMIN(Group B)       ADMIN(Group C)
                     |                     |                    |
                     |-Moderator           |-Moderator          |-Moderator
                     |                     |                    |
                     |-Editor1             |-Editor1            |-Editor1
                     |                     |                    |
                     |-Editor2             |-Editor2            |-Editor2
                     |                                          |
                     |-Editor3                                  |-Editor3

Yes, you can do this. 是的,你可以这样做。 Roles use ACLs just as other objects to. 角色使用ACL就像其他对象一样。 I think the example in the docs answer most of what you are after: 我认为文档中的示例回答了您的大部分内容:

https://parse.com/docs/android_guide#roles https://parse.com/docs/android_guide#roles

Try that and check back here with a specific question if you have problems solving your scenario. 如果您在解决方案时遇到问题,请尝试并在此处查看具体问题。

Snipped from the docs: 从文档中删除:

// By specifying no write privileges for the ACL, we can ensure the role cannot be altered.
ParseACL roleACL = new ParseACL();
roleACL.setPublicReadAccess(true);
ParseRole role = new ParseRole("Administrator", roleACL);
role.saveInBackground();

ParseRole role = new ParseRole(roleName, roleACL);
for (ParseUser user : usersToAddToRole) {
  role.getUsers().add(user)
}
for (ParseRole childRole : rolesToAddToRole) {
  role.getRoles().add(childRole);
}
role.saveInBackground();

This is what I use for read and write, but with the ParseACL object you can set everything you need. 这是我用于读写的内容,但是使用ParseACL对象,您可以设置所需的一切。

 ParseACL defaultACL = new ParseACL();
 defaultACL.setPublicReadAccess(true);
 ParseACL.setDefaultACL(defaultACL, true);

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

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