mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
breaking: remove deprecated groups socket calls
socket.emit('groups.join') removed use `PUT /api/v3/groups/:slug/membership/:uid`
socket.emit('groups.leave') removed use `DELETE /api/v3/groups/:slug/membership/:uid`
socket.emit('groups.grant') removed, `PUT /api/v3/groups/:slug/ownership/:uid`
socket.emit('groups.rescind') removed, `DELETE /api/v3/groups/:slug/ownership/:uid`
socket.emit('groups.update') removed, `PUT /api/v3/groups/:slug`
socket.emit('groups.create') removed, `POST /api/v3/groups`
socket.emit('groups.delete') removed, `DELETE /api/v3/groups`
This commit is contained in:
@@ -5,8 +5,6 @@ const user = require('../user');
|
|||||||
const utils = require('../utils');
|
const utils = require('../utils');
|
||||||
const events = require('../events');
|
const events = require('../events');
|
||||||
const privileges = require('../privileges');
|
const privileges = require('../privileges');
|
||||||
const api = require('../api');
|
|
||||||
const sockets = require('.');
|
|
||||||
|
|
||||||
const SocketGroups = module.exports;
|
const SocketGroups = module.exports;
|
||||||
|
|
||||||
@@ -16,18 +14,6 @@ SocketGroups.before = async (socket, method, data) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketGroups.join = async (socket, data) => {
|
|
||||||
sockets.warnDeprecated(socket, 'PUT /api/v3/groups/:slug/membership/:uid');
|
|
||||||
const slug = await groups.getGroupField(data.groupName, 'slug');
|
|
||||||
await api.groups.join(socket, { slug: slug, uid: data.uid || socket.uid });
|
|
||||||
};
|
|
||||||
|
|
||||||
SocketGroups.leave = async (socket, data) => {
|
|
||||||
sockets.warnDeprecated(socket, 'DELETE /api/v3/groups/:slug/membership/:uid');
|
|
||||||
const slug = await groups.getGroupField(data.groupName, 'slug');
|
|
||||||
await api.groups.leave(socket, { slug: slug, uid: data.uid || socket.uid });
|
|
||||||
};
|
|
||||||
|
|
||||||
SocketGroups.addMember = async (socket, data) => {
|
SocketGroups.addMember = async (socket, data) => {
|
||||||
await isOwner(socket, data);
|
await isOwner(socket, data);
|
||||||
if (data.groupName === 'administrators' || groups.isPrivilegeGroup(data.groupName)) {
|
if (data.groupName === 'administrators' || groups.isPrivilegeGroup(data.groupName)) {
|
||||||
@@ -78,28 +64,6 @@ async function isInvited(socket, data) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SocketGroups.grant = async (socket, data) => {
|
|
||||||
sockets.warnDeprecated(socket, 'PUT /api/v3/groups/:slug/ownership/:uid');
|
|
||||||
|
|
||||||
await isOwner(socket, data);
|
|
||||||
await groups.ownership.grant(data.toUid, data.groupName);
|
|
||||||
logGroupEvent(socket, 'group-owner-grant', {
|
|
||||||
groupName: data.groupName,
|
|
||||||
targetUid: data.toUid,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
SocketGroups.rescind = async (socket, data) => {
|
|
||||||
sockets.warnDeprecated(socket, 'DELETE /api/v3/groups/:slug/ownership/:uid');
|
|
||||||
|
|
||||||
await isOwner(socket, data);
|
|
||||||
await groups.ownership.rescind(data.toUid, data.groupName);
|
|
||||||
logGroupEvent(socket, 'group-owner-rescind', {
|
|
||||||
groupName: data.groupName,
|
|
||||||
targetUid: data.toUid,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
SocketGroups.accept = async (socket, data) => {
|
SocketGroups.accept = async (socket, data) => {
|
||||||
await isOwner(socket, data);
|
await isOwner(socket, data);
|
||||||
await groups.acceptMembership(data.groupName, data.toUid);
|
await groups.acceptMembership(data.groupName, data.toUid);
|
||||||
@@ -189,15 +153,6 @@ SocketGroups.rejectInvite = async (socket, data) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketGroups.update = async (socket, data) => {
|
|
||||||
sockets.warnDeprecated(socket, 'PUT /api/v3/groups/:slug');
|
|
||||||
await isOwner(socket, data);
|
|
||||||
|
|
||||||
const slug = await groups.getGroupField(data.groupName, 'slug');
|
|
||||||
await api.groups.update(socket, { slug, ...data.values });
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
SocketGroups.kick = async (socket, data) => {
|
SocketGroups.kick = async (socket, data) => {
|
||||||
await isOwner(socket, data);
|
await isOwner(socket, data);
|
||||||
if (socket.uid === parseInt(data.uid, 10)) {
|
if (socket.uid === parseInt(data.uid, 10)) {
|
||||||
@@ -212,18 +167,6 @@ SocketGroups.kick = async (socket, data) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketGroups.create = async (socket, data) => {
|
|
||||||
sockets.warnDeprecated(socket, 'POST /api/v3/groups');
|
|
||||||
const groupData = await api.groups.create(socket, data);
|
|
||||||
return groupData;
|
|
||||||
};
|
|
||||||
|
|
||||||
SocketGroups.delete = async (socket, data) => {
|
|
||||||
sockets.warnDeprecated(socket, 'DEL /api/v3/groups');
|
|
||||||
const slug = await groups.getGroupField(data.groupName, 'slug');
|
|
||||||
await api.groups.delete(socket, { slug: slug });
|
|
||||||
};
|
|
||||||
|
|
||||||
SocketGroups.search = async (socket, data) => {
|
SocketGroups.search = async (socket, data) => {
|
||||||
data.options = data.options || {};
|
data.options = data.options || {};
|
||||||
|
|
||||||
|
|||||||
543
test/groups.js
543
test/groups.js
@@ -11,6 +11,7 @@ const helpers = require('./helpers');
|
|||||||
const Groups = require('../src/groups');
|
const Groups = require('../src/groups');
|
||||||
const User = require('../src/user');
|
const User = require('../src/user');
|
||||||
const socketGroups = require('../src/socket.io/groups');
|
const socketGroups = require('../src/socket.io/groups');
|
||||||
|
const apiGroups = require('../src/api/groups');
|
||||||
const meta = require('../src/meta');
|
const meta = require('../src/meta');
|
||||||
const navigation = require('../src/navigation/admin');
|
const navigation = require('../src/navigation/admin');
|
||||||
|
|
||||||
@@ -366,22 +367,19 @@ describe('Groups', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail if group name is invalid', (done) => {
|
it('should fail if group name is invalid', async () => {
|
||||||
socketGroups.create({ uid: adminUid }, { name: ['test', 'administrators'] }, (err) => {
|
try {
|
||||||
assert.equal(err.message, '[[error:invalid-group-name]]');
|
await apiGroups.create({ uid: adminUid }, { name: ['test', 'administrators'] });
|
||||||
done();
|
} catch (err) {
|
||||||
});
|
return assert.equal(err.message, '[[error:invalid-group-name]]');
|
||||||
|
}
|
||||||
|
assert(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not create a system group', (done) => {
|
it('should not create a system group', async () => {
|
||||||
socketGroups.create({ uid: adminUid }, { name: 'mysystemgroup', system: true }, (err) => {
|
await apiGroups.create({ uid: adminUid }, { name: 'mysystemgroup', system: true });
|
||||||
assert.ifError(err);
|
const data = await Groups.getGroupData('mysystemgroup');
|
||||||
Groups.getGroupData('mysystemgroup', (err, data) => {
|
assert.strictEqual(data.system, 0);
|
||||||
assert.ifError(err);
|
|
||||||
assert.strictEqual(data.system, 0);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail if group name is invalid', (done) => {
|
it('should fail if group name is invalid', (done) => {
|
||||||
@@ -466,60 +464,67 @@ describe('Groups', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to rename if group name is invalid', (done) => {
|
it('should fail to rename if group name is invalid', async () => {
|
||||||
socketGroups.update({ uid: adminUid }, { groupName: ['updateTestGroup?'], values: {} }, (err) => {
|
try {
|
||||||
assert.strictEqual(err.message, '[[error:invalid-group-name]]');
|
await apiGroups.update({ uid: adminUid }, { slug: ['updateTestGroup?'], values: {} });
|
||||||
done();
|
} catch (err) {
|
||||||
});
|
return assert.strictEqual(err.message, '[[error:invalid-group-name]]');
|
||||||
|
}
|
||||||
|
assert(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to rename if group name is too short', (done) => {
|
it('should fail to rename if group name is too short', async () => {
|
||||||
socketGroups.update({ uid: adminUid }, { groupName: 'updateTestGroup?', values: { name: '' } }, (err) => {
|
try {
|
||||||
assert.strictEqual(err.message, '[[error:group-name-too-short]]');
|
const slug = await Groups.getGroupField('updateTestGroup?', 'slug');
|
||||||
done();
|
await apiGroups.update({ uid: adminUid }, { slug: slug, name: '' });
|
||||||
});
|
} catch (err) {
|
||||||
|
return assert.strictEqual(err.message, '[[error:group-name-too-short]]');
|
||||||
|
}
|
||||||
|
assert(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to rename if group name is invalid', (done) => {
|
it('should fail to rename if group name is invalid', async () => {
|
||||||
socketGroups.update({ uid: adminUid }, { groupName: 'updateTestGroup?', values: { name: ['invalid'] } }, (err) => {
|
try {
|
||||||
assert.strictEqual(err.message, '[[error:invalid-group-name]]');
|
const slug = await Groups.getGroupField('updateTestGroup?', 'slug');
|
||||||
done();
|
await apiGroups.update({ uid: adminUid }, { slug: slug, name: ['invalid'] });
|
||||||
});
|
} catch (err) {
|
||||||
|
return assert.strictEqual(err.message, '[[error:invalid-group-name]]');
|
||||||
|
}
|
||||||
|
assert(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to rename if group name is invalid', (done) => {
|
it('should fail to rename if group name is invalid', async () => {
|
||||||
socketGroups.update({ uid: adminUid }, { groupName: 'updateTestGroup?', values: { name: 'cid:0:privileges:ban' } }, (err) => {
|
try {
|
||||||
assert.strictEqual(err.message, '[[error:invalid-group-name]]');
|
const slug = await Groups.getGroupField('updateTestGroup?', 'slug');
|
||||||
done();
|
await apiGroups.update({ uid: adminUid }, { slug: slug, name: 'cid:0:privileges:ban' });
|
||||||
});
|
} catch (err) {
|
||||||
|
return assert.strictEqual(err.message, '[[error:invalid-group-name]]');
|
||||||
|
}
|
||||||
|
assert(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to rename if group name is too long', (done) => {
|
it('should fail to rename if group name is too long', async () => {
|
||||||
socketGroups.update({ uid: adminUid }, { groupName: 'updateTestGroup?', values: { name: 'verylongstringverylongstringverylongstringverylongstringverylongstringverylongstringverylongstringverylongstringverylongstringverylongstringverylongstringverylongstringverylongstringverylongstringverylongstringverylongstringverylongstringverylongstringverylongstringverylongstring' } }, (err) => {
|
try {
|
||||||
assert.strictEqual(err.message, '[[error:group-name-too-long]]');
|
const slug = await Groups.getGroupField('updateTestGroup?', 'slug');
|
||||||
done();
|
await apiGroups.update({ uid: adminUid }, { slug: slug, name: 'verylongstringverylongstringverylongstringverylongstringverylongstringverylongstringverylongstringverylongstringverylongstringverylongstringverylongstringverylongstringverylongstringverylongstringverylongstringverylongstringverylongstringverylongstringverylongstringverylongstring' });
|
||||||
});
|
} catch (err) {
|
||||||
|
return assert.strictEqual(err.message, '[[error:group-name-too-long]]');
|
||||||
|
}
|
||||||
|
assert(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to rename if group name is invalid', (done) => {
|
it('should fail to rename if group name is invalid', async () => {
|
||||||
socketGroups.update({ uid: adminUid }, { groupName: 'updateTestGroup?', values: { name: 'test:test' } }, (err) => {
|
const slug = await Groups.getGroupField('updateTestGroup?', 'slug');
|
||||||
assert.strictEqual(err.message, '[[error:invalid-group-name]]');
|
const invalidNames = ['test:test', 'another/test', '---'];
|
||||||
done();
|
for (const name of invalidNames) {
|
||||||
});
|
try {
|
||||||
});
|
// eslint-disable-next-line no-await-in-loop
|
||||||
|
await apiGroups.update({ uid: adminUid }, { slug: slug, name: name });
|
||||||
it('should fail to rename if group name is invalid', (done) => {
|
assert(false);
|
||||||
socketGroups.update({ uid: adminUid }, { groupName: 'updateTestGroup?', values: { name: 'another/test' } }, (err) => {
|
} catch (err) {
|
||||||
assert.strictEqual(err.message, '[[error:invalid-group-name]]');
|
assert.strictEqual(err.message, '[[error:invalid-group-name]]');
|
||||||
done();
|
}
|
||||||
});
|
}
|
||||||
});
|
|
||||||
|
|
||||||
it('should fail to rename if group name is invalid', (done) => {
|
|
||||||
socketGroups.update({ uid: adminUid }, { groupName: 'updateTestGroup?', values: { name: '---' } }, (err) => {
|
|
||||||
assert.strictEqual(err.message, '[[error:invalid-group-name]]');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to rename group to an existing group', (done) => {
|
it('should fail to rename group to an existing group', (done) => {
|
||||||
@@ -621,7 +626,7 @@ describe('Groups', () => {
|
|||||||
try {
|
try {
|
||||||
meta.config.allowPrivateGroups = false;
|
meta.config.allowPrivateGroups = false;
|
||||||
const newUid = await User.create({ username: 'newadmin' });
|
const newUid = await User.create({ username: 'newadmin' });
|
||||||
await socketGroups.join({ uid: newUid }, { groupName: ['test', 'administrators'], uid: newUid }, 1);
|
await apiGroups.join({ uid: newUid }, { slug: ['test', 'administrators'], uid: newUid }, 1);
|
||||||
const isMember = await Groups.isMember(newUid, 'administrators');
|
const isMember = await Groups.isMember(newUid, 'administrators');
|
||||||
assert(!isMember);
|
assert(!isMember);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -658,7 +663,8 @@ describe('Groups', () => {
|
|||||||
|
|
||||||
it('should add user to Global Moderators group', async () => {
|
it('should add user to Global Moderators group', async () => {
|
||||||
const uid = await User.create({ username: 'glomod' });
|
const uid = await User.create({ username: 'glomod' });
|
||||||
await socketGroups.join({ uid: adminUid }, { groupName: 'Global Moderators', uid: uid });
|
const slug = await Groups.getGroupField('Global Moderators', 'slug');
|
||||||
|
await apiGroups.join({ uid: adminUid }, { slug: slug, uid: uid });
|
||||||
const isGlobalMod = await User.isGlobalModerator(uid);
|
const isGlobalMod = await User.isGlobalModerator(uid);
|
||||||
assert.strictEqual(isGlobalMod, true);
|
assert.strictEqual(isGlobalMod, true);
|
||||||
});
|
});
|
||||||
@@ -709,7 +715,8 @@ describe('Groups', () => {
|
|||||||
async function test(groupName) {
|
async function test(groupName) {
|
||||||
let err;
|
let err;
|
||||||
try {
|
try {
|
||||||
await socketGroups.join({ uid: uid }, { groupName: groupName });
|
const slug = await Groups.getGroupField(groupName, 'slug');
|
||||||
|
await apiGroups.join({ uid: uid }, { slug: slug, uid: uid });
|
||||||
const isMember = await Groups.isMember(uid, groupName);
|
const isMember = await Groups.isMember(uid, groupName);
|
||||||
assert.strictEqual(isMember, false);
|
assert.strictEqual(isMember, false);
|
||||||
} catch (_err) {
|
} catch (_err) {
|
||||||
@@ -726,8 +733,7 @@ describe('Groups', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should allow admins to join private groups', async () => {
|
it('should allow admins to join private groups', async () => {
|
||||||
const groupsAPI = require('../src/api/groups');
|
await apiGroups.join({ uid: adminUid }, { uid: adminUid, slug: 'global-moderators' });
|
||||||
await groupsAPI.join({ uid: adminUid }, { uid: adminUid, slug: 'global-moderators' });
|
|
||||||
assert(await Groups.isMember(adminUid, 'Global Moderators'));
|
assert(await Groups.isMember(adminUid, 'Global Moderators'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -810,102 +816,96 @@ describe('Groups', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return error if not logged in', (done) => {
|
it('should return error if not logged in', async () => {
|
||||||
socketGroups.join({ uid: 0 }, {}, (err) => {
|
try {
|
||||||
|
await apiGroups.join({ uid: 0 }, {});
|
||||||
|
assert(false);
|
||||||
|
} catch (err) {
|
||||||
assert.equal(err.message, '[[error:invalid-uid]]');
|
assert.equal(err.message, '[[error:invalid-uid]]');
|
||||||
done();
|
}
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return error if group name is special', (done) => {
|
it('should return error if group name is special', async () => {
|
||||||
socketGroups.join({ uid: testUid }, { groupName: 'administrators' }, (err) => {
|
try {
|
||||||
|
await apiGroups.join({ uid: testUid }, { slug: 'administrators', uid: testUid });
|
||||||
|
assert(false);
|
||||||
|
} catch (err) {
|
||||||
assert.equal(err.message, '[[error:not-allowed]]');
|
assert.equal(err.message, '[[error:not-allowed]]');
|
||||||
done();
|
}
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should error if group does not exist', (done) => {
|
it('should error if group does not exist', async () => {
|
||||||
socketGroups.join({ uid: adminUid }, { groupName: 'doesnotexist' }, (err) => {
|
try {
|
||||||
|
await apiGroups.join({ uid: adminUid }, { slug: 'doesnotexist', uid: adminUid });
|
||||||
|
assert(false);
|
||||||
|
} catch (err) {
|
||||||
assert.equal(err.message, '[[error:no-group]]');
|
assert.equal(err.message, '[[error:no-group]]');
|
||||||
done();
|
}
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should join test group', (done) => {
|
it('should join test group', async () => {
|
||||||
meta.config.allowPrivateGroups = 0;
|
meta.config.allowPrivateGroups = 0;
|
||||||
socketGroups.join({ uid: adminUid }, { groupName: 'Test' }, (err) => {
|
await apiGroups.join({ uid: adminUid }, { slug: 'test', uid: adminUid });
|
||||||
assert.ifError(err);
|
const isMember = await Groups.isMember(adminUid, 'Test');
|
||||||
Groups.isMember(adminUid, 'Test', (err, isMember) => {
|
assert(isMember);
|
||||||
assert.ifError(err);
|
|
||||||
assert(isMember);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should error if not logged in', (done) => {
|
it('should error if not logged in', async () => {
|
||||||
socketGroups.leave({ uid: 0 }, {}, (err) => {
|
try {
|
||||||
|
await apiGroups.leave({ uid: 0 }, {});
|
||||||
|
assert(false);
|
||||||
|
} catch (err) {
|
||||||
assert.equal(err.message, '[[error:invalid-uid]]');
|
assert.equal(err.message, '[[error:invalid-uid]]');
|
||||||
done();
|
}
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return error if group name is special', (done) => {
|
it('should return error if group name is special', async () => {
|
||||||
socketGroups.leave({ uid: adminUid }, { groupName: 'administrators' }, (err) => {
|
try {
|
||||||
|
await apiGroups.leave({ uid: adminUid }, { slug: 'administrators', uid: adminUid });
|
||||||
|
assert(false);
|
||||||
|
} catch (err) {
|
||||||
assert.equal(err.message, '[[error:cant-remove-self-as-admin]]');
|
assert.equal(err.message, '[[error:cant-remove-self-as-admin]]');
|
||||||
done();
|
}
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should leave test group', (done) => {
|
it('should leave test group', async () => {
|
||||||
socketGroups.leave({ uid: adminUid }, { groupName: 'Test' }, (err) => {
|
await apiGroups.leave({ uid: adminUid }, { slug: 'test', uid: adminUid });
|
||||||
assert.ifError(err);
|
const isMember = await Groups.isMember(adminUid, 'Test');
|
||||||
Groups.isMember('Test', adminUid, (err, isMember) => {
|
assert(!isMember);
|
||||||
assert.ifError(err);
|
|
||||||
assert(!isMember);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to join if group is private and join requests are disabled', (done) => {
|
it('should fail to join if group is private and join requests are disabled', async () => {
|
||||||
meta.config.allowPrivateGroups = 1;
|
meta.config.allowPrivateGroups = 1;
|
||||||
socketGroups.join({ uid: testUid }, { groupName: 'PrivateNoJoin' }, (err) => {
|
try {
|
||||||
|
await apiGroups.join({ uid: testUid }, { slug: 'privatenojoin', uid: testUid });
|
||||||
|
assert(false);
|
||||||
|
} catch (err) {
|
||||||
assert.equal(err.message, '[[error:group-join-disabled]]');
|
assert.equal(err.message, '[[error:group-join-disabled]]');
|
||||||
done();
|
}
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to leave if group is private and leave is disabled', async () => {
|
it('should fail to leave if group is private and leave is disabled', async () => {
|
||||||
await socketGroups.join({ uid: testUid }, { groupName: 'PrivateNoLeave' });
|
await Groups.join('PrivateNoLeave', testUid);
|
||||||
|
const isMember = await Groups.isMember(testUid, 'PrivateNoLeave');
|
||||||
|
assert(isMember);
|
||||||
try {
|
try {
|
||||||
await socketGroups.leave({ uid: testUid }, { groupName: 'PrivateNoLeave' });
|
await apiGroups.leave({ uid: testUid }, { slug: 'privatenoleave', uid: testUid });
|
||||||
|
assert(false);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
assert.equal(err.message, '[[error:group-leave-disabled]]');
|
assert.equal(err.message, '[[error:group-leave-disabled]]');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should join if user is admin', (done) => {
|
it('should join if user is admin', async () => {
|
||||||
socketGroups.join({ uid: adminUid }, { groupName: 'PrivateCanJoin' }, (err) => {
|
await apiGroups.join({ uid: adminUid }, { slug: 'privatecanjoin', uid: adminUid });
|
||||||
assert.ifError(err);
|
const isMember = await Groups.isMember(adminUid, 'PrivateCanJoin');
|
||||||
Groups.isMember(adminUid, 'PrivateCanJoin', (err, isMember) => {
|
assert(isMember);
|
||||||
assert.ifError(err);
|
|
||||||
assert(isMember);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should request membership for regular user', (done) => {
|
it('should request membership for regular user', async () => {
|
||||||
socketGroups.join({ uid: testUid }, { groupName: 'PrivateCanJoin' }, (err) => {
|
await apiGroups.join({ uid: testUid }, { slug: 'privatecanjoin', uid: testUid });
|
||||||
assert.ifError(err);
|
const isPending = await Groups.isPending(testUid, 'PrivateCanJoin');
|
||||||
Groups.isPending(testUid, 'PrivateCanJoin', (err, isPending) => {
|
assert(isPending);
|
||||||
assert.ifError(err);
|
|
||||||
assert(isPending);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reject membership of user', (done) => {
|
it('should reject membership of user', (done) => {
|
||||||
@@ -926,73 +926,30 @@ describe('Groups', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should accept membership of user', (done) => {
|
it('should accept membership of user', async () => {
|
||||||
socketGroups.join({ uid: testUid }, { groupName: 'PrivateCanJoin' }, (err) => {
|
await apiGroups.join({ uid: testUid }, { slug: 'privatecanjoin', uid: testUid });
|
||||||
assert.ifError(err);
|
await socketGroups.accept({ uid: adminUid }, { groupName: 'PrivateCanJoin', toUid: testUid });
|
||||||
socketGroups.accept({ uid: adminUid }, { groupName: 'PrivateCanJoin', toUid: testUid }, (err) => {
|
const isMember = await Groups.isMember(testUid, 'PrivateCanJoin');
|
||||||
assert.ifError(err);
|
assert(isMember);
|
||||||
Groups.isMember(testUid, 'PrivateCanJoin', (err, isMember) => {
|
|
||||||
assert.ifError(err);
|
|
||||||
assert(isMember);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reject/accept all memberships requests', (done) => {
|
it('should reject/accept all memberships requests', async () => {
|
||||||
function requestMembership(uids, callback) {
|
async function requestMembership(uid1, uid2) {
|
||||||
async.series([
|
await apiGroups.join({ uid: uid1 }, { slug: 'privatecanjoin', uid: uid1 });
|
||||||
function (next) {
|
await apiGroups.join({ uid: uid2 }, { slug: 'privatecanjoin', uid: uid2 });
|
||||||
socketGroups.join({ uid: uids.uid1 }, { groupName: 'PrivateCanJoin' }, next);
|
|
||||||
},
|
|
||||||
function (next) {
|
|
||||||
socketGroups.join({ uid: uids.uid2 }, { groupName: 'PrivateCanJoin' }, next);
|
|
||||||
},
|
|
||||||
], (err) => {
|
|
||||||
callback(err);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
let uids;
|
const [uid1, uid2] = await Promise.all([
|
||||||
async.waterfall([
|
User.create({ username: 'groupuser1' }),
|
||||||
function (next) {
|
User.create({ username: 'groupuser2' }),
|
||||||
async.parallel({
|
]);
|
||||||
uid1: function (next) {
|
await requestMembership(uid1, uid2);
|
||||||
User.create({ username: 'groupuser1' }, next);
|
await socketGroups.rejectAll({ uid: adminUid }, { groupName: 'PrivateCanJoin' });
|
||||||
},
|
const pending = await Groups.getPending('PrivateCanJoin');
|
||||||
uid2: function (next) {
|
assert.equal(pending.length, 0);
|
||||||
User.create({ username: 'groupuser2' }, next);
|
await requestMembership(uid1, uid2);
|
||||||
},
|
await socketGroups.acceptAll({ uid: adminUid }, { groupName: 'PrivateCanJoin' });
|
||||||
}, next);
|
const isMembers = await Groups.isMembers([uid1, uid2], 'PrivateCanJoin');
|
||||||
},
|
assert.deepStrictEqual(isMembers, [true, true]);
|
||||||
function (results, next) {
|
|
||||||
uids = results;
|
|
||||||
requestMembership(results, next);
|
|
||||||
},
|
|
||||||
function (next) {
|
|
||||||
socketGroups.rejectAll({ uid: adminUid }, { groupName: 'PrivateCanJoin' }, next);
|
|
||||||
},
|
|
||||||
function (next) {
|
|
||||||
Groups.getPending('PrivateCanJoin', next);
|
|
||||||
},
|
|
||||||
function (pending, next) {
|
|
||||||
assert.equal(pending.length, 0);
|
|
||||||
requestMembership(uids, next);
|
|
||||||
},
|
|
||||||
function (next) {
|
|
||||||
socketGroups.acceptAll({ uid: adminUid }, { groupName: 'PrivateCanJoin' }, next);
|
|
||||||
},
|
|
||||||
function (next) {
|
|
||||||
Groups.isMembers([uids.uid1, uids.uid2], 'PrivateCanJoin', next);
|
|
||||||
},
|
|
||||||
function (isMembers, next) {
|
|
||||||
assert(isMembers[0]);
|
|
||||||
assert(isMembers[1]);
|
|
||||||
next();
|
|
||||||
},
|
|
||||||
], (err) => {
|
|
||||||
done(err);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should issue invite to user', (done) => {
|
it('should issue invite to user', (done) => {
|
||||||
@@ -1088,26 +1045,16 @@ describe('Groups', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should grant ownership to user', (done) => {
|
it('should grant ownership to user', async () => {
|
||||||
socketGroups.grant({ uid: adminUid }, { groupName: 'PrivateCanJoin', toUid: testUid }, (err) => {
|
await apiGroups.grant({ uid: adminUid }, { slug: 'privatecanjoin', uid: testUid });
|
||||||
assert.ifError(err);
|
const isOwner = await Groups.ownership.isOwner(testUid, 'PrivateCanJoin');
|
||||||
Groups.ownership.isOwner(testUid, 'PrivateCanJoin', (err, isOwner) => {
|
assert(isOwner);
|
||||||
assert.ifError(err);
|
|
||||||
assert(isOwner);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should rescind ownership from user', (done) => {
|
it('should rescind ownership from user', async () => {
|
||||||
socketGroups.rescind({ uid: adminUid }, { groupName: 'PrivateCanJoin', toUid: testUid }, (err) => {
|
await apiGroups.rescind({ uid: adminUid }, { slug: 'privatecanjoin', uid: testUid });
|
||||||
assert.ifError(err);
|
const isOwner = await Groups.ownership.isOwner(testUid, 'PrivateCanJoin');
|
||||||
Groups.ownership.isOwner(testUid, 'PrivateCanJoin', (err, isOwner) => {
|
assert(!isOwner);
|
||||||
assert.ifError(err);
|
|
||||||
assert(!isOwner);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to kick user with invalid data', (done) => {
|
it('should fail to kick user with invalid data', (done) => {
|
||||||
@@ -1128,116 +1075,108 @@ describe('Groups', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to create group with invalid data', (done) => {
|
it('should fail to create group with invalid data', async () => {
|
||||||
socketGroups.create({ uid: 0 }, {}, (err) => {
|
try {
|
||||||
|
await apiGroups.create({ uid: 0 }, {});
|
||||||
|
assert(false);
|
||||||
|
} catch (err) {
|
||||||
assert.equal(err.message, '[[error:no-privileges]]');
|
assert.equal(err.message, '[[error:no-privileges]]');
|
||||||
done();
|
}
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to create group if group creation is disabled', (done) => {
|
it('should fail to create group if group creation is disabled', async () => {
|
||||||
socketGroups.create({ uid: testUid }, { name: 'avalidname' }, (err) => {
|
try {
|
||||||
|
await apiGroups.create({ uid: testUid }, { name: 'avalidname' });
|
||||||
|
assert(false);
|
||||||
|
} catch (err) {
|
||||||
assert.equal(err.message, '[[error:no-privileges]]');
|
assert.equal(err.message, '[[error:no-privileges]]');
|
||||||
done();
|
}
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to create group if name is privilege group', (done) => {
|
it('should fail to create group if name is privilege group', async () => {
|
||||||
socketGroups.create({ uid: 1 }, { name: 'cid:1:privileges:groups:find' }, (err) => {
|
try {
|
||||||
|
await apiGroups.create({ uid: 1 }, { name: 'cid:1:privileges:groups:find' });
|
||||||
|
assert(false);
|
||||||
|
} catch (err) {
|
||||||
assert.equal(err.message, '[[error:invalid-group-name]]');
|
assert.equal(err.message, '[[error:invalid-group-name]]');
|
||||||
done();
|
}
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create/update group', (done) => {
|
it('should create/update group', async () => {
|
||||||
socketGroups.create({ uid: adminUid }, { name: 'createupdategroup' }, (err, groupData) => {
|
const groupData = await apiGroups.create({ uid: adminUid }, { name: 'createupdategroup' });
|
||||||
assert.ifError(err);
|
assert(groupData);
|
||||||
assert(groupData);
|
|
||||||
const data = {
|
|
||||||
groupName: 'createupdategroup',
|
|
||||||
values: {
|
|
||||||
name: 'renamedupdategroup',
|
|
||||||
description: 'cat group',
|
|
||||||
userTitle: 'cats',
|
|
||||||
userTitleEnabled: 1,
|
|
||||||
disableJoinRequests: 1,
|
|
||||||
hidden: 1,
|
|
||||||
private: 0,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
socketGroups.update({ uid: adminUid }, data, (err) => {
|
|
||||||
assert.ifError(err);
|
|
||||||
Groups.get('renamedupdategroup', {}, (err, groupData) => {
|
|
||||||
assert.ifError(err);
|
|
||||||
assert.equal(groupData.name, 'renamedupdategroup');
|
|
||||||
assert.equal(groupData.userTitle, 'cats');
|
|
||||||
assert.equal(groupData.description, 'cat group');
|
|
||||||
assert.equal(groupData.hidden, true);
|
|
||||||
assert.equal(groupData.disableJoinRequests, true);
|
|
||||||
assert.equal(groupData.private, false);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should fail to create a group with name guests', (done) => {
|
|
||||||
socketGroups.create({ uid: adminUid }, { name: 'guests' }, (err) => {
|
|
||||||
assert.equal(err.message, '[[error:invalid-group-name]]');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should fail to rename guests group', (done) => {
|
|
||||||
const data = {
|
const data = {
|
||||||
groupName: 'guests',
|
slug: 'createupdategroup',
|
||||||
values: {
|
name: 'renamedupdategroup',
|
||||||
name: 'guests2',
|
description: 'cat group',
|
||||||
},
|
userTitle: 'cats',
|
||||||
|
userTitleEnabled: 1,
|
||||||
|
disableJoinRequests: 1,
|
||||||
|
hidden: 1,
|
||||||
|
private: 0,
|
||||||
};
|
};
|
||||||
socketGroups.update({ uid: adminUid }, data, (err) => {
|
await apiGroups.update({ uid: adminUid }, data);
|
||||||
|
const updatedData = await Groups.get('renamedupdategroup', {});
|
||||||
|
assert.equal(updatedData.name, 'renamedupdategroup');
|
||||||
|
assert.equal(updatedData.userTitle, 'cats');
|
||||||
|
assert.equal(updatedData.description, 'cat group');
|
||||||
|
assert.equal(updatedData.hidden, true);
|
||||||
|
assert.equal(updatedData.disableJoinRequests, true);
|
||||||
|
assert.equal(updatedData.private, false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fail to create a group with name guests', async () => {
|
||||||
|
try {
|
||||||
|
await apiGroups.create({ uid: adminUid }, { name: 'guests' });
|
||||||
|
assert(false);
|
||||||
|
} catch (err) {
|
||||||
assert.equal(err.message, '[[error:invalid-group-name]]');
|
assert.equal(err.message, '[[error:invalid-group-name]]');
|
||||||
done();
|
}
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should delete group', (done) => {
|
it('should fail to rename guests group', async () => {
|
||||||
socketGroups.delete({ uid: adminUid }, { groupName: 'renamedupdategroup' }, (err) => {
|
const data = {
|
||||||
assert.ifError(err);
|
slug: 'guests',
|
||||||
Groups.exists('renamedupdategroup', (err, exists) => {
|
name: 'guests2',
|
||||||
assert.ifError(err);
|
};
|
||||||
assert(!exists);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should fail to delete group if name is special', (done) => {
|
try {
|
||||||
socketGroups.delete({ uid: adminUid }, { groupName: 'administrators' }, (err) => {
|
await apiGroups.update({ uid: adminUid }, data);
|
||||||
assert.equal(err.message, '[[error:not-allowed]]');
|
assert(false);
|
||||||
done();
|
} catch (err) {
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should fail to delete group if name is special', (done) => {
|
|
||||||
socketGroups.delete({ uid: adminUid }, { groupName: 'registered-users' }, (err) => {
|
|
||||||
assert.equal(err.message, '[[error:not-allowed]]');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should fail to delete group if name is special', (done) => {
|
|
||||||
socketGroups.delete({ uid: adminUid }, { groupName: 'Global Moderators' }, (err) => {
|
|
||||||
assert.equal(err.message, '[[error:not-allowed]]');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should fail to delete group if name is special', (done) => {
|
|
||||||
socketGroups.delete({ uid: adminUid }, { groupName: 'guests' }, (err) => {
|
|
||||||
assert.equal(err.message, '[[error:invalid-group-name]]');
|
assert.equal(err.message, '[[error:invalid-group-name]]');
|
||||||
done();
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should delete group', async () => {
|
||||||
|
await apiGroups.delete({ uid: adminUid }, { slug: 'renamedupdategroup' });
|
||||||
|
const exists = await Groups.exists('renamedupdategroup');
|
||||||
|
assert(!exists);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fail to delete group if name is special', async () => {
|
||||||
|
const specialGroups = [
|
||||||
|
'administrators', 'registered-users', 'verified-users',
|
||||||
|
'unverified-users', 'global-moderators',
|
||||||
|
];
|
||||||
|
for (const slug of specialGroups) {
|
||||||
|
try {
|
||||||
|
// eslint-disable-next-line no-await-in-loop
|
||||||
|
await apiGroups.delete({ uid: adminUid }, { slug: slug });
|
||||||
|
assert(false);
|
||||||
|
} catch (err) {
|
||||||
|
assert.equal(err.message, '[[error:not-allowed]]');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fail to delete group if name is special', async () => {
|
||||||
|
try {
|
||||||
|
await apiGroups.delete({ uid: adminUid }, { slug: 'guests' });
|
||||||
|
assert(false);
|
||||||
|
} catch (err) {
|
||||||
|
assert.equal(err.message, '[[error:invalid-group-name]]');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to load more groups with invalid data', (done) => {
|
it('should fail to load more groups with invalid data', (done) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user