Skip to content

Commit

Permalink
fix: remove socketGroups.kick
Browse files Browse the repository at this point in the history
  • Loading branch information
julianlam committed Apr 6, 2023
1 parent 9d49ec6 commit f043dce
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/api/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
});
Expand Down
14 changes: 0 additions & 14 deletions src/socket.io/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || {};

Expand Down
24 changes: 8 additions & 16 deletions test/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
assert(!isMember);
done();
});
});
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);
});

it('should fail to create group with invalid data', async () => {
Expand Down Expand Up @@ -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 () => {
Expand Down

0 comments on commit f043dce

Please sign in to comment.