Map group roles to scopes

This commit is contained in:
Girish Ramakrishnan
2018-06-18 14:21:54 -07:00
parent b5c8e7a52a
commit 6cd0601629
5 changed files with 50 additions and 4 deletions

View File

@@ -13,6 +13,7 @@ exports = module.exports = {
verifyWithEmail: verifyWithEmail,
remove: removeUser,
get: get,
getWithRoles: getWithRoles,
getByResetToken: getByResetToken,
getAllAdmins: getAllAdmins,
resetPasswordByIdentifier: resetPasswordByIdentifier,
@@ -330,6 +331,24 @@ function get(userId, callback) {
});
}
function getWithRoles(userId, callback) {
assert.strictEqual(typeof userId, 'string');
assert.strictEqual(typeof callback, 'function');
userdb.get(userId, function (error, result) {
if (error && error.reason === DatabaseError.NOT_FOUND) return callback(new UsersError(UsersError.NOT_FOUND));
if (error) return callback(new UsersError(UsersError.INTERNAL_ERROR, error));
groups.getGroups(userId, function (error, userGroups) {
if (error) return callback(new UsersError(UsersError.INTERNAL_ERROR, error));
result.roles = _.uniq(_.flatten(userGroups.map(function (r) { return r.roles; })));
return callback(null, result);
});
});
}
function getByResetToken(email, resetToken, callback) {
assert.strictEqual(typeof email, 'string');
assert.strictEqual(typeof resetToken, 'string');