mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: remove socketGroups.kick
This commit is contained in:
@@ -158,7 +158,7 @@ groupsAPI.leave = async function (caller, data) {
|
||||
throw new Error('[[error:invalid-uid]]');
|
||||
}
|
||||
if (!isMember) {
|
||||
return;
|
||||
throw new Error('[[error:group-not-member]]');
|
||||
}
|
||||
|
||||
if (groupData.disableLeave && isSelf) {
|
||||
@@ -183,7 +183,7 @@ groupsAPI.leave = async function (caller, data) {
|
||||
const uids = await groups.getOwners(groupName);
|
||||
await notifications.push(notification, uids);
|
||||
|
||||
logGroupEvent(caller, 'group-leave', {
|
||||
logGroupEvent(caller, `group-${isSelf ? 'leave' : 'kick'}`, {
|
||||
groupName: groupName,
|
||||
targetUid: data.uid,
|
||||
});
|
||||
|
||||
@@ -56,20 +56,6 @@ async function isOwner(socket, data) {
|
||||
}
|
||||
}
|
||||
|
||||
SocketGroups.kick = async (socket, data) => {
|
||||
await isOwner(socket, data);
|
||||
if (socket.uid === parseInt(data.uid, 10)) {
|
||||
throw new Error('[[error:cant-kick-self]]');
|
||||
}
|
||||
|
||||
const isOwnerBit = await groups.ownership.isOwner(data.uid, data.groupName);
|
||||
await groups.kick(data.uid, data.groupName, isOwnerBit);
|
||||
logGroupEvent(socket, 'group-kick', {
|
||||
groupName: data.groupName,
|
||||
targetUid: data.uid,
|
||||
});
|
||||
};
|
||||
|
||||
SocketGroups.search = async (socket, data) => {
|
||||
data.options = data.options || {};
|
||||
|
||||
|
||||
@@ -973,22 +973,14 @@ describe('Groups', () => {
|
||||
assert(!isOwner);
|
||||
});
|
||||
|
||||
it('should fail to kick user with invalid data', (done) => {
|
||||
socketGroups.kick({ uid: adminUid }, { groupName: 'PrivateCanJoin', uid: adminUid }, (err) => {
|
||||
assert.equal(err.message, '[[error:cant-kick-self]]');
|
||||
done();
|
||||
});
|
||||
it('should fail to kick user with invalid data', async () => {
|
||||
assert.rejects(apiGroups.leave({ uid: adminUid }, { slug: 'privatecanjoin', uid: 8721632 }), '[[error:group-not-member]]');
|
||||
});
|
||||
|
||||
it('should kick user from group', (done) => {
|
||||
socketGroups.kick({ uid: adminUid }, { groupName: 'PrivateCanJoin', uid: testUid }, (err) => {
|
||||
assert.ifError(err);
|
||||
Groups.isMember(testUid, 'PrivateCanJoin', (err, isMember) => {
|
||||
assert.ifError(err);
|
||||
it('should kick user from group', async () => {
|
||||
await apiGroups.leave({ uid: adminUid }, { slug: 'privatecanjoin', uid: testUid });
|
||||
const isMember = await Groups.isMember(testUid, 'PrivateCanJoin');
|
||||
assert(!isMember);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail to create group with invalid data', async () => {
|
||||
@@ -1197,8 +1189,8 @@ describe('Groups', () => {
|
||||
assert.strictEqual(err.message, '[[error:cant-remove-self-as-admin]]');
|
||||
});
|
||||
|
||||
it('should not error if user is not member', async () => {
|
||||
await apiGroups.leave({ uid: adminUid }, { uid: 3, slug: 'newgroup' });
|
||||
it('should error if user is not member', async () => {
|
||||
assert.rejects(apiGroups.leave({ uid: adminUid }, { uid: 3, slug: 'newgroup' }), '[[error:group-not-member]]');
|
||||
});
|
||||
|
||||
it('should fail if trying to remove someone else from group', async () => {
|
||||
|
||||
Reference in New Issue
Block a user