1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-22 05:19:22 +00:00

Can send a request to join a group

This commit is contained in:
Pierre HUBERT 2019-12-27 09:57:28 +01:00
parent 5bb65e70bb
commit 8c31a4d8c4
2 changed files with 41 additions and 0 deletions

View File

@ -329,6 +329,45 @@ export class GroupsController {
h.success("Response to the invitation was successfully saved!");
}
/**
* Send a request to join a server
*
* @param h Request handler
*/
public static async SendRequest(h: RequestHandler) {
const groupID = await h.postGroupIDWithAccess("id", GroupsAccessLevel.LIMITED_ACCESS);
// Check the user is really a visitor of the group
if(await GroupsHelper.GetMembershipLevel(groupID, h.getUserId()) != GroupMembershipLevels.VISITOR)
h.error(401, "You are not currently a visitor of the group!");
// Check the user is allowed to send a request to join the group
const group = await GroupsHelper.GetInfo(groupID);
if(group.registrationLevel == GroupRegistrationLevel.CLOSED_REGISTRATION)
h.error(401, "You are not authorized to send a registration request for this group!");
// Create & insert membership
const member = new GroupMember({
id: -1,
userID: h.getUserId(),
timeCreate: time(),
groupID: groupID,
level: group.registrationLevel == GroupRegistrationLevel.MODERATED_REGISTRATION
? GroupMembershipLevels.PENDING : GroupMembershipLevels.MEMBER,
following: true,
});
await GroupsHelper.InsertMember(member);
if(group.registrationLevel == GroupRegistrationLevel.MODERATED_REGISTRATION) {
//TODO : Send a notification
}
h.success("The membership has been successfully saved!");
}
/**
* Turn a GroupInfo object into a valid API object
*

View File

@ -110,4 +110,6 @@ export const Routes : Route[] = [
{path: "/groups/invite", cb: (h) => GroupsController.InviteUser(h)},
{path: "/groups/respond_invitation", cb: (h) => GroupsController.RespondInvitation(h)},
{path: "/groups/send_request", cb: (h) => GroupsController.SendRequest(h)},
]