mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-20 16:35:17 +00:00
Can change admin status of conversation members
This commit is contained in:
@ -143,12 +143,36 @@ pub fn add_member(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
r.success("The user was added to the conversation!")
|
||||
}
|
||||
|
||||
/// Update admin status of a user
|
||||
pub fn set_admin(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
let conv_membership = r.post_conv("convID")?;
|
||||
let conv = conversations_helper::get_single(conv_membership.conv_id)?;
|
||||
let user_to_update = r.post_user_id("userID")?;
|
||||
let set_admin = r.post_bool("setAdmin")?;
|
||||
|
||||
if conv.is_managed() {
|
||||
r.bad_request("This conversation is managed, you can not manually change its members!".to_string())?;
|
||||
}
|
||||
|
||||
if !conv.can_mark_other_users_admin(r.user_id_ref()?) {
|
||||
r.forbidden("You are not allowed to make users admin in this conversation!".to_string())?;
|
||||
}
|
||||
|
||||
if conv.get_membership(&user_to_update).is_none() {
|
||||
r.bad_request("This user is not a member of this conversation!".to_string())?;
|
||||
}
|
||||
|
||||
conversations_helper::set_admin(&conv.id, &user_to_update, set_admin)?;
|
||||
|
||||
r.success("The user was added to the conversation!")
|
||||
}
|
||||
|
||||
/// Remove a member from a conversation
|
||||
pub fn remove_member(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
let conv_membership = r.post_conv("convID")?;
|
||||
let conv = conversations_helper::get_single(conv_membership.conv_id)?;
|
||||
|
||||
let user_to_add = r.post_user_id("userID")?;
|
||||
let user_to_remove = r.post_user_id("userID")?;
|
||||
|
||||
if conv.is_managed() {
|
||||
r.bad_request("This conversation is managed, you can not manually change its members!".to_string())?;
|
||||
@ -158,11 +182,11 @@ pub fn remove_member(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
r.forbidden("You are not allowed to remove members from this conversation!".to_string())?;
|
||||
}
|
||||
|
||||
if conv.get_membership(&user_to_add).is_none() {
|
||||
if conv.get_membership(&user_to_remove).is_none() {
|
||||
r.bad_request("This user is not a member of this conversation!".to_string())?;
|
||||
}
|
||||
|
||||
conversations_helper::remove_member(&user_to_add, conv.id, r.user_id_ref()?)?;
|
||||
conversations_helper::remove_member(&user_to_remove, conv.id, r.user_id_ref()?)?;
|
||||
|
||||
r.ok()
|
||||
}
|
||||
|
Reference in New Issue
Block a user