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

@@ -22,16 +22,15 @@ module.exports = function (Groups) {
};
Groups.ownership.grant = async function (toUid, groupName) {
// Note: No ownership checking is done here on purpose!
await db.setAdd('group:' + groupName + ':owners', toUid);
plugins.hooks.fire('action:group.grantOwnership', { uid: toUid, groupName: groupName });
};
Groups.ownership.rescind = async function (toUid, groupName) {
// Note: No ownership checking is done here on purpose!
// If the owners set only contains one member, error out!
// If the owners set only contains one member (and toUid is that member), error out!
const numOwners = await db.setCount('group:' + groupName + ':owners');
if (numOwners <= 1) {
const isOwner = await db.isSortedSetMember(`group:${groupName}:owners`);
if (numOwners <= 1 && isOwner) {
throw new Error('[[error:group-needs-owner]]');
}
await db.setRemove('group:' + groupName + ':owners', toUid);