1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-22 13:29:21 +00:00

Make all HTTP routes asynchronous

This commit is contained in:
Pierre HUBERT 2022-03-11 21:56:08 +01:00
parent 13e73ede8b
commit b2514351a1
24 changed files with 161 additions and 156 deletions

View File

@ -47,7 +47,7 @@ impl HttpRequestHandler {
} }
/// Create a new account /// Create a new account
pub fn create(r: &mut HttpRequestHandler) -> RequestResult { pub async fn create(r: &mut HttpRequestHandler) -> RequestResult {
// Get & check email // Get & check email
let email = r.post_email("emailAddress")?; let email = r.post_email("emailAddress")?;
@ -68,7 +68,7 @@ pub fn create(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Sign in user /// Sign in user
pub fn login_user(request: &mut HttpRequestHandler) -> RequestResult { pub async fn login_user(request: &mut HttpRequestHandler) -> RequestResult {
let email = request.post_email("mail")?; let email = request.post_email("mail")?;
let password = request.post_string("password")?; let password = request.post_string("password")?;
@ -92,7 +92,7 @@ pub fn login_user(request: &mut HttpRequestHandler) -> RequestResult {
} }
/// Sign out user /// Sign out user
pub fn logout_user(request: &mut HttpRequestHandler) -> RequestResult { pub async fn logout_user(request: &mut HttpRequestHandler) -> RequestResult {
if let Some(token) = request.user_access_token() { if let Some(token) = request.user_access_token() {
account_helper::destroy_login_tokens(token)?; account_helper::destroy_login_tokens(token)?;
} }
@ -101,39 +101,39 @@ pub fn logout_user(request: &mut HttpRequestHandler) -> RequestResult {
} }
/// Disconnect a user from all his devices /// Disconnect a user from all his devices
pub fn disconnect_all_devices(r: &mut HttpRequestHandler) -> RequestResult { pub async fn disconnect_all_devices(r: &mut HttpRequestHandler) -> RequestResult {
account_helper::destroy_all_user_tokens(r.user_id_ref()?)?; account_helper::destroy_all_user_tokens(r.user_id_ref()?)?;
r.success("Successfully disconnected!") r.success("Successfully disconnected!")
} }
/// Get current user ID /// Get current user ID
pub fn user_id(request: &mut HttpRequestHandler) -> RequestResult { pub async fn user_id(request: &mut HttpRequestHandler) -> RequestResult {
request.set_response(CurrentUserID::new(&request.user_id()?)) request.set_response(CurrentUserID::new(&request.user_id()?))
} }
/// Get current user email address /// Get current user email address
pub fn get_mail(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_mail(r: &mut HttpRequestHandler) -> RequestResult {
let user = user_helper::find_user_by_id(r.user_id_ref()?)?; let user = user_helper::find_user_by_id(r.user_id_ref()?)?;
r.set_response(UserMailAddressAPI::new(&user)) r.set_response(UserMailAddressAPI::new(&user))
} }
/// Check out whether an email address exists or not /// Check out whether an email address exists or not
pub fn exists_mail(r: &mut HttpRequestHandler) -> RequestResult { pub async fn exists_mail(r: &mut HttpRequestHandler) -> RequestResult {
let email = r.post_email("email")?; let email = r.post_email("email")?;
r.set_response(ResCheckEmailExists::new(account_helper::exists_mail(&email)?)) r.set_response(ResCheckEmailExists::new(account_helper::exists_mail(&email)?))
} }
/// Check out whether a given user has set security questions or not /// Check out whether a given user has set security questions or not
pub fn has_security_questions(r: &mut HttpRequestHandler) -> RequestResult { pub async fn has_security_questions(r: &mut HttpRequestHandler) -> RequestResult {
let user = r.post_user_info_from_email("email")?; let user = r.post_user_info_from_email("email")?;
r.set_response(ResCheckSecurityQuestionsExists::new(user.has_security_questions())) r.set_response(ResCheckSecurityQuestionsExists::new(user.has_security_questions()))
} }
/// Get the security questions of a user /// Get the security questions of a user
pub fn get_security_questions(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_security_questions(r: &mut HttpRequestHandler) -> RequestResult {
let user = r.post_user_info_from_email("email")?; let user = r.post_user_info_from_email("email")?;
if !user.has_security_questions() { if !user.has_security_questions() {
@ -144,7 +144,7 @@ pub fn get_security_questions(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Check the security answers given by a user to reset a password /// Check the security answers given by a user to reset a password
pub fn check_security_answers(r: &mut HttpRequestHandler) -> RequestResult { pub async fn check_security_answers(r: &mut HttpRequestHandler) -> RequestResult {
let user = r.post_user_info_from_email("email")?; let user = r.post_user_info_from_email("email")?;
if !user.has_security_questions() { if !user.has_security_questions() {
@ -171,7 +171,7 @@ pub fn check_security_answers(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Check the validity of a password reset token /// Check the validity of a password reset token
pub fn check_password_reset_token(r: &mut HttpRequestHandler) -> RequestResult { pub async fn check_password_reset_token(r: &mut HttpRequestHandler) -> RequestResult {
let user_id = r.post_user_id_from_password_reset_token("reset_token")?; let user_id = r.post_user_id_from_password_reset_token("reset_token")?;
let user = user_helper::find_user_by_id(&user_id)?; let user = user_helper::find_user_by_id(&user_id)?;
@ -179,7 +179,7 @@ pub fn check_password_reset_token(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Reset user password /// Reset user password
pub fn reset_user_password(r: &mut HttpRequestHandler) -> RequestResult { pub async fn reset_user_password(r: &mut HttpRequestHandler) -> RequestResult {
let user_id = r.post_user_id_from_password_reset_token("reset_token")?; let user_id = r.post_user_id_from_password_reset_token("reset_token")?;
let new_password = r.post_string_opt("password", 3, true)?; let new_password = r.post_string_opt("password", 3, true)?;
@ -191,7 +191,7 @@ pub fn reset_user_password(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Export account's data /// Export account's data
pub fn export_data(r: &mut HttpRequestHandler) -> RequestResult { pub async fn export_data(r: &mut HttpRequestHandler) -> RequestResult {
r.need_user_password("password")?; r.need_user_password("password")?;
let data = account_helper::export(r.user_id_ref()?)?; let data = account_helper::export(r.user_id_ref()?)?;
@ -200,7 +200,7 @@ pub fn export_data(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Delete an account /// Delete an account
pub fn delete_account(r: &mut HttpRequestHandler) -> RequestResult { pub async fn delete_account(r: &mut HttpRequestHandler) -> RequestResult {
r.need_user_password("password")?; r.need_user_password("password")?;
if r.user_id()?.id() < 2 { if r.user_id()?.id() < 2 {

View File

@ -20,7 +20,7 @@ use crate::routes::RequestResult;
use crate::utils::date_utils::time; use crate::utils::date_utils::time;
/// Create a new administrator account /// Create a new administrator account
pub fn create(r: &mut HttpRequestHandler) -> RequestResult { pub async fn create(r: &mut HttpRequestHandler) -> RequestResult {
let email = r.post_email("mail")?; let email = r.post_email("mail")?;
let name = r.post_string_opt("name", 3, true)?; let name = r.post_string_opt("name", 3, true)?;
@ -34,7 +34,7 @@ pub fn create(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Get admin auth options /// Get admin auth options
pub fn get_auth_options(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_auth_options(r: &mut HttpRequestHandler) -> RequestResult {
let mail = r.post_email("mail")?; let mail = r.post_email("mail")?;
let admin = admin_account_helper::find_admin_by_email(&mail)?; let admin = admin_account_helper::find_admin_by_email(&mail)?;
let keys = admin_account_key_helper::get_admin_keys(admin.id)?; let keys = admin_account_key_helper::get_admin_keys(admin.id)?;
@ -43,7 +43,7 @@ pub fn get_auth_options(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Login admin using a reset token /// Login admin using a reset token
pub fn auth_with_reset_token(r: &mut HttpRequestHandler) -> RequestResult { pub async fn auth_with_reset_token(r: &mut HttpRequestHandler) -> RequestResult {
let reset_token = r.post_string("token")?; let reset_token = r.post_string("token")?;
let admin = admin_account_helper::find_admin_by_email(&r.post_email("mail")?)?; let admin = admin_account_helper::find_admin_by_email(&r.post_email("mail")?)?;
@ -65,19 +65,19 @@ pub fn auth_with_reset_token(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Sign out current admin /// Sign out current admin
pub fn sign_out(r: &mut HttpRequestHandler) -> RequestResult { pub async fn sign_out(r: &mut HttpRequestHandler) -> RequestResult {
admin_access_token_helper::destroy(r.admin_id()?)?; admin_access_token_helper::destroy(r.admin_id()?)?;
r.ok() r.ok()
} }
/// Get current admin ID /// Get current admin ID
pub fn get_admin_id(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_admin_id(r: &mut HttpRequestHandler) -> RequestResult {
r.set_response(AdminIDAPI::new(r.admin_id()?)) r.set_response(AdminIDAPI::new(r.admin_id()?))
} }
/// Get and return the list of administrators /// Get and return the list of administrators
pub fn get_list(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_list(r: &mut HttpRequestHandler) -> RequestResult {
let list = admin_account_helper::get_list()? let list = admin_account_helper::get_list()?
.iter() .iter()
.map(AdminInfoAPI::new) .map(AdminInfoAPI::new)
@ -87,7 +87,7 @@ pub fn get_list(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Get current admin information /// Get current admin information
pub fn get_admin_info(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_admin_info(r: &mut HttpRequestHandler) -> RequestResult {
let admin = match r.has_post_parameter("id") { let admin = match r.has_post_parameter("id") {
false => admin_account_helper::find_admin_by_id(r.admin_id()?)?, false => admin_account_helper::find_admin_by_id(r.admin_id()?)?,
true => { true => {
@ -100,7 +100,7 @@ pub fn get_admin_info(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Update general settings /// Update general settings
pub fn update_general_settings(r: &mut HttpRequestHandler) -> RequestResult { pub async fn update_general_settings(r: &mut HttpRequestHandler) -> RequestResult {
let admin_id = r.post_admin_id("id")?; let admin_id = r.post_admin_id("id")?;
let new_name = r.post_string("name")?; let new_name = r.post_string("name")?;
let new_email = r.post_email("email")?; let new_email = r.post_email("email")?;
@ -122,7 +122,7 @@ pub fn update_general_settings(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Generate access reset token /// Generate access reset token
pub fn generate_reset_token(r: &mut HttpRequestHandler) -> RequestResult { pub async fn generate_reset_token(r: &mut HttpRequestHandler) -> RequestResult {
let admin_id = r.post_admin_id("id")?; let admin_id = r.post_admin_id("id")?;
if admin_id != r.admin_id()? { if admin_id != r.admin_id()? {

View File

@ -38,7 +38,7 @@ impl HttpRequestHandler {
} }
/// Get an admin keys /// Get an admin keys
pub fn get_keys_list(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_keys_list(r: &mut HttpRequestHandler) -> RequestResult {
let admin_id = r.post_admin_id("id")?; let admin_id = r.post_admin_id("id")?;
if admin_id != r.admin_id()? { if admin_id != r.admin_id()? {
@ -52,7 +52,7 @@ pub fn get_keys_list(r: &mut HttpRequestHandler) -> RequestResult {
/// Generate a challenge to register a new key /// Generate a challenge to register a new key
pub fn challenge_register_key(r: &mut HttpRequestHandler) -> RequestResult { pub async fn challenge_register_key(r: &mut HttpRequestHandler) -> RequestResult {
let wan = get_wan(); let wan = get_wan();
let (res, state) = wan.generate_challenge_register(&r.admin_id()?.id_str(), false)?; let (res, state) = wan.generate_challenge_register(&r.admin_id()?.id_str(), false)?;
@ -63,7 +63,7 @@ pub fn challenge_register_key(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Register key /// Register key
pub fn register_key(r: &mut HttpRequestHandler) -> RequestResult { pub async fn register_key(r: &mut HttpRequestHandler) -> RequestResult {
let key_name = r.post_string("name")?; let key_name = r.post_string("name")?;
let key_password = r.post_string("password")?; let key_password = r.post_string("password")?;
@ -89,7 +89,7 @@ pub fn register_key(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Delete an admin auth key /// Delete an admin auth key
pub fn delete_auth_key(r: &mut HttpRequestHandler) -> RequestResult { pub async fn delete_auth_key(r: &mut HttpRequestHandler) -> RequestResult {
let admin_id = r.post_admin_id("adminID")?; let admin_id = r.post_admin_id("adminID")?;
let key_id = r.post_u64("keyID")?; let key_id = r.post_u64("keyID")?;
@ -116,7 +116,7 @@ pub fn delete_auth_key(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Generate a challenge to authenticate with a security key /// Generate a challenge to authenticate with a security key
pub fn challenge_auth_with_key(r: &mut HttpRequestHandler) -> RequestResult { pub async fn challenge_auth_with_key(r: &mut HttpRequestHandler) -> RequestResult {
let key = r.post_admin_auth_key("mail", "key_id")?; let key = r.post_admin_auth_key("mail", "key_id")?;
let (challenge_response, auth_state) = let (challenge_response, auth_state) =
@ -128,7 +128,7 @@ pub fn challenge_auth_with_key(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Authenticate a user with a security key /// Authenticate a user with a security key
pub fn auth_with_key(r: &mut HttpRequestHandler) -> RequestResult { pub async fn auth_with_key(r: &mut HttpRequestHandler) -> RequestResult {
let key = r.post_admin_auth_key("mail", "key_id")?; let key = r.post_admin_auth_key("mail", "key_id")?;
let credentials = r.post_auth_public_key_credential("credential")?; let credentials = r.post_auth_public_key_credential("credential")?;

View File

@ -10,7 +10,7 @@ use crate::constants::admin::AdminRole;
use crate::api_data::admin::admin_log_api::AdminLogAPI; use crate::api_data::admin::admin_log_api::AdminLogAPI;
/// Get the list of logs of the user /// Get the list of logs of the user
pub fn get_list(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_list(r: &mut HttpRequestHandler) -> RequestResult {
let logs = match admin_roles_helper::has_role(r.admin_id()?, AdminRole::ACCESS_ALL_ADMINS_LOGS)? { let logs = match admin_roles_helper::has_role(r.admin_id()?, AdminRole::ACCESS_ALL_ADMINS_LOGS)? {
true => admin_log_helper::get_all_admin_logs(), true => admin_log_helper::get_all_admin_logs(),
false => admin_log_helper::get_admin_logs(r.admin_id()?) false => admin_log_helper::get_admin_logs(r.admin_id()?)

View File

@ -12,7 +12,7 @@ use crate::helpers::admin_roles_helper;
use crate::routes::RequestResult; use crate::routes::RequestResult;
/// Get the list of roles embedded in the code /// Get the list of roles embedded in the code
pub fn get_list(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_list(r: &mut HttpRequestHandler) -> RequestResult {
let res = ADMIN_ROLES_LIST.iter() let res = ADMIN_ROLES_LIST.iter()
.map(AdminRoleDetailsAPI::new) .map(AdminRoleDetailsAPI::new)
.collect::<Vec<AdminRoleDetailsAPI>>(); .collect::<Vec<AdminRoleDetailsAPI>>();
@ -21,7 +21,7 @@ pub fn get_list(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Toggle the status of a role for an admin /// Toggle the status of a role for an admin
pub fn toggle(r: &mut HttpRequestHandler) -> RequestResult { pub async fn toggle(r: &mut HttpRequestHandler) -> RequestResult {
let admin_id = r.post_admin_id("adminID")?; let admin_id = r.post_admin_id("adminID")?;
let enable = r.post_bool("enable")?; let enable = r.post_bool("enable")?;
let role_str = r.post_string("role")?; let role_str = r.post_string("role")?;

View File

@ -15,7 +15,7 @@ use crate::helpers::admin_log_helper::log_admin_action;
use crate::routes::RequestResult; use crate::routes::RequestResult;
/// Search for user /// Search for user
pub fn search(r: &mut HttpRequestHandler) -> RequestResult { pub async fn search(r: &mut HttpRequestHandler) -> RequestResult {
r.check_admin_has_role(AdminRole::MANAGE_USERS)?; r.check_admin_has_role(AdminRole::MANAGE_USERS)?;
let name = r.post_string_opt("name", 0, true)?; let name = r.post_string_opt("name", 0, true)?;
@ -27,7 +27,7 @@ pub fn search(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Get information about a single user /// Get information about a single user
pub fn get_single(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_single(r: &mut HttpRequestHandler) -> RequestResult {
r.check_admin_has_role(AdminRole::MANAGE_USERS)?; r.check_admin_has_role(AdminRole::MANAGE_USERS)?;
let user_id = r.post_user_id("user_id")?; let user_id = r.post_user_id("user_id")?;
@ -40,7 +40,7 @@ pub fn get_single(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Change the email address of a Comunic user /// Change the email address of a Comunic user
pub fn change_email_address(r: &mut HttpRequestHandler) -> RequestResult { pub async fn change_email_address(r: &mut HttpRequestHandler) -> RequestResult {
r.check_admin_has_role(AdminRole::MANAGE_USERS)?; r.check_admin_has_role(AdminRole::MANAGE_USERS)?;
let user_id = r.post_user_id("user_id")?; let user_id = r.post_user_id("user_id")?;
@ -67,7 +67,7 @@ pub fn change_email_address(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Create a password reset link for a Comunic user /// Create a password reset link for a Comunic user
pub fn create_password_reset_link(r: &mut HttpRequestHandler) -> RequestResult { pub async fn create_password_reset_link(r: &mut HttpRequestHandler) -> RequestResult {
r.check_admin_has_role(AdminRole::MANAGE_USERS)?; r.check_admin_has_role(AdminRole::MANAGE_USERS)?;
let user_id = r.post_user_id("user_id")?; let user_id = r.post_user_id("user_id")?;

View File

@ -20,7 +20,7 @@ use crate::utils::date_utils::time;
use crate::utils::string_utils::remove_html_nodes; use crate::utils::string_utils::remove_html_nodes;
/// Create a new comment /// Create a new comment
pub fn create(r: &mut HttpRequestHandler) -> RequestResult { pub async fn create(r: &mut HttpRequestHandler) -> RequestResult {
let post = r.post_post_with_access("postID", PostAccessLevel::BASIC_ACCESS)?; let post = r.post_post_with_access("postID", PostAccessLevel::BASIC_ACCESS)?;
if !posts_helper::allow_comments_on_post(&post)? { if !posts_helper::allow_comments_on_post(&post)? {
@ -61,14 +61,14 @@ pub fn create(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Get information about a single comment /// Get information about a single comment
pub fn get_single(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_single(r: &mut HttpRequestHandler) -> RequestResult {
let comment = r.post_comment_with_access("commentID")?; let comment = r.post_comment_with_access("commentID")?;
r.set_response(CommentAPI::new(&comment, &r.user_id_opt())?) r.set_response(CommentAPI::new(&comment, &r.user_id_opt())?)
} }
/// Change a comment's content /// Change a comment's content
pub fn edit(r: &mut HttpRequestHandler) -> RequestResult { pub async fn edit(r: &mut HttpRequestHandler) -> RequestResult {
let comment = r.post_comment_with_full_access("commentID")?; let comment = r.post_comment_with_full_access("commentID")?;
let new_content = r.post_content("content", 2, true)?; let new_content = r.post_content("content", 2, true)?;
@ -78,7 +78,7 @@ pub fn edit(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Delete a comment /// Delete a comment
pub fn delete(r: &mut HttpRequestHandler) -> RequestResult { pub async fn delete(r: &mut HttpRequestHandler) -> RequestResult {
let comment = r.post_comment_with_full_access("commentID")?; let comment = r.post_comment_with_full_access("commentID")?;
comments_helper::delete(&comment)?; comments_helper::delete(&comment)?;

View File

@ -31,7 +31,7 @@ use crate::utils::string_utils::remove_html_nodes;
use crate::utils::user_data_utils::{delete_user_data_file_if_exists, user_data_path}; use crate::utils::user_data_utils::{delete_user_data_file_if_exists, user_data_path};
/// Create a new conversation /// Create a new conversation
pub fn create(r: &mut HttpRequestHandler) -> RequestResult { pub async fn create(r: &mut HttpRequestHandler) -> RequestResult {
let mut members = r.post_users_id("users")?; let mut members = r.post_users_id("users")?;
// Add current user ID if required // Add current user ID if required
@ -55,14 +55,14 @@ pub fn create(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Get the list of conversations of a user /// Get the list of conversations of a user
pub fn get_list(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_list(r: &mut HttpRequestHandler) -> RequestResult {
let list = conversations_helper::get_list_user(&r.user_id()?)?; let list = conversations_helper::get_list_user(&r.user_id()?)?;
r.set_response(list.iter().map(|c| ConversationAPI::new(c)).collect::<Vec<ConversationAPI>>()) r.set_response(list.iter().map(|c| ConversationAPI::new(c)).collect::<Vec<ConversationAPI>>())
} }
/// Get information about a single conversation /// Get information about a single conversation
pub fn get_single(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_single(r: &mut HttpRequestHandler) -> RequestResult {
let conv = r.post_conv("conversationID")?; let conv = r.post_conv("conversationID")?;
let conv = conversations_helper::get_single(conv.conv_id)?; let conv = conversations_helper::get_single(conv.conv_id)?;
@ -70,7 +70,7 @@ pub fn get_single(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Update the settings of a conversation /// Update the settings of a conversation
pub fn update_settings(r: &mut HttpRequestHandler) -> RequestResult { pub async fn update_settings(r: &mut HttpRequestHandler) -> RequestResult {
let conv_membership = r.post_conv("conversationID")?; let conv_membership = r.post_conv("conversationID")?;
// Update following state, if required // Update following state, if required
@ -105,7 +105,7 @@ pub fn update_settings(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Change conversation image /// Change conversation image
pub fn change_image(r: &mut HttpRequestHandler) -> RequestResult { pub async fn change_image(r: &mut HttpRequestHandler) -> RequestResult {
let conv_membership = r.post_conv_admin("convID")?; let conv_membership = r.post_conv_admin("convID")?;
let conv = conversations_helper::get_single(conv_membership.conv_id)?; let conv = conversations_helper::get_single(conv_membership.conv_id)?;
@ -119,7 +119,7 @@ pub fn change_image(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Delete conversation image /// Delete conversation image
pub fn delete_image(r: &mut HttpRequestHandler) -> RequestResult { pub async fn delete_image(r: &mut HttpRequestHandler) -> RequestResult {
let conv_membership = r.post_conv_admin("convID")?; let conv_membership = r.post_conv_admin("convID")?;
let conv = conversations_helper::get_single(conv_membership.conv_id)?; let conv = conversations_helper::get_single(conv_membership.conv_id)?;
@ -129,7 +129,7 @@ pub fn delete_image(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Add a new member to a conversation /// Add a new member to a conversation
pub fn add_member(r: &mut HttpRequestHandler) -> RequestResult { pub async fn add_member(r: &mut HttpRequestHandler) -> RequestResult {
let conv_membership = r.post_conv("convID")?; let conv_membership = r.post_conv("convID")?;
let conv = conversations_helper::get_single(conv_membership.conv_id)?; let conv = conversations_helper::get_single(conv_membership.conv_id)?;
@ -153,7 +153,7 @@ pub fn add_member(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Update admin status of a user /// Update admin status of a user
pub fn set_admin(r: &mut HttpRequestHandler) -> RequestResult { pub async fn set_admin(r: &mut HttpRequestHandler) -> RequestResult {
let conv_membership = r.post_conv_admin("convID")?; let conv_membership = r.post_conv_admin("convID")?;
let conv = conversations_helper::get_single(conv_membership.conv_id)?; let conv = conversations_helper::get_single(conv_membership.conv_id)?;
let user_to_update = r.post_user_id("userID")?; let user_to_update = r.post_user_id("userID")?;
@ -177,7 +177,7 @@ pub fn set_admin(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Remove a member from a conversation /// Remove a member from a conversation
pub fn remove_member(r: &mut HttpRequestHandler) -> RequestResult { pub async fn remove_member(r: &mut HttpRequestHandler) -> RequestResult {
let conv_membership = r.post_conv_admin("convID")?; let conv_membership = r.post_conv_admin("convID")?;
let conv = conversations_helper::get_single(conv_membership.conv_id)?; let conv = conversations_helper::get_single(conv_membership.conv_id)?;
@ -201,7 +201,7 @@ pub fn remove_member(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Find a private conversation /// Find a private conversation
pub fn find_private(r: &mut HttpRequestHandler) -> RequestResult { pub async fn find_private(r: &mut HttpRequestHandler) -> RequestResult {
let other_user = r.post_user_id("otherUser")?; let other_user = r.post_user_id("otherUser")?;
let allow_create = r.post_bool_opt("allowCreate", false); let allow_create = r.post_bool_opt("allowCreate", false);
@ -236,7 +236,7 @@ pub fn find_private(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Refresh a single conversation /// Refresh a single conversation
pub fn refresh_single(r: &mut HttpRequestHandler) -> RequestResult { pub async fn refresh_single(r: &mut HttpRequestHandler) -> RequestResult {
let conv = r.post_conv("conversationID")?; let conv = r.post_conv("conversationID")?;
let last_message_id = r.post_u64("last_message_id")?; let last_message_id = r.post_u64("last_message_id")?;
@ -262,7 +262,7 @@ pub fn refresh_single(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Get older messages of a conversation /// Get older messages of a conversation
pub fn get_older_messages(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_older_messages(r: &mut HttpRequestHandler) -> RequestResult {
let conv = r.post_conv("conversationID")?; let conv = r.post_conv("conversationID")?;
let max_id = r.post_u64("oldest_message_id")? - 1; let max_id = r.post_u64("oldest_message_id")? - 1;
@ -280,7 +280,7 @@ pub fn get_older_messages(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Send a new message /// Send a new message
pub fn send_message(r: &mut HttpRequestHandler) -> RequestResult { pub async fn send_message(r: &mut HttpRequestHandler) -> RequestResult {
let conv = r.post_conv("conversationID")?; let conv = r.post_conv("conversationID")?;
// Get associated file // Get associated file
@ -401,21 +401,21 @@ pub fn send_message(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Count the number of unread conversation of the user /// Count the number of unread conversation of the user
pub fn count_unread(r: &mut HttpRequestHandler) -> RequestResult { pub async fn count_unread(r: &mut HttpRequestHandler) -> RequestResult {
let num = conversations_helper::count_unread_for_user(&r.user_id()?)?; let num = conversations_helper::count_unread_for_user(&r.user_id()?)?;
r.set_response(ResultCountUnreadConversations::new(num)) r.set_response(ResultCountUnreadConversations::new(num))
} }
/// Get the list of unread conversations of a user /// Get the list of unread conversations of a user
pub fn list_unread(r: &mut HttpRequestHandler) -> RequestResult { pub async fn list_unread(r: &mut HttpRequestHandler) -> RequestResult {
let list = conversations_helper::get_list_unread(&r.user_id()?)?; let list = conversations_helper::get_list_unread(&r.user_id()?)?;
r.set_response(UnreadConversationAPI::for_list(&list)?) r.set_response(UnreadConversationAPI::for_list(&list)?)
} }
/// Delete a conversation /// Delete a conversation
pub fn delete_conversation(r: &mut HttpRequestHandler) -> RequestResult { pub async fn delete_conversation(r: &mut HttpRequestHandler) -> RequestResult {
let conv_membership = r.post_conv("conversationID")?; let conv_membership = r.post_conv("conversationID")?;
let conv = conversations_helper::get_single(conv_membership.conv_id)?; let conv = conversations_helper::get_single(conv_membership.conv_id)?;
@ -429,7 +429,7 @@ pub fn delete_conversation(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Update a single conversation message /// Update a single conversation message
pub fn update_message(r: &mut HttpRequestHandler) -> RequestResult { pub async fn update_message(r: &mut HttpRequestHandler) -> RequestResult {
let msg_id = r.post_u64("messageID")?; let msg_id = r.post_u64("messageID")?;
let new_content = r.post_string_opt("content", MIN_CONVERSATION_MESSAGE_LENGTH, true)?; let new_content = r.post_string_opt("content", MIN_CONVERSATION_MESSAGE_LENGTH, true)?;
@ -453,7 +453,7 @@ pub fn update_message(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Delete a conversation message /// Delete a conversation message
pub fn delete_message(r: &mut HttpRequestHandler) -> RequestResult { pub async fn delete_message(r: &mut HttpRequestHandler) -> RequestResult {
let msg_id = r.post_u64("messageID")?; let msg_id = r.post_u64("messageID")?;
if !conversations_helper::is_message_owner(&r.user_id()?, msg_id)? { if !conversations_helper::is_message_owner(&r.user_id()?, msg_id)? {

View File

@ -16,7 +16,7 @@ use crate::helpers::{forez_presence_helper, groups_helper, user_helper};
use crate::routes::RequestResult; use crate::routes::RequestResult;
/// Get the list of declared Forez groups in the application /// Get the list of declared Forez groups in the application
pub fn get_list_groups(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_list_groups(r: &mut HttpRequestHandler) -> RequestResult {
let mut list = vec![]; let mut list = vec![];
for group in &conf().forez_groups { for group in &conf().forez_groups {
@ -27,7 +27,7 @@ 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_member_info(r: &mut HttpRequestHandler) -> RequestResult { pub async 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 member = r.post_user_id("user")?;

View File

@ -11,14 +11,14 @@ use crate::helpers::{friends_helper, notifications_helper, user_helper};
use crate::routes::RequestResult; use crate::routes::RequestResult;
/// Get the list of friends of the current user /// Get the list of friends of the current user
pub fn get_list(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_list(r: &mut HttpRequestHandler) -> RequestResult {
let list = friends_helper::GetFriendsQuery::new(&r.user_id()?).exec()?; let list = friends_helper::GetFriendsQuery::new(&r.user_id()?).exec()?;
r.set_response(FriendAPI::from_list(&list)) r.set_response(FriendAPI::from_list(&list))
} }
/// Get information about a single friendship /// Get information about a single friendship
pub fn get_single_friendship_info(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_single_friendship_info(r: &mut HttpRequestHandler) -> RequestResult {
let friend_id = r.post_user_id("friendID")?; let friend_id = r.post_user_id("friendID")?;
let info = friends_helper::GetFriendsQuery::new(&r.user_id()?) let info = friends_helper::GetFriendsQuery::new(&r.user_id()?)
@ -33,7 +33,7 @@ pub fn get_single_friendship_info(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Get the list of friends of another user /// Get the list of friends of another user
pub fn get_other_user_list(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_other_user_list(r: &mut HttpRequestHandler) -> RequestResult {
let user_id = r.post_user_id("userID")?; let user_id = r.post_user_id("userID")?;
if !user_helper::can_see_user_page(&r.user_id_or_invalid(), &user_id)? { if !user_helper::can_see_user_page(&r.user_id_or_invalid(), &user_id)? {
@ -52,7 +52,7 @@ pub fn get_other_user_list(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Get the status of a friendship /// Get the status of a friendship
pub fn get_status(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_status(r: &mut HttpRequestHandler) -> RequestResult {
let friend_id = r.post_user_id("friendID")?; let friend_id = r.post_user_id("friendID")?;
let curr_user_id = r.user_id()?; let curr_user_id = r.user_id()?;
@ -62,7 +62,7 @@ pub fn get_status(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Send a new friendship request /// Send a new friendship request
pub fn send_request(r: &mut HttpRequestHandler) -> RequestResult { pub async fn send_request(r: &mut HttpRequestHandler) -> RequestResult {
let friend_id = r.post_user_id("friendID")?; let friend_id = r.post_user_id("friendID")?;
if friend_id == r.user_id()? { if friend_id == r.user_id()? {
@ -91,7 +91,7 @@ pub fn send_request(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Cancel a friendship request /// Cancel a friendship request
pub fn cancel_request(r: &mut HttpRequestHandler) -> RequestResult { pub async fn cancel_request(r: &mut HttpRequestHandler) -> RequestResult {
let friend_id = r.post_user_id("friendID")?; let friend_id = r.post_user_id("friendID")?;
if !friends_helper::sent_request(&r.user_id()?, &friend_id)? { if !friends_helper::sent_request(&r.user_id()?, &friend_id)? {
@ -107,7 +107,7 @@ pub fn cancel_request(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Respond to a friendship request /// Respond to a friendship request
pub fn respond_request(r: &mut HttpRequestHandler) -> RequestResult { pub async fn respond_request(r: &mut HttpRequestHandler) -> RequestResult {
let friend_id = r.post_user_id("friendID")?; let friend_id = r.post_user_id("friendID")?;
let accept = r.post_bool("accept")?; let accept = r.post_bool("accept")?;
@ -131,7 +131,7 @@ pub fn respond_request(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Remove a friend from the list /// Remove a friend from the list
pub fn remove_friend(r: &mut HttpRequestHandler) -> RequestResult { pub async fn remove_friend(r: &mut HttpRequestHandler) -> RequestResult {
let friend_id = r.post_friend_id("friendID")?; let friend_id = r.post_friend_id("friendID")?;
friends_helper::remove_friendship(r.user_id_ref()?, &friend_id)?; friends_helper::remove_friendship(r.user_id_ref()?, &friend_id)?;
@ -143,7 +143,7 @@ pub fn remove_friend(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Update following status /// Update following status
pub fn set_following(r: &mut HttpRequestHandler) -> RequestResult { pub async fn set_following(r: &mut HttpRequestHandler) -> RequestResult {
let friend_id = r.post_friend_id("friendID")?; let friend_id = r.post_friend_id("friendID")?;
let follow = r.post_bool("follow")?; let follow = r.post_bool("follow")?;
@ -153,7 +153,7 @@ pub fn set_following(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Update post texts authorization status /// Update post texts authorization status
pub fn set_can_post_texts(r: &mut HttpRequestHandler) -> RequestResult { pub async fn set_can_post_texts(r: &mut HttpRequestHandler) -> RequestResult {
let friend_id = r.post_friend_id("friendID")?; let friend_id = r.post_friend_id("friendID")?;
let allow = r.post_bool("allow")?; let allow = r.post_bool("allow")?;

View File

@ -51,7 +51,7 @@ impl HttpRequestHandler {
} }
/// Create a new group /// Create a new group
pub fn create(r: &mut HttpRequestHandler) -> RequestResult { pub async fn create(r: &mut HttpRequestHandler) -> RequestResult {
let new_group = NewGroup { let new_group = NewGroup {
name: r.post_string_opt("name", 3, true)?, name: r.post_string_opt("name", 3, true)?,
owner_id: r.user_id()?, owner_id: r.user_id()?,
@ -63,7 +63,7 @@ pub fn create(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Get the list of groups of the current user /// Get the list of groups of the current user
pub fn get_list_user(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_list_user(r: &mut HttpRequestHandler) -> RequestResult {
let list = groups_helper::get_list_user(r.user_id_ref()?, false)? let list = groups_helper::get_list_user(r.user_id_ref()?, false)?
.iter() .iter()
.map(|f| f.id()) .map(|f| f.id())
@ -73,7 +73,7 @@ pub fn get_list_user(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Get information about a single group /// Get information about a single group
pub fn get_info_single(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_info_single(r: &mut HttpRequestHandler) -> RequestResult {
let group_id = r.post_group_id_with_access("id", GroupAccessLevel::LIMITED_ACCESS)?; let group_id = r.post_group_id_with_access("id", GroupAccessLevel::LIMITED_ACCESS)?;
let group = groups_helper::get_info(&group_id)?; let group = groups_helper::get_info(&group_id)?;
@ -81,7 +81,7 @@ pub fn get_info_single(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Get information about multiple users /// Get information about multiple users
pub fn get_info_multiple(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_info_multiple(r: &mut HttpRequestHandler) -> RequestResult {
let groups_id = r.post_numbers_list("list", 1)?; let groups_id = r.post_numbers_list("list", 1)?;
let mut list = HashMap::new(); let mut list = HashMap::new();
@ -103,7 +103,7 @@ pub fn get_info_multiple(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Get advanced information about a user /// Get advanced information about a user
pub fn get_advanced_info(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_advanced_info(r: &mut HttpRequestHandler) -> RequestResult {
let group_id = r.post_group_id_with_access("id", GroupAccessLevel::VIEW_ACCESS)?; let group_id = r.post_group_id_with_access("id", GroupAccessLevel::VIEW_ACCESS)?;
let group = groups_helper::get_info(&group_id)?; let group = groups_helper::get_info(&group_id)?;
@ -111,7 +111,7 @@ pub fn get_advanced_info(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Get the settings of the group /// Get the settings of the group
pub fn get_settings(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_settings(r: &mut HttpRequestHandler) -> RequestResult {
let group_id = r.post_group_id_with_access("id", GroupAccessLevel::ADMIN_ACCESS)?; let group_id = r.post_group_id_with_access("id", GroupAccessLevel::ADMIN_ACCESS)?;
let group = groups_helper::get_info(&group_id)?; let group = groups_helper::get_info(&group_id)?;
@ -121,7 +121,7 @@ pub fn get_settings(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Set new settings to the group /// Set new settings to the group
pub fn set_settings(r: &mut HttpRequestHandler) -> RequestResult { pub async fn set_settings(r: &mut HttpRequestHandler) -> RequestResult {
let group_id = r.post_group_id_with_access("id", GroupAccessLevel::ADMIN_ACCESS)?; let group_id = r.post_group_id_with_access("id", GroupAccessLevel::ADMIN_ACCESS)?;
let new_settings = Group { let new_settings = Group {
@ -144,7 +144,7 @@ pub fn set_settings(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Check out whether a virtual directory is available for a group or not /// Check out whether a virtual directory is available for a group or not
pub fn check_virtual_dir(r: &mut HttpRequestHandler) -> RequestResult { pub async fn check_virtual_dir(r: &mut HttpRequestHandler) -> RequestResult {
let group_id = r.post_group_id_with_access("groupID", GroupAccessLevel::ADMIN_ACCESS)?; let group_id = r.post_group_id_with_access("groupID", GroupAccessLevel::ADMIN_ACCESS)?;
let dir = r.post_virtual_directory("directory")?; let dir = r.post_virtual_directory("directory")?;
@ -156,7 +156,7 @@ pub fn check_virtual_dir(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Change a group's logo /// Change a group's logo
pub fn upload_logo(r: &mut HttpRequestHandler) -> RequestResult { pub async fn upload_logo(r: &mut HttpRequestHandler) -> RequestResult {
let group_id = r.post_group_id_with_access("id", GroupAccessLevel::ADMIN_ACCESS)?; let group_id = r.post_group_id_with_access("id", GroupAccessLevel::ADMIN_ACCESS)?;
if !r.has_file("logo") { if !r.has_file("logo") {
@ -173,7 +173,7 @@ pub fn upload_logo(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Delete a group's logo /// Delete a group's logo
pub fn delete_logo(r: &mut HttpRequestHandler) -> RequestResult { pub async fn delete_logo(r: &mut HttpRequestHandler) -> RequestResult {
let group_id = r.post_group_id_with_access("id", GroupAccessLevel::ADMIN_ACCESS)?; let group_id = r.post_group_id_with_access("id", GroupAccessLevel::ADMIN_ACCESS)?;
groups_helper::delete_logo(&group_id)?; groups_helper::delete_logo(&group_id)?;
@ -182,7 +182,7 @@ pub fn delete_logo(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Create a new group's conversation /// Create a new group's conversation
pub fn create_conversation(r: &mut HttpRequestHandler) -> RequestResult { pub async fn create_conversation(r: &mut HttpRequestHandler) -> RequestResult {
let group = r.post_group_id_with_access("group_id", GroupAccessLevel::ADMIN_ACCESS)?; let group = r.post_group_id_with_access("group_id", GroupAccessLevel::ADMIN_ACCESS)?;
let min_membership_level = r.post_group_membership_level_for_conversation("min_membership_level")?; let min_membership_level = r.post_group_membership_level_for_conversation("min_membership_level")?;
let name = r.post_string("name")?; let name = r.post_string("name")?;
@ -193,7 +193,7 @@ pub fn create_conversation(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Update a group's conversation visibility /// Update a group's conversation visibility
pub fn set_conversation_visibility(r: &mut HttpRequestHandler) -> RequestResult { pub async fn set_conversation_visibility(r: &mut HttpRequestHandler) -> RequestResult {
let conv = r.post_group_conv_admin("conv_id")?; let conv = r.post_group_conv_admin("conv_id")?;
let min_level = r.post_group_membership_level_for_conversation("min_membership_level")?; let min_level = r.post_group_membership_level_for_conversation("min_membership_level")?;
@ -203,7 +203,7 @@ pub fn set_conversation_visibility(r: &mut HttpRequestHandler) -> RequestResult
} }
/// Delete a group's conversation /// Delete a group's conversation
pub fn delete_conversation(r: &mut HttpRequestHandler) -> RequestResult { pub async fn delete_conversation(r: &mut HttpRequestHandler) -> RequestResult {
let conv = r.post_group_conv_admin("conv_id")?; let conv = r.post_group_conv_admin("conv_id")?;
conversations_helper::delete_conversation(&conv)?; conversations_helper::delete_conversation(&conv)?;
@ -212,7 +212,7 @@ pub fn delete_conversation(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Get the list of members of a group /// Get the list of members of a group
pub fn get_members(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_members(r: &mut HttpRequestHandler) -> RequestResult {
let group_id = r.post_group_id("id")?; let group_id = r.post_group_id("id")?;
let group_access_level = groups_helper::get_access_level(&group_id, r.user_id_opt())?; let group_access_level = groups_helper::get_access_level(&group_id, r.user_id_opt())?;
let group = groups_helper::get_info(&group_id)?; let group = groups_helper::get_info(&group_id)?;
@ -228,7 +228,7 @@ pub fn get_members(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Cancel an invitation sent to a user /// Cancel an invitation sent to a user
pub fn cancel_invitation(r: &mut HttpRequestHandler) -> RequestResult { pub async fn cancel_invitation(r: &mut HttpRequestHandler) -> RequestResult {
let group_id = r.post_group_id_with_access("groupID", GroupAccessLevel::MODERATOR_ACCESS)?; let group_id = r.post_group_id_with_access("groupID", GroupAccessLevel::MODERATOR_ACCESS)?;
let user_id = r.post_user_id("userID")?; let user_id = r.post_user_id("userID")?;
@ -245,7 +245,7 @@ pub fn cancel_invitation(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Invite a user to join a group /// Invite a user to join a group
pub fn invite_user(r: &mut HttpRequestHandler) -> RequestResult { pub async fn invite_user(r: &mut HttpRequestHandler) -> RequestResult {
let group_id = r.post_group_id_with_access("group_id", GroupAccessLevel::MODERATOR_ACCESS)?; let group_id = r.post_group_id_with_access("group_id", GroupAccessLevel::MODERATOR_ACCESS)?;
let user_id = r.post_user_id("userID")?; let user_id = r.post_user_id("userID")?;
@ -263,7 +263,7 @@ pub fn invite_user(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Respond to a user invitation /// Respond to a user invitation
pub fn respond_invitation(r: &mut HttpRequestHandler) -> RequestResult { pub async fn respond_invitation(r: &mut HttpRequestHandler) -> RequestResult {
let group_id = r.post_group_id_with_access("id", GroupAccessLevel::LIMITED_ACCESS)?; let group_id = r.post_group_id_with_access("id", GroupAccessLevel::LIMITED_ACCESS)?;
let accept = r.post_bool("accept")?; let accept = r.post_bool("accept")?;
@ -287,7 +287,7 @@ pub fn respond_invitation(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Send a request to join a group /// Send a request to join a group
pub fn send_request(r: &mut HttpRequestHandler) -> RequestResult { pub async fn send_request(r: &mut HttpRequestHandler) -> RequestResult {
let group_id = r.post_group_id_with_access("id", GroupAccessLevel::LIMITED_ACCESS)?; let group_id = r.post_group_id_with_access("id", GroupAccessLevel::LIMITED_ACCESS)?;
if groups_helper::get_membership_level(&group_id, r.user_id_opt())? != GroupMembershipLevel::VISITOR { if groups_helper::get_membership_level(&group_id, r.user_id_opt())? != GroupMembershipLevel::VISITOR {
@ -325,7 +325,7 @@ pub fn send_request(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Cancel a group membership request /// Cancel a group membership request
pub fn cancel_request(r: &mut HttpRequestHandler) -> RequestResult { pub async fn cancel_request(r: &mut HttpRequestHandler) -> RequestResult {
let group_id = r.post_group_id_with_access("id", GroupAccessLevel::LIMITED_ACCESS)?; let group_id = r.post_group_id_with_access("id", GroupAccessLevel::LIMITED_ACCESS)?;
if groups_helper::get_membership_level(&group_id, r.user_id_opt())? != GroupMembershipLevel::PENDING { if groups_helper::get_membership_level(&group_id, r.user_id_opt())? != GroupMembershipLevel::PENDING {
@ -341,7 +341,7 @@ pub fn cancel_request(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Remove a member from a group (as a moderator or an admin) /// Remove a member from a group (as a moderator or an admin)
pub fn delete_member(r: &mut HttpRequestHandler) -> RequestResult { pub async fn delete_member(r: &mut HttpRequestHandler) -> RequestResult {
let group_id = r.post_group_id_with_access("groupID", GroupAccessLevel::MODERATOR_ACCESS)?; let group_id = r.post_group_id_with_access("groupID", GroupAccessLevel::MODERATOR_ACCESS)?;
// Get the membership of the user making the request // Get the membership of the user making the request
@ -369,7 +369,7 @@ pub fn delete_member(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Update a user's membership /// Update a user's membership
pub fn update_membership(r: &mut HttpRequestHandler) -> RequestResult { pub async fn update_membership(r: &mut HttpRequestHandler) -> RequestResult {
let group_id = r.post_group_id_with_access("groupID", GroupAccessLevel::ADMIN_ACCESS)?; let group_id = r.post_group_id_with_access("groupID", GroupAccessLevel::ADMIN_ACCESS)?;
let user_id = r.post_user_id("userID")?; let user_id = r.post_user_id("userID")?;
@ -395,7 +395,7 @@ pub fn update_membership(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Respond to a group membership request /// Respond to a group membership request
pub fn respond_request(r: &mut HttpRequestHandler) -> RequestResult { pub async fn respond_request(r: &mut HttpRequestHandler) -> RequestResult {
let group_id = r.post_group_id_with_access("groupID", GroupAccessLevel::MODERATOR_ACCESS)?; let group_id = r.post_group_id_with_access("groupID", GroupAccessLevel::MODERATOR_ACCESS)?;
let user_id = r.post_user_id("userID")?; let user_id = r.post_user_id("userID")?;
let accept = r.post_bool("accept")?; let accept = r.post_bool("accept")?;
@ -416,7 +416,7 @@ pub fn respond_request(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Get information about a single user membership over a group /// Get information about a single user membership over a group
pub fn get_membership(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_membership(r: &mut HttpRequestHandler) -> RequestResult {
let group_id = r.post_group_id_with_access("groupID", GroupAccessLevel::MODERATOR_ACCESS)?; let group_id = r.post_group_id_with_access("groupID", GroupAccessLevel::MODERATOR_ACCESS)?;
let user_id = r.post_user_id("userID")?; let user_id = r.post_user_id("userID")?;
@ -426,7 +426,7 @@ pub fn get_membership(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Delete the membership of a user over a group /// Delete the membership of a user over a group
pub fn remove_membership(r: &mut HttpRequestHandler) -> RequestResult { pub async fn remove_membership(r: &mut HttpRequestHandler) -> RequestResult {
let group_id = r.post_group_id_with_access("id", GroupAccessLevel::LIMITED_ACCESS)?; let group_id = r.post_group_id_with_access("id", GroupAccessLevel::LIMITED_ACCESS)?;
if groups_helper::is_last_admin(&group_id, &r.user_id()?)? { if groups_helper::is_last_admin(&group_id, &r.user_id()?)? {
@ -442,7 +442,7 @@ pub fn remove_membership(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Update following status over a group /// Update following status over a group
pub fn set_following(r: &mut HttpRequestHandler) -> RequestResult { pub async fn set_following(r: &mut HttpRequestHandler) -> RequestResult {
let group_id = r.post_group_id_with_access("groupID", GroupAccessLevel::MEMBER_ACCESS)?; let group_id = r.post_group_id_with_access("groupID", GroupAccessLevel::MEMBER_ACCESS)?;
let following = r.post_bool("follow")?; let following = r.post_bool("follow")?;
@ -452,7 +452,7 @@ pub fn set_following(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Delete a group /// Delete a group
pub fn delete_group(r: &mut HttpRequestHandler) -> RequestResult { pub async fn delete_group(r: &mut HttpRequestHandler) -> RequestResult {
let group_id = r.post_group_id_with_access("groupID", GroupAccessLevel::ADMIN_ACCESS)?; let group_id = r.post_group_id_with_access("groupID", GroupAccessLevel::ADMIN_ACCESS)?;
r.need_user_password("password")?; r.need_user_password("password")?;

View File

@ -12,6 +12,11 @@ use crate::helpers::likes_helper::LikeType;
struct LikeTarget(u64, LikeType); struct LikeTarget(u64, LikeType);
/// Update like status (async version)
pub async fn update_async<H: BaseRequestHandler>(r: &mut H) -> RequestResult {
update(r)
}
/// Update like status /// Update like status
pub fn update<H: BaseRequestHandler>(r: &mut H) -> RequestResult { pub fn update<H: BaseRequestHandler>(r: &mut H) -> RequestResult {
let req_type = r.post_string("type")?; let req_type = r.post_string("type")?;

View File

@ -35,13 +35,13 @@ impl HttpRequestHandler {
} }
/// Count the number of unread notifications /// Count the number of unread notifications
pub fn count_unread(r: &mut HttpRequestHandler) -> RequestResult { pub async fn count_unread(r: &mut HttpRequestHandler) -> RequestResult {
let number = notifications_helper::count_unread(r.user_id_ref()?)?; let number = notifications_helper::count_unread(r.user_id_ref()?)?;
r.set_response(ResNumberUnreadNotifications::new(number)) r.set_response(ResNumberUnreadNotifications::new(number))
} }
/// Count the number of unread notifications /// Count the number of unread notifications
pub fn count_all_news(r: &mut HttpRequestHandler) -> RequestResult { pub async fn count_all_news(r: &mut HttpRequestHandler) -> RequestResult {
let notifications = notifications_helper::count_unread(r.user_id_ref()?)?; let notifications = notifications_helper::count_unread(r.user_id_ref()?)?;
let conversations = conversations_helper::count_unread_for_user(r.user_id_ref()?)?; let conversations = conversations_helper::count_unread_for_user(r.user_id_ref()?)?;
let friends_requests = match r.post_bool_opt("friends_request", false) { let friends_requests = match r.post_bool_opt("friends_request", false) {
@ -53,14 +53,14 @@ pub fn count_all_news(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Get the list of unread notifications /// Get the list of unread notifications
pub fn get_list_unread(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_list_unread(r: &mut HttpRequestHandler) -> RequestResult {
let list = notifications_helper::get_list_unread(r.user_id_ref()?)?; let list = notifications_helper::get_list_unread(r.user_id_ref()?)?;
r.set_response(NotificationAPI::for_list(&list)) r.set_response(NotificationAPI::for_list(&list))
} }
/// Mark a notification as seen /// Mark a notification as seen
pub fn mark_seen(r: &mut HttpRequestHandler) -> RequestResult { pub async fn mark_seen(r: &mut HttpRequestHandler) -> RequestResult {
let notif = r.post_notif_id("notifID")?; let notif = r.post_notif_id("notifID")?;
let delete_similar = r.post_bool_opt("delete_similar", false); let delete_similar = r.post_bool_opt("delete_similar", false);
@ -79,7 +79,7 @@ pub fn mark_seen(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Delete all the notifications of the current user /// Delete all the notifications of the current user
pub fn delete_all(r: &mut HttpRequestHandler) -> RequestResult { pub async fn delete_all(r: &mut HttpRequestHandler) -> RequestResult {
notifications_helper::delete_all_user(r.user_id_ref()?)?; notifications_helper::delete_all_user(r.user_id_ref()?)?;
r.success("Notifications deleted.") r.success("Notifications deleted.")

View File

@ -35,7 +35,7 @@ impl PostFile {
} }
/// Get the list of posts of a user /// Get the list of posts of a user
pub fn get_list_user(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_list_user(r: &mut HttpRequestHandler) -> RequestResult {
let user_id = r.post_user_id("userID")?; let user_id = r.post_user_id("userID")?;
let start_from = r.post_u64_opt("startFrom", 0)?; let start_from = r.post_u64_opt("startFrom", 0)?;
@ -51,7 +51,7 @@ pub fn get_list_user(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Get the list of posts of a group /// Get the list of posts of a group
pub fn get_list_group(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_list_group(r: &mut HttpRequestHandler) -> RequestResult {
let group_id = r.post_group_id_with_access("groupID", GroupAccessLevel::VIEW_ACCESS)?; let group_id = r.post_group_id_with_access("groupID", GroupAccessLevel::VIEW_ACCESS)?;
let start_from = r.post_u64_opt("startFrom", 0)?; let start_from = r.post_u64_opt("startFrom", 0)?;
@ -63,7 +63,7 @@ pub fn get_list_group(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Get the latest posts of a group /// Get the latest posts of a group
pub fn get_latest(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_latest(r: &mut HttpRequestHandler) -> RequestResult {
let start_from = r.post_u64_opt("startFrom", 0)?; let start_from = r.post_u64_opt("startFrom", 0)?;
let include_groups = r.post_bool_opt("include_groups", false); let include_groups = r.post_bool_opt("include_groups", false);
@ -75,14 +75,14 @@ pub fn get_latest(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Get information about a single post /// Get information about a single post
pub fn get_single(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_single(r: &mut HttpRequestHandler) -> RequestResult {
let post = r.post_post_with_access("postID", PostAccessLevel::BASIC_ACCESS)?; let post = r.post_post_with_access("postID", PostAccessLevel::BASIC_ACCESS)?;
r.set_response(PostAPI::new(&post, &r.user_id_opt())?) r.set_response(PostAPI::new(&post, &r.user_id_opt())?)
} }
/// Create a new post /// Create a new post
pub fn create_post(r: &mut HttpRequestHandler) -> RequestResult { pub async fn create_post(r: &mut HttpRequestHandler) -> RequestResult {
// Process page target // Process page target
let target_page = match r.post_string("kind-page")?.as_str() { let target_page = match r.post_string("kind-page")?.as_str() {
"user" => { "user" => {
@ -241,7 +241,7 @@ pub fn create_post(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Change the visibility level of a post /// Change the visibility level of a post
pub fn set_visibility_level(r: &mut HttpRequestHandler) -> RequestResult { pub async fn set_visibility_level(r: &mut HttpRequestHandler) -> RequestResult {
let post = r.post_post_with_access("postID", PostAccessLevel::FULL_ACCESS)?; let post = r.post_post_with_access("postID", PostAccessLevel::FULL_ACCESS)?;
let new_visibility = PostVisibilityLevel::from_api(&r.post_string("new_level")?); let new_visibility = PostVisibilityLevel::from_api(&r.post_string("new_level")?);
@ -256,7 +256,7 @@ pub fn set_visibility_level(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Update the content of a post /// Update the content of a post
pub fn update_content(r: &mut HttpRequestHandler) -> RequestResult { pub async fn update_content(r: &mut HttpRequestHandler) -> RequestResult {
let post = r.post_post_with_access("postID", PostAccessLevel::FULL_ACCESS)?; let post = r.post_post_with_access("postID", PostAccessLevel::FULL_ACCESS)?;
let new_content = r.post_content("new_content", 2, true)?; let new_content = r.post_content("new_content", 2, true)?;
@ -269,7 +269,7 @@ pub fn update_content(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Delete a post /// Delete a post
pub fn delete(r: &mut HttpRequestHandler) -> RequestResult { pub async fn delete(r: &mut HttpRequestHandler) -> RequestResult {
let post = r.post_post_with_access("postID", PostAccessLevel::FULL_ACCESS)?; let post = r.post_post_with_access("postID", PostAccessLevel::FULL_ACCESS)?;
posts_helper::delete(&post)?; posts_helper::delete(&post)?;
@ -278,7 +278,7 @@ pub fn delete(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Get the list of targets where the current user can create posts /// Get the list of targets where the current user can create posts
pub fn get_targets(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_targets(r: &mut HttpRequestHandler) -> RequestResult {
let friends = friends_helper::get_list_that_allow_posts_from_user(r.user_id_ref()?)?; let friends = friends_helper::get_list_that_allow_posts_from_user(r.user_id_ref()?)?;
let groups = groups_helper::get_list_where_user_can_create_posts(r.user_id_ref()?)?; let groups = groups_helper::get_list_where_user_can_create_posts(r.user_id_ref()?)?;

View File

@ -11,14 +11,14 @@ use crate::helpers::{account_helper, independent_push_notifications_service_help
use crate::routes::RequestResult; use crate::routes::RequestResult;
/// Get current push notifications status for a connection /// Get current push notifications status for a connection
pub fn get_status(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_status(r: &mut HttpRequestHandler) -> RequestResult {
let status = &r.user_access_token().unwrap().push_notifications_token.clone(); let status = &r.user_access_token().unwrap().push_notifications_token.clone();
r.set_response(PushNotificationsStatusAPI::new(status)) r.set_response(PushNotificationsStatusAPI::new(status))
} }
/// Configure push notifications for a client /// Configure push notifications for a client
pub fn configure(r: &mut HttpRequestHandler) -> RequestResult { pub async fn configure(r: &mut HttpRequestHandler) -> RequestResult {
let status = r.post_string("status")?; let status = r.post_string("status")?;
let status = match status.as_str() { let status = match status.as_str() {

View File

@ -10,7 +10,7 @@ use crate::data::http_request_handler::HttpRequestHandler;
use crate::helpers::{groups_helper, user_helper}; use crate::helpers::{groups_helper, user_helper};
/// Search for user /// Search for user
pub fn search_user(r: &mut HttpRequestHandler) -> RequestResult { pub async fn search_user(r: &mut HttpRequestHandler) -> RequestResult {
let query = r.post_string_opt("query", 1, true)?; let query = r.post_string_opt("query", 1, true)?;
let limit = r.post_u64_opt("searchLimit", 5)?; let limit = r.post_u64_opt("searchLimit", 5)?;
@ -23,7 +23,7 @@ pub fn search_user(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Perform a global search /// Perform a global search
pub fn search_global(r: &mut HttpRequestHandler) -> RequestResult { pub async fn search_global(r: &mut HttpRequestHandler) -> RequestResult {
let query = r.post_string("query")?; let query = r.post_string("query")?;
let limit = 10; let limit = 10;

View File

@ -8,11 +8,11 @@ use crate::routes::RequestResult;
/// @author Pierre Hubert /// @author Pierre Hubert
/// Root server index /// Root server index
pub fn main_index(request: &mut HttpRequestHandler) -> RequestResult { pub async fn main_index(request: &mut HttpRequestHandler) -> RequestResult {
request.success("Comunic API server V3. (c) Pierre Hubert 2020") request.success("Comunic API server V3. (c) Pierre Hubert 2020")
} }
/// Get server configuration /// Get server configuration
pub fn get_config(request: &mut HttpRequestHandler) -> RequestResult { pub async fn get_config(request: &mut HttpRequestHandler) -> RequestResult {
request.set_response(ServerConfig::new(request.api_client())) request.set_response(ServerConfig::new(request.api_client()))
} }

View File

@ -26,14 +26,14 @@ use crate::routes::RequestResult;
use crate::utils::string_utils::remove_html_nodes; use crate::utils::string_utils::remove_html_nodes;
/// Get the general settings of the user /// Get the general settings of the user
pub fn get_general(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_general(r: &mut HttpRequestHandler) -> RequestResult {
let user = user_helper::find_user_by_id(r.user_id_ref()?)?; let user = user_helper::find_user_by_id(r.user_id_ref()?)?;
r.set_response(GeneralSettingsAPI::new(&user)) r.set_response(GeneralSettingsAPI::new(&user))
} }
/// Set the general settings of the user /// Set the general settings of the user
pub fn set_general(r: &mut HttpRequestHandler) -> RequestResult { pub async fn set_general(r: &mut HttpRequestHandler) -> RequestResult {
let page_status = match (r.post_bool("isPublic")?, r.post_bool("isOpen")?) { let page_status = match (r.post_bool("isPublic")?, r.post_bool("isOpen")?) {
(true, true) => UserPageVisibility::OPEN, (true, true) => UserPageVisibility::OPEN,
(true, false) => UserPageVisibility::PUBLIC, (true, false) => UserPageVisibility::PUBLIC,
@ -67,7 +67,7 @@ pub fn set_general(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Check the availability of a virtual directory /// Check the availability of a virtual directory
pub fn check_virtual_directory(r: &mut HttpRequestHandler) -> RequestResult { pub async fn check_virtual_directory(r: &mut HttpRequestHandler) -> RequestResult {
// We can do this check just by getting it, there is no need to store it in a variable // We can do this check just by getting it, there is no need to store it in a variable
r.post_checked_virtual_directory_opt("directory", r.user_id()?.id(), VirtualDirType::USER)?; r.post_checked_virtual_directory_opt("directory", r.user_id()?.id(), VirtualDirType::USER)?;
@ -75,14 +75,14 @@ pub fn check_virtual_directory(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Get the current language of the user /// Get the current language of the user
pub fn get_language(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_language(r: &mut HttpRequestHandler) -> RequestResult {
let user = user_helper::find_user_by_id(r.user_id_ref()?)?; let user = user_helper::find_user_by_id(r.user_id_ref()?)?;
r.set_response(LanguageSettingsAPI::new(&user)) r.set_response(LanguageSettingsAPI::new(&user))
} }
/// Set the current language of the user /// Set the current language of the user
pub fn set_language(r: &mut HttpRequestHandler) -> RequestResult { pub async fn set_language(r: &mut HttpRequestHandler) -> RequestResult {
let lang = r.post_string("lang")?; let lang = r.post_string("lang")?;
if !SUPPORTED_LANGUAGES.contains(&lang.as_str()) { if !SUPPORTED_LANGUAGES.contains(&lang.as_str()) {
@ -100,7 +100,7 @@ pub fn set_language(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Get security settings /// Get security settings
pub fn get_security(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_security(r: &mut HttpRequestHandler) -> RequestResult {
r.need_user_password("password")?; r.need_user_password("password")?;
let user = user_helper::find_user_by_id(r.user_id_ref()?)?; let user = user_helper::find_user_by_id(r.user_id_ref()?)?;
@ -109,7 +109,7 @@ pub fn get_security(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Set security settings /// Set security settings
pub fn set_security(r: &mut HttpRequestHandler) -> RequestResult { pub async fn set_security(r: &mut HttpRequestHandler) -> RequestResult {
r.need_user_password("password")?; r.need_user_password("password")?;
let new_settings = SecuritySettings { let new_settings = SecuritySettings {
@ -131,14 +131,14 @@ pub fn set_security(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Check user password /// Check user password
pub fn check_password(r: &mut HttpRequestHandler) -> RequestResult { pub async fn check_password(r: &mut HttpRequestHandler) -> RequestResult {
r.need_user_password("password")?; r.need_user_password("password")?;
r.success("The password is valid.") r.success("The password is valid.")
} }
/// Update user password /// Update user password
pub fn update_password(r: &mut HttpRequestHandler) -> RequestResult { pub async fn update_password(r: &mut HttpRequestHandler) -> RequestResult {
r.need_user_password("oldPassword")?; r.need_user_password("oldPassword")?;
let new_password = r.post_string("newPassword")?; let new_password = r.post_string("newPassword")?;
@ -149,14 +149,14 @@ pub fn update_password(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Get account image settings /// Get account image settings
pub fn get_account_image_settings(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_account_image_settings(r: &mut HttpRequestHandler) -> RequestResult {
let user = user_helper::find_user_by_id(r.user_id_ref()?)?; let user = user_helper::find_user_by_id(r.user_id_ref()?)?;
r.set_response(AccountImageSettingsAPI::new(&user)) r.set_response(AccountImageSettingsAPI::new(&user))
} }
/// Upload a new account image /// Upload a new account image
pub fn upload_account_image(r: &mut HttpRequestHandler) -> RequestResult { pub async fn upload_account_image(r: &mut HttpRequestHandler) -> RequestResult {
if !r.has_file("picture") { if !r.has_file("picture") {
return r.bad_request("An error occurred while receiving the image !".to_string()); return r.bad_request("An error occurred while receiving the image !".to_string());
} }
@ -169,14 +169,14 @@ pub fn upload_account_image(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Delete user account image /// Delete user account image
pub fn delete_account_image(r: &mut HttpRequestHandler) -> RequestResult { pub async fn delete_account_image(r: &mut HttpRequestHandler) -> RequestResult {
account_helper::delete_account_image(r.user_id_ref()?)?; account_helper::delete_account_image(r.user_id_ref()?)?;
r.success("Account image deleted!") r.success("Account image deleted!")
} }
/// Change account image visibility /// Change account image visibility
pub fn set_account_image_visibility(r: &mut HttpRequestHandler) -> RequestResult { pub async fn set_account_image_visibility(r: &mut HttpRequestHandler) -> RequestResult {
let level = AccountImageVisibility::from_api(&r.post_string("visibility")?); let level = AccountImageVisibility::from_api(&r.post_string("visibility")?);
account_helper::set_account_image_visibility(r.user_id_ref()?, level)?; account_helper::set_account_image_visibility(r.user_id_ref()?, level)?;
@ -185,7 +185,7 @@ pub fn set_account_image_visibility(r: &mut HttpRequestHandler) -> RequestResult
} }
/// Upload a custom emoji /// Upload a custom emoji
pub fn upload_custom_emoji(r: &mut HttpRequestHandler) -> RequestResult { pub async fn upload_custom_emoji(r: &mut HttpRequestHandler) -> RequestResult {
let shortcut = r.post_emoji_shortcut("shortcut")?; let shortcut = r.post_emoji_shortcut("shortcut")?;
if custom_emojies_helper::has_user_similar_shortcut(r.user_id_ref()?, &shortcut)? { if custom_emojies_helper::has_user_similar_shortcut(r.user_id_ref()?, &shortcut)? {
@ -204,7 +204,7 @@ pub fn upload_custom_emoji(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Delete custom emoji /// Delete custom emoji
pub fn delete_custom_emoji(r: &mut HttpRequestHandler) -> RequestResult { pub async fn delete_custom_emoji(r: &mut HttpRequestHandler) -> RequestResult {
let emoji = r.post_emoji_id("emojiID")?; let emoji = r.post_emoji_id("emojiID")?;
custom_emojies_helper::delete(&emoji)?; custom_emojies_helper::delete(&emoji)?;
@ -213,14 +213,14 @@ pub fn delete_custom_emoji(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Get data conservation policy /// Get data conservation policy
pub fn get_data_conservation_policy(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_data_conservation_policy(r: &mut HttpRequestHandler) -> RequestResult {
let user = user_helper::find_user_by_id(r.user_id_ref()?)?; let user = user_helper::find_user_by_id(r.user_id_ref()?)?;
r.set_response(DataConservationSettingsAPI::new(&user)) r.set_response(DataConservationSettingsAPI::new(&user))
} }
/// Set data conservation policy /// Set data conservation policy
pub fn set_data_conservation_policy(r: &mut HttpRequestHandler) -> RequestResult { pub async fn set_data_conservation_policy(r: &mut HttpRequestHandler) -> RequestResult {
r.need_user_password("password")?; r.need_user_password("password")?;
let policy = NewDataConservationPolicy { let policy = NewDataConservationPolicy {
@ -265,14 +265,14 @@ pub fn set_data_conservation_policy(r: &mut HttpRequestHandler) -> RequestResult
} }
/// Get notifications settings /// Get notifications settings
pub fn get_notifications(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_notifications(r: &mut HttpRequestHandler) -> RequestResult {
let user = user_helper::find_user_by_id(r.user_id_ref()?)?; let user = user_helper::find_user_by_id(r.user_id_ref()?)?;
r.set_response(NotificationSettingsAPI::new(&user)) r.set_response(NotificationSettingsAPI::new(&user))
} }
/// Set (update) notifications settings /// Set (update) notifications settings
pub fn set_notifications(r: &mut HttpRequestHandler) -> RequestResult { pub async fn set_notifications(r: &mut HttpRequestHandler) -> RequestResult {
account_helper::set_notifications_settings(NewNotificationsSettings { account_helper::set_notifications_settings(NewNotificationsSettings {
user_id: r.user_id()?, user_id: r.user_id()?,
allow_notifications_sound: r.post_bool("allow_notifications_sound")?, allow_notifications_sound: r.post_bool("allow_notifications_sound")?,

View File

@ -20,7 +20,7 @@ impl HttpRequestHandler {
} }
/// Get information about a single survey /// Get information about a single survey
pub fn get_info_single(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_info_single(r: &mut HttpRequestHandler) -> RequestResult {
let post = r.post_post_with_access("postID", PostAccessLevel::BASIC_ACCESS)?; let post = r.post_post_with_access("postID", PostAccessLevel::BASIC_ACCESS)?;
let survey = r.ok_or_not_found( let survey = r.ok_or_not_found(
survey_helper::get_info(post.id), survey_helper::get_info(post.id),
@ -31,7 +31,7 @@ pub fn get_info_single(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Respond to a survey /// Respond to a survey
pub fn send_response(r: &mut HttpRequestHandler) -> RequestResult { pub async fn send_response(r: &mut HttpRequestHandler) -> RequestResult {
let survey_id = r.post_survey_id_from_post_id("postID", PostAccessLevel::BASIC_ACCESS)?; let survey_id = r.post_survey_id_from_post_id("postID", PostAccessLevel::BASIC_ACCESS)?;
let choice_id = r.post_u64("choiceID")?; let choice_id = r.post_u64("choiceID")?;
@ -47,7 +47,7 @@ pub fn send_response(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Cancel a response to a survey /// Cancel a response to a survey
pub fn cancel_response(r: &mut HttpRequestHandler) -> RequestResult { pub async fn cancel_response(r: &mut HttpRequestHandler) -> RequestResult {
let survey_id = r.post_survey_id_from_post_id("postID", PostAccessLevel::BASIC_ACCESS)?; let survey_id = r.post_survey_id_from_post_id("postID", PostAccessLevel::BASIC_ACCESS)?;
survey_helper::cancel_response(r.user_id_ref()?, survey_id)?; survey_helper::cancel_response(r.user_id_ref()?, survey_id)?;
@ -56,7 +56,7 @@ pub fn cancel_response(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Create a new choice for a survey /// Create a new choice for a survey
pub fn create_new_choice(r: &mut HttpRequestHandler) -> RequestResult { pub async fn create_new_choice(r: &mut HttpRequestHandler) -> RequestResult {
let post = r.post_post_with_access("postID", PostAccessLevel::BASIC_ACCESS)?; let post = r.post_post_with_access("postID", PostAccessLevel::BASIC_ACCESS)?;
let new_choice = r.post_string("choice")?; let new_choice = r.post_string("choice")?;
@ -82,7 +82,7 @@ pub fn create_new_choice(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Block the creation of new choices /// Block the creation of new choices
pub fn block_new_choices_creation(r: &mut HttpRequestHandler) -> RequestResult { pub async fn block_new_choices_creation(r: &mut HttpRequestHandler) -> RequestResult {
let survey_id = r.post_survey_id_from_post_id("postID", PostAccessLevel::FULL_ACCESS)?; let survey_id = r.post_survey_id_from_post_id("postID", PostAccessLevel::FULL_ACCESS)?;
survey_helper::block_new_choices_creation(survey_id)?; survey_helper::block_new_choices_creation(survey_id)?;

View File

@ -15,7 +15,7 @@ use crate::helpers::user_helper;
use crate::helpers::user_helper::find_user_by_id; use crate::helpers::user_helper::find_user_by_id;
/// Get information about a single user /// Get information about a single user
pub fn get_single(request: &mut HttpRequestHandler) -> RequestResult { pub async fn get_single(request: &mut HttpRequestHandler) -> RequestResult {
let user_id = UserID::new(request.post_u64("userID")?); let user_id = UserID::new(request.post_u64("userID")?);
let user = match user_helper::find_user_by_id(&user_id) { let user = match user_helper::find_user_by_id(&user_id) {
Ok(user) => user, Ok(user) => user,
@ -30,7 +30,7 @@ pub fn get_single(request: &mut HttpRequestHandler) -> RequestResult {
} }
/// Get information about several users /// Get information about several users
pub fn get_multiple(request: &mut HttpRequestHandler) -> RequestResult { pub async fn get_multiple(request: &mut HttpRequestHandler) -> RequestResult {
let user_ids = request.post_numbers_list("usersID", 1)?; let user_ids = request.post_numbers_list("usersID", 1)?;
let mut map: HashMap<u64, APIUserInfo> = HashMap::new(); let mut map: HashMap<u64, APIUserInfo> = HashMap::new();
@ -49,7 +49,7 @@ pub fn get_multiple(request: &mut HttpRequestHandler) -> RequestResult {
} }
/// Get advanced information about a user /// Get advanced information about a user
pub fn get_advanced_info(request: &mut HttpRequestHandler) -> RequestResult { pub async fn get_advanced_info(request: &mut HttpRequestHandler) -> RequestResult {
let user_id = request.post_user_id("userID")?; let user_id = request.post_user_id("userID")?;
if !user_helper::can_see_user_page(&request.user_id_opt().unwrap_or(UserID::new(0)), &user_id)? { if !user_helper::can_see_user_page(&request.user_id_opt().unwrap_or(UserID::new(0)), &user_id)? {

View File

@ -171,7 +171,7 @@ mod ws_connections_list {
} }
/// Get a WebSocket access token /// Get a WebSocket access token
pub fn get_token(r: &mut HttpRequestHandler) -> ResultBoxError { pub async fn get_token(r: &mut HttpRequestHandler) -> ResultBoxError {
ws_tokens_list::clean_list(); ws_tokens_list::clean_list();
let access_token = rand_str(WS_ACCESS_TOKEN_LENGTH); let access_token = rand_str(WS_ACCESS_TOKEN_LENGTH);

View File

@ -10,7 +10,7 @@ use crate::data::http_request_handler::HttpRequestHandler;
use crate::helpers::{groups_helper, user_helper}; use crate::helpers::{groups_helper, user_helper};
/// Find a user by its virtual directory /// Find a user by its virtual directory
pub fn find_user(r: &mut HttpRequestHandler) -> RequestResult { pub async fn find_user(r: &mut HttpRequestHandler) -> RequestResult {
let directory = r.post_virtual_directory("subfolder")?; let directory = r.post_virtual_directory("subfolder")?;
let user = r.ok_or_not_found( let user = r.ok_or_not_found(
@ -22,7 +22,7 @@ pub fn find_user(r: &mut HttpRequestHandler) -> RequestResult {
} }
/// Search for user / group with a given virtual directory /// Search for user / group with a given virtual directory
pub fn find(r: &mut HttpRequestHandler) -> RequestResult { pub async fn find(r: &mut HttpRequestHandler) -> RequestResult {
let directory = r.post_virtual_directory("directory")?; let directory = r.post_virtual_directory("directory")?;
let user = user_helper::find_user_by_virtual_directory(&directory); let user = user_helper::find_user_by_virtual_directory(&directory);

View File

@ -9,7 +9,7 @@ use crate::helpers::webapp_helper;
use crate::routes::RequestResult; use crate::routes::RequestResult;
/// Get the list of memberships of a given user /// Get the list of memberships of a given user
pub fn get_memberships(r: &mut HttpRequestHandler) -> RequestResult { pub async fn get_memberships(r: &mut HttpRequestHandler) -> RequestResult {
let memberships = webapp_helper::get_user_memberships(r.user_id_ref()?)?; let memberships = webapp_helper::get_user_memberships(r.user_id_ref()?)?;
r.set_response(UserMembershipAPI::for_list(&memberships)) r.set_response(UserMembershipAPI::for_list(&memberships))

View File

@ -182,7 +182,7 @@ macro_rules! route {
$r = Some(Route::get_without_login($uri)); $r = Some(Route::get_without_login($uri));
if let Some(c) = $call { if let Some(c) = $call {
return ($r, Some($func(c))); return ($r, Some($func(c).await));
} }
} }
}; };
@ -193,7 +193,7 @@ macro_rules! route {
$r = Some(Route::post_without_login($uri)); $r = Some(Route::post_without_login($uri));
if let Some(c) = $call { if let Some(c) = $call {
return ($r, Some($func(c))); return ($r, Some($func(c).await));
} }
} }
}; };
@ -204,7 +204,7 @@ macro_rules! route {
$r = Some(Route::post($uri)); $r = Some(Route::post($uri));
if let Some(c) = $call { if let Some(c) = $call {
return ($r, Some($func(c))); return ($r, Some($func(c).await));
} }
} }
}; };
@ -215,7 +215,7 @@ macro_rules! route {
$r = Some(Route::limited_post_without_login($uri, $policy)); $r = Some(Route::limited_post_without_login($uri, $policy));
if let Some(c) = $call { if let Some(c) = $call {
return ($r, Some($func(c))); return ($r, Some($func(c).await));
} }
} }
}; };
@ -226,7 +226,7 @@ macro_rules! route {
$r = Some(Route::limited_post($uri, $policy)); $r = Some(Route::limited_post($uri, $policy));
if let Some(c) = $call { if let Some(c) = $call {
return ($r, Some($func(c))); return ($r, Some($func(c).await));
} }
} }
}; };
@ -237,7 +237,7 @@ macro_rules! route {
$r = Some(Route::limited_admin_post_without_login($uri, $policy)); $r = Some(Route::limited_admin_post_without_login($uri, $policy));
if let Some(c) = $call { if let Some(c) = $call {
return ($r, Some($func(c))); return ($r, Some($func(c).await));
} }
} }
}; };
@ -248,7 +248,7 @@ macro_rules! route {
$r = Some(Route::admin_post($uri)); $r = Some(Route::admin_post($uri));
if let Some(c) = $call { if let Some(c) = $call {
return ($r, Some($func(c))); return ($r, Some($func(c).await));
} }
} }
}; };
@ -259,7 +259,7 @@ macro_rules! route {
$r = Some(Route::admin_post_restricted($uri, $role)); $r = Some(Route::admin_post_restricted($uri, $role));
if let Some(c) = $call { if let Some(c) = $call {
return ($r, Some($func(c))); return ($r, Some($func(c).await));
} }
} }
}; };
@ -416,7 +416,7 @@ pub async fn find_route(req_uri: &str, call: Option<&mut HttpRequestHandler>) ->
// Likes controller // Likes controller
route!(r, req_uri, call, POST_LOGIN, "/likes/update", likes_controller::update); route!(r, req_uri, call, POST_LOGIN, "/likes/update", likes_controller::update_async);
// Surveys controller // Surveys controller