mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-30 12:20:38 +01:00
feat: #11420, add new GET routes to retrieve pending and invited members of a group, plus accept/reject pending
This commit is contained in:
@@ -206,11 +206,57 @@ groupsAPI.rescind = async (caller, data) => {
|
||||
|
||||
await groups.ownership.rescind(data.uid, groupName);
|
||||
logGroupEvent(caller, 'group-owner-rescind', {
|
||||
groupName: groupName,
|
||||
groupName,
|
||||
targetUid: data.uid,
|
||||
});
|
||||
};
|
||||
|
||||
groupsAPI.getPending = async (caller, { slug }) => {
|
||||
const groupName = await groups.getGroupNameByGroupSlug(slug);
|
||||
await isOwner(caller, groupName);
|
||||
|
||||
return await groups.getPending(groupName);
|
||||
};
|
||||
|
||||
groupsAPI.accept = async (caller, { slug, uid }) => {
|
||||
const groupName = await groups.getGroupNameByGroupSlug(slug);
|
||||
|
||||
await isOwner(caller, groupName);
|
||||
const isPending = await groups.isPending(uid, groupName);
|
||||
if (!isPending) {
|
||||
throw new Error('[[error:group-user-not-pending]]');
|
||||
}
|
||||
|
||||
await groups.acceptMembership(groupName, uid);
|
||||
logGroupEvent(caller, 'group-accept-membership', {
|
||||
groupName,
|
||||
targetUid: uid,
|
||||
});
|
||||
};
|
||||
|
||||
groupsAPI.reject = async (caller, { slug, uid }) => {
|
||||
const groupName = await groups.getGroupNameByGroupSlug(slug);
|
||||
|
||||
await isOwner(caller, groupName);
|
||||
const isPending = await groups.isPending(uid, groupName);
|
||||
if (!isPending) {
|
||||
throw new Error('[[error:group-user-not-pending]]');
|
||||
}
|
||||
|
||||
await groups.rejectMembership(groupName, uid);
|
||||
logGroupEvent(caller, 'group-reject-membership', {
|
||||
groupName,
|
||||
targetUid: uid,
|
||||
});
|
||||
};
|
||||
|
||||
groupsAPI.getInvites = async (caller, { slug }) => {
|
||||
const groupName = await groups.getGroupNameByGroupSlug(slug);
|
||||
await isOwner(caller, groupName);
|
||||
|
||||
return await groups.getInvites(groupName);
|
||||
};
|
||||
|
||||
async function isOwner(caller, groupName) {
|
||||
if (typeof groupName !== 'string') {
|
||||
throw new Error('[[error:invalid-group-name]]');
|
||||
|
||||
Reference in New Issue
Block a user