check for last owner on user kick from group

This commit is contained in:
pichalite
2016-03-10 18:59:49 +00:00
parent 09b93ac6ff
commit c1c5db4b77
3 changed files with 30 additions and 3 deletions

View File

@@ -413,4 +413,24 @@ module.exports = function(Groups) {
}
db.getSetMembers('group:' + groupName + ':pending', callback);
};
Groups.kick = function(uid, groupName, isOwner, callback) {
if (isOwner) {
// If the owners set only contains one member, error out!
async.waterfall([
function (next) {
db.setCount('group:' + groupName + ':owners', next);
},
function (numOwners, next) {
if (numOwners <= 1) {
return next(new Error('[[error:group-needs-owner]]'));
}
Groups.leave(groupName, uid, callback);
next();
}
], callback);
} else {
Groups.leave(groupName, uid, callback);
}
};
};