1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-06-20 16:35:17 +00:00

Get the ID of a group included in a request

This commit is contained in:
2020-06-24 13:34:09 +02:00
parent c245045d67
commit 4d844ccbad
6 changed files with 70 additions and 1 deletions

View File

@ -8,4 +8,26 @@ pub enum GroupVisibilityLevel {
OPEN_GROUP,
PRIVATE_GROUP,
SECRETE_GROUP,
}
#[allow(non_camel_case_types)]
#[derive(Eq, PartialEq, Hash)]
pub enum GroupAccessLevel {
//Can not even know if the group exists or not
NO_ACCESS = 0,
//Access to the name of the group only
LIMITED_ACCESS = 1,
//Can see the posts of the group, but not a member of the group
VIEW_ACCESS = 2,
//Member access (same as view access but as member)
MEMBER_ACCESS = 3,
//Can create posts, even if posts creation is restricted
MODERATOR_ACCESS = 4,
//Can do everything
ADMIN_ACCESS = 5,
}

View File

@ -14,8 +14,10 @@ use crate::controllers::routes::RequestResult;
use crate::data::api_client::APIClient;
use crate::data::config::conf;
use crate::data::error::{ExecError, ResultBoxError};
use crate::data::group::GroupAccessLevel;
use crate::data::group_id::GroupID;
use crate::data::user::UserID;
use crate::helpers::{account_helper, api_helper, conversations_helper, user_helper};
use crate::helpers::{account_helper, api_helper, conversations_helper, groups_helper, user_helper};
use crate::utils::string_utils::remove_html_nodes;
use crate::utils::user_data_utils::{generate_new_user_data_file_name, prepare_file_creation, user_data_path};
use crate::utils::virtual_directories_utils::check_virtual_directory;
@ -448,4 +450,24 @@ impl HttpRequestHandler {
Ok(conv_id)
}
/// Get the ID
pub fn post_group_id(&mut self, name: &str) -> ResultBoxError<GroupID> {
let group_id = GroupID::new(self.post_u64(name)?);
if !groups_helper::exists(&group_id)? {
self.not_found("Specified group not found!".to_string())?;
}
Ok(group_id)
}
/// Get the ID of a group included in a request with a check for access level of current user
pub fn post_group_id_with_access(&mut self, name: &str, min_level: GroupAccessLevel) -> ResultBoxError<GroupID> {
let group_id = self.post_group_id(name)?;
// TODO : add security checks
Ok(group_id)
}
}