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:
parent
703177a587
commit
786ac364bd
@ -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!")
|
||||
}
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user