1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-12-26 13:38:52 +00:00

Do one TODO

This commit is contained in:
Pierre HUBERT 2020-03-26 17:11:24 +01:00
parent c222c8b054
commit c945c6acda
2 changed files with 2 additions and 5 deletions

View File

@ -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

View File

@ -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<boolean> {
public static async IsLastAdmin(groupID: number, userID: number) : Promise<boolean> {
return await this.GetMembershipLevel(groupID, userID) == GroupMembershipLevels.ADMINISTRATOR
&& await GroupsHelper.CountMembersAtLevel(groupID, GroupMembershipLevels.ADMINISTRATOR) == 1;
}