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]]');
|
throw new Error('[[error:invalid-uid]]');
|
||||||
}
|
}
|
||||||
if (!isMember) {
|
if (!isMember) {
|
||||||
return;
|
throw new Error('[[error:group-not-member]]');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (groupData.disableLeave && isSelf) {
|
if (groupData.disableLeave && isSelf) {
|
||||||
@@ -183,7 +183,7 @@ groupsAPI.leave = async function (caller, data) {
|
|||||||
const uids = await groups.getOwners(groupName);
|
const uids = await groups.getOwners(groupName);
|
||||||
await notifications.push(notification, uids);
|
await notifications.push(notification, uids);
|
||||||
|
|
||||||
logGroupEvent(caller, 'group-leave', {
|
logGroupEvent(caller, `group-${isSelf ? 'leave' : 'kick'}`, {
|
||||||
groupName: groupName,
|
groupName: groupName,
|
||||||
targetUid: data.uid,
|
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) => {
|
SocketGroups.search = async (socket, data) => {
|
||||||
data.options = data.options || {};
|
data.options = data.options || {};
|
||||||
|
|
||||||
|
|||||||
@@ -973,22 +973,14 @@ describe('Groups', () => {
|
|||||||
assert(!isOwner);
|
assert(!isOwner);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to kick user with invalid data', (done) => {
|
it('should fail to kick user with invalid data', async () => {
|
||||||
socketGroups.kick({ uid: adminUid }, { groupName: 'PrivateCanJoin', uid: adminUid }, (err) => {
|
assert.rejects(apiGroups.leave({ uid: adminUid }, { slug: 'privatecanjoin', uid: 8721632 }), '[[error:group-not-member]]');
|
||||||
assert.equal(err.message, '[[error:cant-kick-self]]');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should kick user from group', (done) => {
|
it('should kick user from group', async () => {
|
||||||
socketGroups.kick({ uid: adminUid }, { groupName: 'PrivateCanJoin', uid: testUid }, (err) => {
|
await apiGroups.leave({ uid: adminUid }, { slug: 'privatecanjoin', uid: testUid });
|
||||||
assert.ifError(err);
|
const isMember = await Groups.isMember(testUid, 'PrivateCanJoin');
|
||||||
Groups.isMember(testUid, 'PrivateCanJoin', (err, isMember) => {
|
assert(!isMember);
|
||||||
assert.ifError(err);
|
|
||||||
assert(!isMember);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to create group with invalid data', async () => {
|
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]]');
|
assert.strictEqual(err.message, '[[error:cant-remove-self-as-admin]]');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not error if user is not member', async () => {
|
it('should error if user is not member', async () => {
|
||||||
await apiGroups.leave({ uid: adminUid }, { uid: 3, slug: 'newgroup' });
|
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 () => {
|
it('should fail if trying to remove someone else from group', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user