mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-22 21:39:21 +00:00
Can request to join a group
This commit is contained in:
parent
135c3d6459
commit
205541f6d8
@ -13,11 +13,12 @@ use crate::constants::{DEFAULT_GROUP_LOGO, PATH_GROUPS_LOGOS};
|
||||
use crate::controllers::routes::RequestResult;
|
||||
use crate::data::group::{Group, GroupAccessLevel, GroupPostsCreationLevel, GroupRegistrationLevel, GroupVisibilityLevel};
|
||||
use crate::data::group_id::GroupID;
|
||||
use crate::data::group_member::GroupMembershipLevel;
|
||||
use crate::data::group_member::{GroupMember, GroupMembershipLevel};
|
||||
use crate::data::http_request_handler::HttpRequestHandler;
|
||||
use crate::data::new_group::NewGroup;
|
||||
use crate::helpers::{groups_helper, virtual_directory_helper};
|
||||
use crate::helpers::virtual_directory_helper::VirtualDirType;
|
||||
use crate::utils::date_utils::time;
|
||||
|
||||
/// Create a new group
|
||||
pub fn create(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
@ -193,3 +194,36 @@ pub fn respond_invitation(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
|
||||
r.success("Response to the invitation was successfully saved!")
|
||||
}
|
||||
|
||||
/// Send a request to join a group
|
||||
pub fn send_request(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
let group_id = r.post_group_id_with_access("id", GroupAccessLevel::LIMITED_ACCESS)?;
|
||||
|
||||
if groups_helper::get_membership_level(&group_id, r.user_id_opt())? != GroupMembershipLevel::VISITOR {
|
||||
r.forbidden("You are not currently a visitor of the group!".to_string())?;
|
||||
}
|
||||
|
||||
let group = groups_helper::get_info(&group_id)?;
|
||||
|
||||
let level = match group.registration_level {
|
||||
GroupRegistrationLevel::OPEN_REGISTRATION => GroupMembershipLevel::MEMBER,
|
||||
GroupRegistrationLevel::MODERATED_REGISTRATION => GroupMembershipLevel::PENDING,
|
||||
GroupRegistrationLevel::CLOSED_REGISTRATION => {
|
||||
r.forbidden("You are not authorized to send a registration request for this group!".to_string())?;
|
||||
unreachable!();
|
||||
}
|
||||
};
|
||||
|
||||
groups_helper::insert_member(&GroupMember {
|
||||
id: 0,
|
||||
user_id: r.user_id()?,
|
||||
group_id,
|
||||
time_create: time(),
|
||||
level,
|
||||
following: true,
|
||||
})?;
|
||||
|
||||
// TODO : Send a notification, if required
|
||||
|
||||
r.success("The membership has been successfully saved!")
|
||||
}
|
@ -154,6 +154,8 @@ pub fn get_routes() -> Vec<Route> {
|
||||
|
||||
Route::post("/groups/respond_invitation", Box::new(groups_controller::respond_invitation)),
|
||||
|
||||
Route::post("/groups/send_request", Box::new(groups_controller::send_request)),
|
||||
|
||||
|
||||
// Virtual directory controller
|
||||
Route::post("/user/findbyfolder", Box::new(virtual_directory_controller::find_user)),
|
||||
|
Loading…
Reference in New Issue
Block a user