1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-22 21:39:21 +00:00

Can change group membership

This commit is contained in:
Pierre HUBERT 2020-06-29 08:17:51 +02:00
parent 703177a587
commit 786ac364bd
2 changed files with 34 additions and 1 deletions

View File

@ -272,5 +272,26 @@ pub fn delete_member(r: &mut HttpRequestHandler) -> RequestResult {
/// Update a user's membership
pub fn update_membership(r: &mut HttpRequestHandler) -> RequestResult {
r.success("ready to implement")
let group_id = r.post_group_id_with_access("groupID", GroupAccessLevel::ADMIN_ACCESS)?;
let user_id = r.post_user_id("userID")?;
if user_id == r.user_id()? {
r.bad_request("You can not update your own membership!".to_string())?;
}
let level = groups_helper::get_membership_level(&group_id, Some(user_id.clone()))?;
if level > GroupMembershipLevel::MEMBER {
r.forbidden("This user is not a member of the group!".to_string())?;
}
let new_level = GroupMembershipLevel::from_api(&r.post_string("level")?);
if new_level > GroupMembershipLevel::MEMBER {
r.forbidden("You can not assign this visibility level!".to_string())?;
}
groups_helper::update_membership_level(&group_id, &user_id, new_level)?;
r.success("User membership has been successfully updated!")
}

View File

@ -30,6 +30,18 @@ impl GroupMembershipLevel {
GroupMembershipLevel::VISITOR => "visitor",
}.to_string()
}
pub fn from_api(level: &str) -> GroupMembershipLevel {
match level {
"administrator" => GroupMembershipLevel::ADMINISTRATOR,
"moderator" => GroupMembershipLevel::MODERATOR,
"member" => GroupMembershipLevel::MEMBER,
"invited" => GroupMembershipLevel::INVITED,
"pending" => GroupMembershipLevel::PENDING,
"visitor" => GroupMembershipLevel::VISITOR,
_ => GroupMembershipLevel::VISITOR,
}
}
}
pub struct GroupMember {