Recursive lookup for roles

This commit is contained in:
Florent Vilmart
2016-02-26 13:35:56 -05:00
parent 34a621b279
commit 753bead4ac
2 changed files with 60 additions and 0 deletions

View File

@@ -159,6 +159,22 @@ Auth.prototype._getAllRoleNamesForId = function(roleID) {
return Promise.resolve([]);
}
var roleIDs = results.map(r => r.objectId);
var parentRolesPromises = roleIDs.map( (roleId) => {
return this._getAllRoleNamesForId(roleId);
});
parentRolesPromises.push(Promise.resolve(roleIDs));
return Promise.all(parentRolesPromises);
}).then(function(results){
// Flatten
let roleIDs = results.reduce( (memo, result) => {
if (typeof result == "object") {
memo = memo.concat(result);
} else {
memo.push(result);
}
return memo;
}, []);
return Promise.resolve(roleIDs);
});
};