Set up users roles and permissions in parse.com

2019-06-03 07:51发布

问题:

looking to set up user permissions in parse.com. i have a know list of users in my user "table". i want to lock down the app for supervisors(role) only view most tables and modify a few. have managers(role) to view almost all tables and modify most. Administrators to view and modify all.

after searching for days i only see code to modify roles and permissions. what is the purpose using code if the roles and permissions are only setup once? or would someone please explain how to set up roles and permissions in the data window online. thanks for your help

I get this error on the save line: https://api.parse.com/1/classes/_Role/24EHbUyDzv 404 (Not Found)

my sample code for utility:

// First create a pointer to the object of yourClassName
var user = Parse.Object.extend("User");
var pointer = new user();
pointer.id = "aL5dfXQsRO";

// Now you can add the pointer to the relation
query = new Parse.Query(Parse.Role); 
query.equalTo("name", "manager"); 
query.first ( { 
      success: function(object) { 
      object.relation("users").add(pointer); 
      object.save();
      //response.success("The user has been authorized.");
},

回答1:

It looks like there's two options to get the job done.

1) Write some single-purpose code to set the roles. Roles are a type of relation, so you will have to create them as such. Here is a quote from a Parse engineer on the subject:

To add objects to a relation column, you need to use the client SDKs or REST API.

2) The workaround described here. The gist of it is, you can export your table's data, modify data for the roles, and then import the updates back into Parse. This will allow you to manually set the roles without having to write single-purpose code.

Edit: Here's your code sample and correction

// First create a pointer to the object of yourClassName
var UserClass = Parse.Object.extend("User");
var userPointer = new UserClass();
userPointer.id = "aL5dfXQsRO";

// Now you can add the pointer to the relation
query = new Parse.Query(Parse.Role); 
query.equalTo("name", "manager"); 
query.first ( { 
    success: function(object) { 
        object.relation("users").add(userPointer); 
        object.save();