mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-28 09:36:16 +01:00
feat: update groups.leave to allow global mods to kick users out of groups
This commit is contained in:
@@ -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]]');
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user