mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-28 17:46:16 +01:00
check for last owner on user kick from group
This commit is contained in:
@@ -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,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);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -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) {
|
||||
callback(err);
|
||||
}
|
||||
groups.kick(data.uid, data.groupName, isOwner, callback);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
SocketGroups.create = function(socket, data, callback) {
|
||||
if (!socket.uid) {
|
||||
|
||||
Reference in New Issue
Block a user