diff --git a/src/controllers/GroupsController.ts b/src/controllers/GroupsController.ts index 356e0de..e0e4425 100644 --- a/src/controllers/GroupsController.ts +++ b/src/controllers/GroupsController.ts @@ -532,11 +532,8 @@ export class GroupsController { */ public static async RemoveMembership(h: RequestHandler) { const groupID = await h.postGroupIDWithAccess("id", GroupsAccessLevel.LIMITED_ACCESS); - const level = await GroupsHelper.GetMembershipLevel(groupID, h.getUserId()); - // TODO : use new method - if(level == GroupMembershipLevels.ADMINISTRATOR - && await GroupsHelper.CountMembersAtLevel(groupID, GroupMembershipLevels.ADMINISTRATOR) == 1) + if(await GroupsHelper.IsLastAdmin(groupID, h.getUserId())) h.error(401, "You are the last administrator of the group!"); // Delete mebmership diff --git a/src/helpers/GroupsHelper.ts b/src/helpers/GroupsHelper.ts index ee6a8d4..d78ad2b 100644 --- a/src/helpers/GroupsHelper.ts +++ b/src/helpers/GroupsHelper.ts @@ -398,7 +398,7 @@ export class GroupsHelper { * @param groupID Target group ID * @param userID Target user ID */ - private static async IsLastAdmin(groupID: number, userID: number) : Promise { + public static async IsLastAdmin(groupID: number, userID: number) : Promise { return await this.GetMembershipLevel(groupID, userID) == GroupMembershipLevels.ADMINISTRATOR && await GroupsHelper.CountMembersAtLevel(groupID, GroupMembershipLevels.ADMINISTRATOR) == 1; }