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:
parent
5bb65e70bb
commit
8c31a4d8c4
@ -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
|
||||
*
|
||||
|
@ -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)},
|
||||
]
|
Loading…
Reference in New Issue
Block a user