mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 02:25:55 +01:00
feat: invites regardless of registration type, invite privilege, groups to join on acceptance (#8786)
* feat: allow invites in normal registration mode + invite privilege * feat: select groups to join from an invite * test: check if groups from invitations have been joined * fix: remove unused variable * feat: write API versions of socket calls * docs: openapi specs for the new routes * test: iron out mongo redis difference * refactor: move inviteGroups endpoint into write API * refactor: use GET /api/v3/users/:uid/invites/groups Instead of GET /api/v3/users/:uid/inviteGroups * fix: no need for /api/v3 prefix when using api module * fix: tests * refactor: change POST /api/v3/users/invite To POST /api/v3/users/:uid/invites * refactor: make helpers.invite awaitable * fix: restrict invite API to self-use only * fix: move invite groups controller to write api, +tests * fix: tests Co-authored-by: Julian Lam <julian@nodebb.org>
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const async = require('async');
|
||||
|
||||
const util = require('util');
|
||||
const sleep = util.promisify(setTimeout);
|
||||
|
||||
@@ -223,37 +221,6 @@ SocketUser.getUnreadCounts = async function (socket) {
|
||||
return results;
|
||||
};
|
||||
|
||||
SocketUser.invite = async function (socket, email) {
|
||||
if (!email || !socket.uid) {
|
||||
throw new Error('[[error:invalid-data]]');
|
||||
}
|
||||
|
||||
const registrationType = meta.config.registrationType;
|
||||
if (registrationType !== 'invite-only' && registrationType !== 'admin-invite-only') {
|
||||
throw new Error('[[error:forum-not-invite-only]]');
|
||||
}
|
||||
|
||||
const isAdmin = await user.isAdministrator(socket.uid);
|
||||
if (registrationType === 'admin-invite-only' && !isAdmin) {
|
||||
throw new Error('[[error:no-privileges]]');
|
||||
}
|
||||
|
||||
const max = meta.config.maximumInvites;
|
||||
email = email.split(',').map(email => email.trim()).filter(Boolean);
|
||||
|
||||
await async.eachSeries(email, async function (email) {
|
||||
let invites = 0;
|
||||
if (max) {
|
||||
invites = await user.getInvitesNumber(socket.uid);
|
||||
}
|
||||
if (!isAdmin && max && invites >= max) {
|
||||
throw new Error('[[error:invite-maximum-met, ' + invites + ', ' + max + ']]');
|
||||
}
|
||||
|
||||
await user.sendInvitationEmail(socket.uid, email);
|
||||
});
|
||||
};
|
||||
|
||||
SocketUser.getUserByUID = async function (socket, uid) {
|
||||
return await userController.getUserDataByField(socket.uid, 'uid', uid);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user