|
|
@ -10,22 +10,38 @@ var groups = require('../../groups'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
User.makeAdmins = function(socket, uids, callback) {
|
|
|
|
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) {
|
|
|
|
async.each(uids, function(uid, next) {
|
|
|
|
toggleAdmin(uids, false, callback);
|
|
|
|
groups.join('administrators', uid, next);
|
|
|
|
|
|
|
|
}, callback);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function toggleAdmin(uids, isAdmin, callback) {
|
|
|
|
User.removeAdmins = function(socket, uids, callback) {
|
|
|
|
if(!Array.isArray(uids)) {
|
|
|
|
if(!Array.isArray(uids)) {
|
|
|
|
return callback(new Error('[[error:invalid-data]]'));
|
|
|
|
return callback(new Error('[[error:invalid-data]]'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async.each(uids, function(uid, next) {
|
|
|
|
if (uids.indexOf(socket.uid.toString()) !== -1) {
|
|
|
|
groups[isAdmin ? 'join' : 'leave']('administrators', uid, next);
|
|
|
|
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);
|
|
|
|
}, callback);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
User.createUser = function(socket, userData, callback) {
|
|
|
|
User.createUser = function(socket, userData, callback) {
|
|
|
|
if (!userData) {
|
|
|
|
if (!userData) {
|
|
|
|