Skip to content

Instantly share code, notes, and snippets.

@tridungle
Forked from ziad-saab/get-roles.js
Created July 18, 2019 02:55
Show Gist options
  • Save tridungle/018faafa9b69957e3cfe7e627655e29d to your computer and use it in GitHub Desktop.
Save tridungle/018faafa9b69957e3cfe7e627655e29d 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');
});
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment