mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-31 11:50:08 +01:00
fix: remove socketGroups.issueMassInvite
This commit is contained in:
@@ -285,21 +285,22 @@ define('forum/groups/details', [
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$('[component="groups/members/bulk-invite-button"]').on('click', function () {
|
$('[component="groups/members/bulk-invite-button"]').on('click', async () => {
|
||||||
const usernames = $('[component="groups/members/bulk-invite"]').val();
|
let usernames = $('[component="groups/members/bulk-invite"]').val();
|
||||||
if (!usernames) {
|
if (!usernames) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
socket.emit('groups.issueMassInvite', {
|
|
||||||
usernames: usernames,
|
// Filter out bad usernames
|
||||||
groupName: ajaxify.data.group.name,
|
usernames = usernames.split(',').map(username => slugify(username));
|
||||||
}, function (err) {
|
usernames = await Promise.all(usernames.map(slug => api.head(`/users/bySlug/${slug}`).then(() => slug).catch(() => false)));
|
||||||
if (err) {
|
usernames = usernames.filter(Boolean);
|
||||||
return alerts.error(err);
|
|
||||||
}
|
const uids = await Promise.all(usernames.map(slug => api.get(`/users/bySlug/${slug}`).then(({ uid }) => uid)));
|
||||||
|
|
||||||
|
await Promise.all(uids.map(async uid => api.post(`/groups/${ajaxify.data.group.slug}/invites/${uid}`))).then(() => {
|
||||||
updateList();
|
updateList();
|
||||||
});
|
}).catch(alerts.error);
|
||||||
return false;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,27 +56,6 @@ async function isOwner(socket, data) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SocketGroups.issueMassInvite = async (socket, data) => {
|
|
||||||
await isOwner(socket, data);
|
|
||||||
if (!data || !data.usernames || !data.groupName) {
|
|
||||||
throw new Error('[[error:invalid-data]]');
|
|
||||||
}
|
|
||||||
let usernames = String(data.usernames).split(',');
|
|
||||||
usernames = usernames.map(username => username && username.trim());
|
|
||||||
|
|
||||||
let uids = await user.getUidsByUsernames(usernames);
|
|
||||||
uids = uids.filter(uid => !!uid && parseInt(uid, 10));
|
|
||||||
|
|
||||||
await groups.invite(data.groupName, uids);
|
|
||||||
|
|
||||||
for (const uid of uids) {
|
|
||||||
logGroupEvent(socket, 'group-invite', {
|
|
||||||
groupName: data.groupName,
|
|
||||||
targetUid: uid,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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)) {
|
||||||
|
|||||||
@@ -932,27 +932,6 @@ describe('Groups', () => {
|
|||||||
assert(isInvited);
|
assert(isInvited);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail with invalid data', (done) => {
|
|
||||||
socketGroups.issueMassInvite({ uid: adminUid }, { groupName: 'PrivateCanJoin', usernames: null }, (err) => {
|
|
||||||
assert.equal(err.message, '[[error:invalid-data]]');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should issue mass invite to users', (done) => {
|
|
||||||
User.create({ username: 'invite2' }, (err, uid) => {
|
|
||||||
assert.ifError(err);
|
|
||||||
socketGroups.issueMassInvite({ uid: adminUid }, { groupName: 'PrivateCanJoin', usernames: 'invite1, invite2' }, (err) => {
|
|
||||||
assert.ifError(err);
|
|
||||||
Groups.isInvited([adminUid, uid], 'PrivateCanJoin', (err, isInvited) => {
|
|
||||||
assert.ifError(err);
|
|
||||||
assert.deepStrictEqual(isInvited, [false, true]);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should rescind invite', async () => {
|
it('should rescind invite', async () => {
|
||||||
const uid = await User.create({ username: 'invite3' });
|
const uid = await User.create({ username: 'invite3' });
|
||||||
await apiGroups.issueInvite({ uid: adminUid }, { slug: 'privatecanjoin', uid });
|
await apiGroups.issueInvite({ uid: adminUid }, { slug: 'privatecanjoin', uid });
|
||||||
|
|||||||
Reference in New Issue
Block a user