1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-06-21 08:55:16 +00:00

Collect new group settings

This commit is contained in:
2020-06-26 08:58:00 +02:00
parent c2bac9401a
commit dad2363c92
8 changed files with 152 additions and 10 deletions

View File

@ -1,10 +1,10 @@
use crate::constants::database_tables_names::USER_ACCESS_TOKENS_TABLE;
use crate::data::api_client::APIClient;
use crate::data::error::{ExecError, ResultBoxError};
use crate::data::user::UserID;
use crate::data::user_token::UserAccessToken;
use crate::constants::database_tables_names::USER_ACCESS_TOKENS_TABLE;
use crate::helpers::{database, user_helper};
use crate::helpers::database::{QueryInfo, InsertQuery, DeleteQuery};
use crate::helpers::database::{DeleteQuery, InsertQuery, QueryInfo};
use crate::utils::crypt_utils::{crypt_pass, rand_str};
/// Account helper
@ -78,11 +78,27 @@ pub fn get_user_by_login_token(token: &str, client: &APIClient) -> ResultBoxErro
/// Destroy a given user login tokens
pub fn destroy_login_tokens(id: &UserID, client: &APIClient) -> ResultBoxError<()> {
database::delete(DeleteQuery::new(USER_ACCESS_TOKENS_TABLE)
.cond_u32("service_id", client.id)
.cond_user_id("user_id", id)
)?;
Ok(())
}
/// Check out whether a virtual directory is taken by a user or not
pub fn check_user_directory_availability(dir: &str, user_id: Option<UserID>) -> ResultBoxError<bool> {
let found_user = user_helper::find_user_by_virtual_directory(dir);
match (found_user, user_id) {
// A user was found, but we did not specify a user
(Ok(_), None) => Ok(false),
// A user was found, and we specified a user ID, we check if the IDs are the same
(Ok(user), Some(id)) => Ok(user.id == id),
// No user was found, virtual directory is considered as available
(Err(_), _) => Ok(true)
}
}

View File

@ -271,6 +271,17 @@ pub fn count_members(group_id: &GroupID) -> ResultBoxError<usize> {
.exec_count()
}
/// Check the availability of a virtual directory for a group
pub fn check_directory_availability(dir: &str, group_id: Option<GroupID>) -> ResultBoxError<bool> {
let group = find_by_virtual_directory(dir);
match (group, group_id) {
(Ok(_), None) => Ok(false),
(Ok(g), Some(g2)) => Ok(g == g2),
(Err(_), _) => Ok(true)
}
}
/// Turn a database entry into a group struct
fn db_to_group(row: &database::RowResult) -> ResultBoxError<Group> {
let group_id = row.get_group_id("id")?;

View File

@ -8,4 +8,5 @@ pub mod custom_emojies_helper;
pub mod background_image_helper;
pub mod likes_helper;
pub mod groups_helper;
pub mod conversations_helper;
pub mod conversations_helper;
pub mod virtual_directory_helper;

View File

@ -0,0 +1,32 @@
//! # Virtual directory helper
//!
//! @author Pierre Hubert
use crate::data::error::ResultBoxError;
use crate::data::group_id::GroupID;
use crate::helpers::{account_helper, groups_helper};
use crate::utils::virtual_directories_utils::check_virtual_directory;
pub enum VirtualDirType {
USER,
GROUP,
}
/// Check the availability of a virtual directory
pub fn check_availability(dir: &str, target_id: u64, target_type: VirtualDirType) -> ResultBoxError<bool> {
if !check_virtual_directory(dir) {
return Ok(false);
}
match target_type {
VirtualDirType::USER => {
// TODO : implement this check
unimplemented!();
}
VirtualDirType::GROUP => {
Ok(
account_helper::check_user_directory_availability(dir, None)?
&& groups_helper::check_directory_availability(dir, Some(GroupID::new(target_id)))?)
}
}
}