feat(api): group ownership API route, switch client-side to use API route

This commit is contained in:
Julian Lam
2020-12-22 14:26:31 -05:00
parent 98550d61d7
commit 32e36f7b2e
8 changed files with 53 additions and 36 deletions

View File

@@ -177,6 +177,28 @@ groupsAPI.leave = async function (caller, data) {
});
};
groupsAPI.grant = async (caller, data) => {
const groupName = await groups.getGroupNameByGroupSlug(data.slug);
await isOwner(caller, groupName);
await groups.ownership.grant(data.uid, groupName);
logGroupEvent(caller, 'group-owner-grant', {
groupName: groupName,
targetUid: data.uid,
});
};
groupsAPI.rescind = async (caller, data) => {
const groupName = await groups.getGroupNameByGroupSlug(data.slug);
await isOwner(caller, groupName);
await groups.ownership.rescind(data.uid, groupName);
logGroupEvent(caller, 'group-owner-rescind', {
groupName: groupName,
targetUid: data.uid,
});
};
async function isOwner(caller, groupName) {
if (typeof groupName !== 'string') {
throw new Error('[[error:invalid-group-name]]');