some checks to make last admin isnt removed

v1.18.x
barisusakli 11 years ago
parent 842a1f90cf
commit 07275b5fc4

@ -100,7 +100,7 @@ define('forum/admin/users', function() {
return;
}
if (uids.indexOf(yourid) !== -1) {
if (uids.indexOf(yourid.toString()) !== -1) {
app.alertError('You can\'t remove yourself as Administrator!');
} else {
bootbox.confirm('Do you really want to remove admins?', function(confirm) {

@ -150,6 +150,10 @@
db.isSetMember('group:' + groupName + ':members', uid, callback);
};
Groups.getMemberCount = function(groupName, callback) {
db.setCount('group:' + groupName + ':members', callback);
};
Groups.isMemberOfGroupList = function(uid, groupListKey, callback) {
db.getSetMembers('group:' + groupListKey + ':members', function(err, groupNames) {
groupNames = internals.removeEphemeralGroups(groupNames);

@ -10,22 +10,38 @@ var groups = require('../../groups'),
User.makeAdmins = function(socket, uids, callback) {
toggleAdmin(uids, true, callback);
};
if(!Array.isArray(uids)) {
return callback(new Error('[[error:invalid-data]]'));
}
User.removeAdmins = function(socket, uids, callback) {
toggleAdmin(uids, false, callback);
async.each(uids, function(uid, next) {
groups.join('administrators', uid, next);
}, callback);
};
function toggleAdmin(uids, isAdmin, callback) {
User.removeAdmins = function(socket, uids, callback) {
if(!Array.isArray(uids)) {
return callback(new Error('[[error:invalid-data]]'));
}
async.each(uids, function(uid, next) {
groups[isAdmin ? 'join' : 'leave']('administrators', uid, next);
if (uids.indexOf(socket.uid.toString()) !== -1) {
return callback(new Error('[[error:cant-remove-self-as-admin]]'));
}
async.eachSeries(uids, function(uid, next) {
groups.getMemberCount('administrators', function(err, count) {
if (err) {
return next(err);
}
if (count === 1) {
return next(new Error('[[error:cant-remove-last-admin]]'));
}
groups.leave('administrators', uid, next);
});
}, callback);
}
};
User.createUser = function(socket, userData, callback) {
if (!userData) {

Loading…
Cancel
Save