feat: update groups.leave to allow global mods to kick users out of groups

This commit is contained in:
Julian Lam
2023-12-01 13:04:32 -05:00
parent 78835ebbe9
commit 2c6024e07f
2 changed files with 14 additions and 6 deletions

View File

@@ -201,10 +201,9 @@ groupsAPI.leave = async function (caller, data) {
throw new Error('[[error:cant-remove-self-as-admin]]');
}
const [groupData, isCallerAdmin, isCallerOwner, userExists, isMember] = await Promise.all([
const [groupData, isCallerOwner, userExists, isMember] = await Promise.all([
groups.getGroupData(groupName),
user.isAdministrator(caller.uid),
groups.ownership.isOwner(caller.uid, groupName),
isOwner(caller, groupName, false),
user.exists(data.uid),
groups.isMember(data.uid, groupName),
]);
@@ -221,7 +220,7 @@ groupsAPI.leave = async function (caller, data) {
throw new Error('[[error:group-leave-disabled]]');
}
if (isSelf || isCallerAdmin || isCallerOwner) {
if (isSelf || isCallerOwner) {
await groups.leave(groupName, data.uid);
} else {
throw new Error('[[error:no-privileges]]');

View File

@@ -759,7 +759,7 @@ describe('Groups', () => {
});
});
describe('socket methods', () => {
describe('socket/api methods', () => {
it('should error if data is null', (done) => {
socketGroups.before({ uid: 0 }, 'groups.join', null, (err) => {
assert.equal(err.message, '[[error:invalid-data]]');
@@ -1166,12 +1166,21 @@ describe('Groups', () => {
);
});
it('should remove user from group', async () => {
it('should remove user from group if caller is admin', async () => {
await apiGroups.leave({ uid: adminUid }, { uid: testUid, slug: 'newgroup' });
const isMember = await Groups.isMember(testUid, 'newgroup');
assert(!isMember);
});
it('should remove user from group if caller is a global moderator', async () => {
const globalModUid = await User.getUidByUsername('glomod');
await apiGroups.join({ uid: adminUid }, { uid: testUid, slug: 'newgroup' });
await apiGroups.leave({ uid: globalModUid }, { uid: testUid, slug: 'newgroup' });
const isMember = await Groups.isMember(testUid, 'newgroup');
assert(!isMember);
});
it('should fail with invalid data', async () => {
let err;
try {