Remove the admin toggle route

This commit is contained in:
Johannes Zellner
2016-02-11 10:46:57 +01:00
parent db5cc1f694
commit 163ceef527
3 changed files with 1 additions and 45 deletions
+1 -29
View File
@@ -12,7 +12,6 @@ exports = module.exports = {
remove: removeUser,
get: getUser,
getByResetToken: getByResetToken,
changeAdmin: changeAdmin,
getAllAdmins: getAllAdmins,
resetPasswordByIdentifier: resetPasswordByIdentifier,
setPassword: setPassword,
@@ -228,7 +227,7 @@ function listUsers(callback) {
if (error) return callback(new UserError(UserError.INTERNAL_ERROR, error));
var allUsers = result.map(function (obj) {
var u = _.pick(obj, 'id', 'username', 'email', 'displayName', 'groupIds');
var u = _.pick(obj, 'id', 'username', 'email', 'displayName', 'groupIds');
u.admin = u.groupIds.indexOf(groups.ADMIN_GROUP_ID) !== -1;
return u;
});
@@ -289,33 +288,6 @@ function updateUser(userId, username, email, displayName, callback) {
});
}
function changeAdmin(username, admin, callback) {
assert.strictEqual(typeof username, 'string');
assert.strictEqual(typeof admin, 'boolean');
assert.strictEqual(typeof callback, 'function');
getUser(username, function (error, user) {
if (error) return callback(error);
userdb.getAllAdmins(function (error, result) {
if (error) return callback(new UserError(UserError.INTERNAL_ERROR, error));
// protect from a system where there is no admin left
if (result.length <= 1 && !admin) return callback(new UserError(UserError.NOT_ALLOWED, 'Only admin'));
var func = admin ? groups.addMember : groups.removeMember;
func(groups.ADMIN_GROUP_ID, user.id, function (error) {
if (error) return callback(new UserError(UserError.INTERNAL_ERROR, error));
callback(null);
mailer.adminChanged(user, admin);
});
});
});
}
function setGroups(userId, groupIds, callback) {
assert.strictEqual(typeof userId, 'string');
assert(Array.isArray(groupIds));