From c945c6acdad27baf67fbb31747660a92bcd78869 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Thu, 26 Mar 2020 17:11:24 +0100 Subject: [PATCH] Do one TODO --- src/controllers/GroupsController.ts | 5 +---- src/helpers/GroupsHelper.ts | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) 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; }