1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-26 07:19:23 +00:00

Can delete a group membership

This commit is contained in:
Pierre HUBERT 2019-12-27 18:31:31 +01:00
parent b396dcd01c
commit a3e05bd49e
2 changed files with 23 additions and 0 deletions

View File

@ -516,6 +516,27 @@ export class GroupsController {
h.success("Membership invitation has been cancelled!"); h.success("Membership invitation has been cancelled!");
} }
/**
* Delete the membership of a user to a group
*
* @param h Request handler
*/
public static async RemoveMembership(h: RequestHandler) {
const groupID = await h.postGroupIDWithAccess("id", GroupsAccessLevel.LIMITED_ACCESS);
const level = await GroupsHelper.GetMembershipLevel(groupID, h.getUserId());
if(level == GroupMembershipLevels.ADMINISTRATOR
&& await GroupsHelper.CountMembersAtLevel(groupID, GroupMembershipLevels.ADMINISTRATOR) == 1)
h.error(401, "You are the last administrator of the group!");
// Delete mebmership
await GroupsHelper.DeleteMember(groupID, h.getUserId());
// TODO : delete group membership notifications
h.success("Your membership has been successfully deleted!");
}
/** /**
* Turn a GroupInfo object into a valid API object * Turn a GroupInfo object into a valid API object
* *

View File

@ -124,4 +124,6 @@ export const Routes : Route[] = [
{path: "/groups/get_membership", cb: (h) => GroupsController.GetMembership(h)}, {path: "/groups/get_membership", cb: (h) => GroupsController.GetMembership(h)},
{path: "/groups/cancel_invitation", cb: (h) => GroupsController.CancelInvitation(h)}, {path: "/groups/cancel_invitation", cb: (h) => GroupsController.CancelInvitation(h)},
{path: "/groups/remove_membership", cb: (h) => GroupsController.RemoveMembership(h)},
] ]