mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-06 12:31:33 +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:
@@ -31,4 +31,34 @@ module.exports = function (Groups) {
|
||||
const isMembers = await Groups.isMemberOfGroups(uid, groupNames);
|
||||
return groupNames.filter((name, i) => isMembers[i]);
|
||||
}
|
||||
|
||||
Groups.getUserInviteGroups = async function (uid) {
|
||||
let allGroups = await Groups.getNonPrivilegeGroups('groups:createtime', 0, -1);
|
||||
allGroups = allGroups.filter(group => !Groups.ephemeralGroups.includes(group.name));
|
||||
|
||||
const publicGroups = allGroups.filter(group => group.hidden === 0 && group.system === 0 && group.private === 0);
|
||||
const adminModGroups = [{ name: 'administrators' }, { name: 'Global Moderators' }];
|
||||
// Private (but not hidden)
|
||||
const privateGroups = allGroups.filter(group => group.hidden === 0 && group.system === 0 && group.private === 1);
|
||||
|
||||
const [ownership, isAdmin, isGlobalMod] = await Promise.all([
|
||||
Promise.all(privateGroups.map(group => Groups.ownership.isOwner(uid, group.name))),
|
||||
user.isAdministrator(uid),
|
||||
user.isGlobalModerator(uid),
|
||||
]);
|
||||
const ownGroups = privateGroups.filter((group, index) => ownership[index]);
|
||||
|
||||
let inviteGroups = [];
|
||||
if (isAdmin) {
|
||||
inviteGroups = inviteGroups.concat(adminModGroups).concat(privateGroups);
|
||||
} else if (isGlobalMod) {
|
||||
inviteGroups = inviteGroups.concat(privateGroups);
|
||||
} else {
|
||||
inviteGroups = inviteGroups.concat(ownGroups);
|
||||
}
|
||||
|
||||
return inviteGroups
|
||||
.concat(publicGroups)
|
||||
.map(group => group.name);
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user