1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-25 23:09:22 +00:00

Replace get_members_info with a more appropriate route

This commit is contained in:
Pierre HUBERT 2021-04-25 15:58:24 +02:00
parent f34310733a
commit 92787dbb4d
5 changed files with 14 additions and 37 deletions

View File

@ -1,26 +0,0 @@
//! #Forez member information
//!
//! @author Pierre Hubert
use serde::Serialize;
use crate::api_data::group_member_api::GroupMemberAPI;
use crate::api_data::user_info::{APIAdvancedInfo, APIUserInfo};
use crate::data::error::Res;
use crate::data::group_member::GroupMember;
use crate::data::user::{User, UserID};
#[derive(Serialize)]
pub struct ForezMemberAPI {
user: APIAdvancedInfo,
membership: GroupMemberAPI,
}
impl ForezMemberAPI {
pub fn new(user: &User, membership: &GroupMember, request_from: UserID) -> Res<Self> {
Ok(Self {
user: APIUserInfo::new_advanced_info(&Some(request_from.clone()), user)?,
membership: GroupMemberAPI::new(membership),
})
}
}

View File

@ -70,5 +70,4 @@ pub mod removed_user_from_conv_message;
pub mod user_is_writing_message_in_conversation; pub mod user_is_writing_message_in_conversation;
pub mod res_create_conversation_for_group; pub mod res_create_conversation_for_group;
pub mod notification_settings_api; pub mod notification_settings_api;
pub mod push_notifications_status_api; pub mod push_notifications_status_api;
pub mod forez_member_api;

View File

@ -5,8 +5,8 @@
//! //!
//! @author Pierre Hubert //! @author Pierre Hubert
use crate::api_data::forez_member_api::ForezMemberAPI;
use crate::api_data::group_api::GroupApi; use crate::api_data::group_api::GroupApi;
use crate::api_data::user_info::APIUserInfo;
use crate::data::base_request_handler::BaseRequestHandler; use crate::data::base_request_handler::BaseRequestHandler;
use crate::data::config::conf; use crate::data::config::conf;
use crate::data::http_request_handler::HttpRequestHandler; use crate::data::http_request_handler::HttpRequestHandler;
@ -27,18 +27,18 @@ pub fn get_list_groups(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Get advanced information about all the members of a group /// Get advanced information about all the members of a group
pub fn get_members_info(r: &mut HttpRequestHandler) -> RequestResult { pub fn get_member_info(r: &mut HttpRequestHandler) -> RequestResult {
let group = r.post_forez_group("group")?; let group = r.post_forez_group("group")?;
let member = r.post_user_id("user")?;
let members = groups_helper::get_list_members(&group)?; let membership = groups_helper::get_membership(&group, Some(member.clone()))?;
let mut users = vec![];
for member in members { if !membership.is_at_least_member() {
let user = user_helper::find_user_by_id(&member.user_id)?; r.bad_request("This user is not a member of the group yet!".to_string())?;
users.push(ForezMemberAPI::new(&user, &member, r.user_id()?)?);
} }
r.set_response(users) let user = user_helper::find_user_by_id(&member)?;
r.set_response(APIUserInfo::new_advanced_info(&Some(member), &user)?)
} }
/// Set presence /// Set presence

View File

@ -69,6 +69,10 @@ impl GroupMember {
pub fn is_moderator(&self) -> bool { pub fn is_moderator(&self) -> bool {
self.level <= GroupMembershipLevel::MODERATOR self.level <= GroupMembershipLevel::MODERATOR
} }
pub fn is_at_least_member(&self) -> bool {
self.level <= GroupMembershipLevel::MEMBER
}
} }
#[cfg(test)] #[cfg(test)]

View File

@ -300,6 +300,6 @@ pub fn get_routes() -> Vec<Route> {
// Forez controller // Forez controller
Route::post("/forez/get_groups", Box::new(forez_controller::get_list_groups)), Route::post("/forez/get_groups", Box::new(forez_controller::get_list_groups)),
Route::post("/forez/get_members_info", Box::new(forez_controller::get_members_info)), Route::post("/forez/get_member_info", Box::new(forez_controller::get_member_info)),
] ]
} }