Skip to content

Instantly share code, notes, and snippets.

@ziad-saab
Last active October 4, 2021 15:52
Show Gist options
  • Save ziad-saab/41eca04a72d8038493ba to your computer and use it in GitHub Desktop.
Save ziad-saab/41eca04a72d8038493ba to your computer and use it in GitHub Desktop.
Get a list of a user's roles from Parse, including child roles, up to a certain depth
// Maximum depth is 3, after that we get a "" error from Parse
function getUserRoles(user) {
var queries = [
new Parse.Query('_Role').equalTo('users', user)
];
for (var i = 0; i < 2; i++) {
queries.push(new Parse.Query('_Role').matchesQuery('roles', queries[i]));
}
return user.rolesPromise = Parse.Query.or.apply(Parse.Query, queries).find().then(
function(roles) {
return roles.map(function(role) {
return role.get('name');
});
}
);
}
@dsyrstad
Copy link

dsyrstad commented Oct 4, 2021

@coderofsalvation No question from me. I just posted my TS version of the code, in case anyone needed it.

@coderofsalvation
Copy link

hehe indeed my bad 😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment