mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-21 00:45:18 +00:00
Collect new group settings
This commit is contained in:
@ -22,6 +22,15 @@ impl GroupVisibilityLevel {
|
||||
GroupVisibilityLevel::SECRETE_GROUP => "secrete",
|
||||
}.to_string()
|
||||
}
|
||||
|
||||
pub fn from_api(level: &str) -> GroupVisibilityLevel {
|
||||
match level {
|
||||
"open" => GroupVisibilityLevel::OPEN_GROUP,
|
||||
"private" => GroupVisibilityLevel::PRIVATE_GROUP,
|
||||
"secrete" => GroupVisibilityLevel::SECRETE_GROUP,
|
||||
_ => GroupVisibilityLevel::SECRETE_GROUP
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
@ -40,6 +49,15 @@ impl GroupRegistrationLevel {
|
||||
GroupRegistrationLevel::CLOSED_REGISTRATION => "closed",
|
||||
}.to_string()
|
||||
}
|
||||
|
||||
pub fn from_api(level: &str) -> GroupRegistrationLevel {
|
||||
match level {
|
||||
"open" => GroupRegistrationLevel::OPEN_REGISTRATION,
|
||||
"moderated" => GroupRegistrationLevel::MODERATED_REGISTRATION,
|
||||
"closed" => GroupRegistrationLevel::CLOSED_REGISTRATION,
|
||||
_ => GroupRegistrationLevel::CLOSED_REGISTRATION,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
@ -59,6 +77,14 @@ impl GroupPostsCreationLevel {
|
||||
GroupPostsCreationLevel::POSTS_LEVEL_ALL_MEMBERS => "members",
|
||||
}.to_string()
|
||||
}
|
||||
|
||||
pub fn from_api(level: &str) -> GroupPostsCreationLevel {
|
||||
match level {
|
||||
"members" => GroupPostsCreationLevel::POSTS_LEVEL_ALL_MEMBERS,
|
||||
"moderators" => GroupPostsCreationLevel::POSTS_LEVEL_MODERATORS,
|
||||
_ => GroupPostsCreationLevel::POSTS_LEVEL_MODERATORS
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
|
@ -17,8 +17,9 @@ 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, groups_helper, user_helper};
|
||||
use crate::utils::string_utils::remove_html_nodes;
|
||||
use crate::helpers::{account_helper, api_helper, conversations_helper, groups_helper, user_helper, virtual_directory_helper};
|
||||
use crate::helpers::virtual_directory_helper::VirtualDirType;
|
||||
use crate::utils::string_utils::{check_url, 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;
|
||||
|
||||
@ -440,6 +441,15 @@ impl HttpRequestHandler {
|
||||
Ok(remove_html_nodes(self.post_string_opt(name, min_length, required)?.as_str()))
|
||||
}
|
||||
|
||||
/// Get an optionnal string included in the request, with HTML codes removed
|
||||
pub fn post_string_without_html_opt(&mut self, name: &str, min_length: usize) -> ResultBoxError<Option<String>> {
|
||||
if !self.has_post_parameter(name) {
|
||||
Ok(None)
|
||||
} else {
|
||||
Ok(Some(remove_html_nodes(self.post_string_opt(name, min_length, true)?.as_str())))
|
||||
}
|
||||
}
|
||||
|
||||
/// Get & return the ID of the conversation included in the POST request
|
||||
pub fn post_conv_id(&mut self, name: &str) -> ResultBoxError<u64> {
|
||||
let conv_id = self.post_u64(name)?;
|
||||
@ -477,4 +487,34 @@ impl HttpRequestHandler {
|
||||
|
||||
Ok(group_id)
|
||||
}
|
||||
|
||||
/// Get an URL included in the request
|
||||
pub fn post_url_opt(&mut self, name: &str, required: bool) -> ResultBoxError<Option<String>> {
|
||||
let url = self.post_string_opt(name, 0, required)?;
|
||||
|
||||
if url.is_empty() && !required {
|
||||
Ok(None)
|
||||
} else {
|
||||
if !check_url(&url) {
|
||||
self.bad_request(format!("Invalid url specified in {} !", name))?;
|
||||
}
|
||||
|
||||
Ok(Some(url))
|
||||
}
|
||||
}
|
||||
|
||||
/// Get an optional virtual directory included in the request
|
||||
pub fn post_checked_virtual_directory_opt(&mut self, name: &str, target_id: u64, target_type: VirtualDirType) -> ResultBoxError<Option<String>> {
|
||||
if !self.has_post_parameter(name) {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let dir = self.post_virtual_directory(name)?;
|
||||
|
||||
if !virtual_directory_helper::check_availability(&dir, target_id, target_type)? {
|
||||
self.forbidden("Requested virtual directory is not available!".to_string())?;
|
||||
}
|
||||
|
||||
Ok(Some(dir))
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user