mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-23 05:49:22 +00:00
Can respond to a group membership request
This commit is contained in:
parent
786ac364bd
commit
2d796d11bd
@ -295,3 +295,20 @@ pub fn update_membership(r: &mut HttpRequestHandler) -> RequestResult {
|
|||||||
|
|
||||||
r.success("User membership has been successfully updated!")
|
r.success("User membership has been successfully updated!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Respond to a group membership request
|
||||||
|
pub fn respond_request(r: &mut HttpRequestHandler) -> RequestResult {
|
||||||
|
let group_id = r.post_group_id_with_access("groupID", GroupAccessLevel::MODERATOR_ACCESS)?;
|
||||||
|
let user_id = r.post_user_id("userID")?;
|
||||||
|
let accept = r.post_bool("accept")?;
|
||||||
|
|
||||||
|
if groups_helper::get_membership_level(&group_id, Some(user_id.clone()))? != GroupMembershipLevel::PENDING {
|
||||||
|
r.forbidden("This user has not requested a membership for this group!".to_string())?;
|
||||||
|
}
|
||||||
|
|
||||||
|
groups_helper::respond_request(&group_id, &user_id, accept)?;
|
||||||
|
|
||||||
|
// TODO : Create a notification
|
||||||
|
|
||||||
|
r.success("The response to the request has been successfully saved!")
|
||||||
|
}
|
@ -162,6 +162,8 @@ pub fn get_routes() -> Vec<Route> {
|
|||||||
|
|
||||||
Route::post("/groups/update_membership_level", Box::new(groups_controller::update_membership)),
|
Route::post("/groups/update_membership_level", Box::new(groups_controller::update_membership)),
|
||||||
|
|
||||||
|
Route::post("/groups/respond_request", Box::new(groups_controller::respond_request)),
|
||||||
|
|
||||||
|
|
||||||
// Virtual directory controller
|
// Virtual directory controller
|
||||||
Route::post("/user/findbyfolder", Box::new(virtual_directory_controller::find_user)),
|
Route::post("/user/findbyfolder", Box::new(virtual_directory_controller::find_user)),
|
||||||
|
@ -401,6 +401,14 @@ pub fn respond_invitation(g: &GroupID, u: &UserID, accept: bool) -> ResultBoxErr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Respond to a group membership request
|
||||||
|
pub fn respond_request(group_id: &GroupID, user_id: &UserID, accept: bool) -> ResultBoxError {
|
||||||
|
match accept {
|
||||||
|
true => update_membership_level(&group_id, &user_id, GroupMembershipLevel::MEMBER),
|
||||||
|
false => delete_member(&group_id, &user_id),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Turn a database entry into a group struct
|
/// Turn a database entry into a group struct
|
||||||
fn db_to_group(row: &database::RowResult) -> ResultBoxError<Group> {
|
fn db_to_group(row: &database::RowResult) -> ResultBoxError<Group> {
|
||||||
let group_id = row.get_group_id("id")?;
|
let group_id = row.get_group_id("id")?;
|
||||||
|
Loading…
Reference in New Issue
Block a user