Merge pull request #4346 from pichalite/issue-4340

check for last owner on user kick from group
v1.18.x
Barış Soner Uşaklı 9 years ago
commit e49af50ac8

@ -125,5 +125,6 @@
"no-session-found": "No login session found!",
"not-in-room": "User not in room",
"no-users-in-room": "No users in this room"
"no-users-in-room": "No users in this room",
"cant-kick-self": "You can't kick yourself from the group"
}

@ -413,4 +413,23 @@ 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, next);
}
], callback);
} else {
Groups.leave(groupName, uid, callback);
}
};
};

@ -155,9 +155,15 @@ SocketGroups.kick = isOwner(function(socket, data, callback) {
if (socket.uid === parseInt(data.uid, 10)) {
return callback(new Error('[[error:cant-kick-self]]'));
}
groups.leave(data.groupName, data.uid, callback);
});
groups.ownership.isOwner(data.uid, data.groupName, function(err, isOwner) {
if (err) {
return callback(err);
}
groups.kick(data.uid, data.groupName, isOwner, callback);
});
});
SocketGroups.create = function(socket, data, callback) {
if (!socket.uid) {

Loading…
Cancel
Save