Note that there are some explanatory texts on larger screens.

plurals
  1. POParse.com, Adding users to created roles
    primarykey
    data
    text
    <p>I have a cloud code which creates two account roles when a user signs up. Below is the method</p> <pre><code>Parse.Cloud.afterSave("account", function(request) { var accountName = request.object.get("name"); //create admin role var adminRoleACL = new Parse.ACL(); adminRoleACL.setPublicWriteAccess(true); var adminRole = new Parse.Role(accountName + "_Administrator", adminRoleACL); adminRole.save() ; //create user role var userRoleACL = new Parse.ACL(); userRoleACL.setPublicWriteAccess(true); var userRole = new Parse.Role(accountName + "_User", userRoleACL); userRole.save(); }); </code></pre> <p>Now what i wanted to achieve was to add the user which just signed up to these two roles. But unfortunately i saw that in cloud code i can't get the current user. So what i did was to add the users in the role after the roles are created from the client side. Below is the code for the same. The code executes fine and i did not see any error, however i did not see the users being added to the roles in the data browser. Any idea why is this happening? Am i missing something. I would be really thankful for all your help.</p> <pre><code>user.signUp(null, { success : function(user) { var currentUser = Parse.User.current(); var accountName = account.get("name"); var query = new Parse.Query(Parse.Role); query.contains("name", accountName); query.find({ success : function(roles) { if (!roles) { alert("No roles for " + accountName + " were found"); } else { for (var i = 0; i &lt; roles.length; i++) { //add the user for admin role //TODO: this needs to be done only once for the account owner if (roles[i].get("name").search(USER_TYPE.ADMIN) &gt;= 0) { roles[i].getUsers().add(currentUser); } //add the user for user role if (roles[i].get("name").search(USER_TYPE.USER) &gt;= 0) { roles[i].getUsers().add(currentUser); } var saved = roles[i].save(); } alert("User was added into roles"); } }, error : function(error) { alert("Could not add users to the account " + accountName + " error: " + error.message); } }); alert("User created successfully"); }, error : function(user, error) { alert("Error: " + error.code + " " + error.message); } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload