mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-25 23:09:22 +00:00
Make all HTTP routes asynchronous
This commit is contained in:
parent
13e73ede8b
commit
b2514351a1
@ -47,7 +47,7 @@ impl HttpRequestHandler {
|
||||
}
|
||||
|
||||
/// Create a new account
|
||||
pub fn create(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
pub async fn create(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
|
||||
// Get & check email
|
||||
let email = r.post_email("emailAddress")?;
|
||||
@ -68,7 +68,7 @@ pub fn create(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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 password = request.post_string("password")?;
|
||||
|
||||
@ -92,7 +92,7 @@ pub fn login_user(request: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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() {
|
||||
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
|
||||
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()?)?;
|
||||
|
||||
r.success("Successfully disconnected!")
|
||||
}
|
||||
|
||||
/// 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()?))
|
||||
}
|
||||
|
||||
/// 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()?)?;
|
||||
r.set_response(UserMailAddressAPI::new(&user))
|
||||
}
|
||||
|
||||
/// 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")?;
|
||||
|
||||
r.set_response(ResCheckEmailExists::new(account_helper::exists_mail(&email)?))
|
||||
}
|
||||
|
||||
/// 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")?;
|
||||
|
||||
r.set_response(ResCheckSecurityQuestionsExists::new(user.has_security_questions()))
|
||||
}
|
||||
|
||||
/// 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")?;
|
||||
|
||||
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
|
||||
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")?;
|
||||
|
||||
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
|
||||
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 = 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
|
||||
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 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
|
||||
pub fn export_data(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
pub async fn export_data(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
r.need_user_password("password")?;
|
||||
|
||||
let data = account_helper::export(r.user_id_ref()?)?;
|
||||
@ -200,7 +200,7 @@ pub fn export_data(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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")?;
|
||||
|
||||
if r.user_id()?.id() < 2 {
|
||||
|
@ -20,7 +20,7 @@ use crate::routes::RequestResult;
|
||||
use crate::utils::date_utils::time;
|
||||
|
||||
/// 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 name = r.post_string_opt("name", 3, true)?;
|
||||
|
||||
@ -34,7 +34,7 @@ pub fn create(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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 admin = admin_account_helper::find_admin_by_email(&mail)?;
|
||||
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
|
||||
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 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
|
||||
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()?)?;
|
||||
|
||||
r.ok()
|
||||
}
|
||||
|
||||
/// 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()?))
|
||||
}
|
||||
|
||||
/// 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()?
|
||||
.iter()
|
||||
.map(AdminInfoAPI::new)
|
||||
@ -87,7 +87,7 @@ pub fn get_list(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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") {
|
||||
false => admin_account_helper::find_admin_by_id(r.admin_id()?)?,
|
||||
true => {
|
||||
@ -100,7 +100,7 @@ pub fn get_admin_info(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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 new_name = r.post_string("name")?;
|
||||
let new_email = r.post_email("email")?;
|
||||
@ -122,7 +122,7 @@ pub fn update_general_settings(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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")?;
|
||||
|
||||
if admin_id != r.admin_id()? {
|
||||
|
@ -38,7 +38,7 @@ impl HttpRequestHandler {
|
||||
}
|
||||
|
||||
/// 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")?;
|
||||
|
||||
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
|
||||
pub fn challenge_register_key(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
pub async fn challenge_register_key(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
let wan = get_wan();
|
||||
|
||||
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
|
||||
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_password = r.post_string("password")?;
|
||||
|
||||
@ -89,7 +89,7 @@ pub fn register_key(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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 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
|
||||
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 (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
|
||||
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 credentials = r.post_auth_public_key_credential("credential")?;
|
||||
|
||||
|
@ -10,7 +10,7 @@ use crate::constants::admin::AdminRole;
|
||||
use crate::api_data::admin::admin_log_api::AdminLogAPI;
|
||||
|
||||
/// 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)? {
|
||||
true => admin_log_helper::get_all_admin_logs(),
|
||||
false => admin_log_helper::get_admin_logs(r.admin_id()?)
|
||||
|
@ -12,7 +12,7 @@ use crate::helpers::admin_roles_helper;
|
||||
use crate::routes::RequestResult;
|
||||
|
||||
/// 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()
|
||||
.map(AdminRoleDetailsAPI::new)
|
||||
.collect::<Vec<AdminRoleDetailsAPI>>();
|
||||
@ -21,7 +21,7 @@ pub fn get_list(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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 enable = r.post_bool("enable")?;
|
||||
let role_str = r.post_string("role")?;
|
||||
|
@ -15,7 +15,7 @@ use crate::helpers::admin_log_helper::log_admin_action;
|
||||
use crate::routes::RequestResult;
|
||||
|
||||
/// 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)?;
|
||||
|
||||
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
|
||||
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)?;
|
||||
|
||||
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
|
||||
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)?;
|
||||
|
||||
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
|
||||
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)?;
|
||||
|
||||
let user_id = r.post_user_id("user_id")?;
|
||||
|
@ -20,7 +20,7 @@ use crate::utils::date_utils::time;
|
||||
use crate::utils::string_utils::remove_html_nodes;
|
||||
|
||||
/// 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)?;
|
||||
|
||||
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
|
||||
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")?;
|
||||
|
||||
r.set_response(CommentAPI::new(&comment, &r.user_id_opt())?)
|
||||
}
|
||||
|
||||
/// 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 new_content = r.post_content("content", 2, true)?;
|
||||
|
||||
@ -78,7 +78,7 @@ pub fn edit(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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")?;
|
||||
|
||||
comments_helper::delete(&comment)?;
|
||||
|
@ -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};
|
||||
|
||||
/// 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")?;
|
||||
|
||||
// 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
|
||||
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()?)?;
|
||||
|
||||
r.set_response(list.iter().map(|c| ConversationAPI::new(c)).collect::<Vec<ConversationAPI>>())
|
||||
}
|
||||
|
||||
/// 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 = 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
|
||||
pub fn update_settings(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
pub async fn update_settings(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
let conv_membership = r.post_conv("conversationID")?;
|
||||
|
||||
// Update following state, if required
|
||||
@ -105,7 +105,7 @@ pub fn update_settings(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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 = conversations_helper::get_single(conv_membership.conv_id)?;
|
||||
|
||||
@ -119,7 +119,7 @@ pub fn change_image(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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 = 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
|
||||
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 = 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
|
||||
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 = conversations_helper::get_single(conv_membership.conv_id)?;
|
||||
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
|
||||
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 = conversations_helper::get_single(conv_membership.conv_id)?;
|
||||
|
||||
@ -201,7 +201,7 @@ pub fn remove_member(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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 allow_create = r.post_bool_opt("allowCreate", false);
|
||||
|
||||
@ -236,7 +236,7 @@ pub fn find_private(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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 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
|
||||
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 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
|
||||
pub fn send_message(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
pub async fn send_message(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
let conv = r.post_conv("conversationID")?;
|
||||
|
||||
// Get associated file
|
||||
@ -401,21 +401,21 @@ pub fn send_message(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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()?)?;
|
||||
|
||||
r.set_response(ResultCountUnreadConversations::new(num))
|
||||
}
|
||||
|
||||
/// 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()?)?;
|
||||
|
||||
r.set_response(UnreadConversationAPI::for_list(&list)?)
|
||||
}
|
||||
|
||||
/// 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 = 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
|
||||
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 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
|
||||
pub fn delete_message(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
pub async fn delete_message(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
let msg_id = r.post_u64("messageID")?;
|
||||
|
||||
if !conversations_helper::is_message_owner(&r.user_id()?, msg_id)? {
|
||||
|
@ -16,7 +16,7 @@ use crate::helpers::{forez_presence_helper, groups_helper, user_helper};
|
||||
use crate::routes::RequestResult;
|
||||
|
||||
/// 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![];
|
||||
|
||||
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
|
||||
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 member = r.post_user_id("user")?;
|
||||
|
||||
|
@ -11,14 +11,14 @@ use crate::helpers::{friends_helper, notifications_helper, user_helper};
|
||||
use crate::routes::RequestResult;
|
||||
|
||||
/// 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()?;
|
||||
|
||||
r.set_response(FriendAPI::from_list(&list))
|
||||
}
|
||||
|
||||
/// 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 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
|
||||
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")?;
|
||||
|
||||
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
|
||||
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 curr_user_id = r.user_id()?;
|
||||
|
||||
@ -62,7 +62,7 @@ pub fn get_status(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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")?;
|
||||
|
||||
if friend_id == r.user_id()? {
|
||||
@ -91,7 +91,7 @@ pub fn send_request(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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")?;
|
||||
|
||||
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
|
||||
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 accept = r.post_bool("accept")?;
|
||||
|
||||
@ -131,7 +131,7 @@ pub fn respond_request(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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")?;
|
||||
|
||||
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
|
||||
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 follow = r.post_bool("follow")?;
|
||||
|
||||
@ -153,7 +153,7 @@ pub fn set_following(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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 allow = r.post_bool("allow")?;
|
||||
|
||||
|
@ -51,7 +51,7 @@ impl HttpRequestHandler {
|
||||
}
|
||||
|
||||
/// Create a new group
|
||||
pub fn create(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
pub async fn create(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
let new_group = NewGroup {
|
||||
name: r.post_string_opt("name", 3, true)?,
|
||||
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
|
||||
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)?
|
||||
.iter()
|
||||
.map(|f| f.id())
|
||||
@ -73,7 +73,7 @@ pub fn get_list_user(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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 = groups_helper::get_info(&group_id)?;
|
||||
|
||||
@ -81,7 +81,7 @@ pub fn get_info_single(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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 mut list = HashMap::new();
|
||||
@ -103,7 +103,7 @@ pub fn get_info_multiple(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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 = 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
|
||||
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 = groups_helper::get_info(&group_id)?;
|
||||
|
||||
@ -121,7 +121,7 @@ pub fn get_settings(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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 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
|
||||
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 dir = r.post_virtual_directory("directory")?;
|
||||
|
||||
@ -156,7 +156,7 @@ pub fn check_virtual_dir(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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)?;
|
||||
|
||||
if !r.has_file("logo") {
|
||||
@ -173,7 +173,7 @@ pub fn upload_logo(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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)?;
|
||||
|
||||
groups_helper::delete_logo(&group_id)?;
|
||||
@ -182,7 +182,7 @@ pub fn delete_logo(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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 min_membership_level = r.post_group_membership_level_for_conversation("min_membership_level")?;
|
||||
let name = r.post_string("name")?;
|
||||
@ -193,7 +193,7 @@ pub fn create_conversation(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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 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
|
||||
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")?;
|
||||
|
||||
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
|
||||
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_access_level = groups_helper::get_access_level(&group_id, r.user_id_opt())?;
|
||||
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
|
||||
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 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
|
||||
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 user_id = r.post_user_id("userID")?;
|
||||
|
||||
@ -263,7 +263,7 @@ pub fn invite_user(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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 accept = r.post_bool("accept")?;
|
||||
|
||||
@ -287,7 +287,7 @@ pub fn respond_invitation(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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)?;
|
||||
|
||||
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
|
||||
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)?;
|
||||
|
||||
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)
|
||||
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)?;
|
||||
|
||||
// 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
|
||||
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 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
|
||||
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 user_id = r.post_user_id("userID")?;
|
||||
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
|
||||
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 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
|
||||
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)?;
|
||||
|
||||
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
|
||||
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 following = r.post_bool("follow")?;
|
||||
|
||||
@ -452,7 +452,7 @@ pub fn set_following(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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)?;
|
||||
r.need_user_password("password")?;
|
||||
|
||||
|
@ -12,6 +12,11 @@ use crate::helpers::likes_helper::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
|
||||
pub fn update<H: BaseRequestHandler>(r: &mut H) -> RequestResult {
|
||||
let req_type = r.post_string("type")?;
|
||||
|
@ -35,13 +35,13 @@ impl HttpRequestHandler {
|
||||
}
|
||||
|
||||
/// 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()?)?;
|
||||
r.set_response(ResNumberUnreadNotifications::new(number))
|
||||
}
|
||||
|
||||
/// 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 conversations = conversations_helper::count_unread_for_user(r.user_id_ref()?)?;
|
||||
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
|
||||
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()?)?;
|
||||
|
||||
r.set_response(NotificationAPI::for_list(&list))
|
||||
}
|
||||
|
||||
/// 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 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
|
||||
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()?)?;
|
||||
|
||||
r.success("Notifications deleted.")
|
||||
|
@ -35,7 +35,7 @@ impl PostFile {
|
||||
}
|
||||
|
||||
/// 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 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
|
||||
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 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
|
||||
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 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
|
||||
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)?;
|
||||
|
||||
r.set_response(PostAPI::new(&post, &r.user_id_opt())?)
|
||||
}
|
||||
|
||||
/// Create a new post
|
||||
pub fn create_post(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
pub async fn create_post(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
// Process page target
|
||||
let target_page = match r.post_string("kind-page")?.as_str() {
|
||||
"user" => {
|
||||
@ -241,7 +241,7 @@ pub fn create_post(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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 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
|
||||
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 new_content = r.post_content("new_content", 2, true)?;
|
||||
|
||||
@ -269,7 +269,7 @@ pub fn update_content(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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)?;
|
||||
|
||||
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
|
||||
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 groups = groups_helper::get_list_where_user_can_create_posts(r.user_id_ref()?)?;
|
||||
|
||||
|
@ -11,14 +11,14 @@ use crate::helpers::{account_helper, independent_push_notifications_service_help
|
||||
use crate::routes::RequestResult;
|
||||
|
||||
/// 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();
|
||||
|
||||
r.set_response(PushNotificationsStatusAPI::new(status))
|
||||
}
|
||||
|
||||
/// 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 = match status.as_str() {
|
||||
|
@ -10,7 +10,7 @@ use crate::data::http_request_handler::HttpRequestHandler;
|
||||
use crate::helpers::{groups_helper, user_helper};
|
||||
|
||||
/// 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 limit = r.post_u64_opt("searchLimit", 5)?;
|
||||
|
||||
@ -23,7 +23,7 @@ pub fn search_user(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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 limit = 10;
|
||||
|
||||
|
@ -8,11 +8,11 @@ use crate::routes::RequestResult;
|
||||
/// @author Pierre Hubert
|
||||
|
||||
/// 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")
|
||||
}
|
||||
|
||||
/// 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()))
|
||||
}
|
@ -26,14 +26,14 @@ use crate::routes::RequestResult;
|
||||
use crate::utils::string_utils::remove_html_nodes;
|
||||
|
||||
/// 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()?)?;
|
||||
|
||||
r.set_response(GeneralSettingsAPI::new(&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")?) {
|
||||
(true, true) => UserPageVisibility::OPEN,
|
||||
(true, false) => UserPageVisibility::PUBLIC,
|
||||
@ -67,7 +67,7 @@ pub fn set_general(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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
|
||||
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
|
||||
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()?)?;
|
||||
|
||||
r.set_response(LanguageSettingsAPI::new(&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")?;
|
||||
|
||||
if !SUPPORTED_LANGUAGES.contains(&lang.as_str()) {
|
||||
@ -100,7 +100,7 @@ pub fn set_language(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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")?;
|
||||
|
||||
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
|
||||
pub fn set_security(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
pub async fn set_security(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
r.need_user_password("password")?;
|
||||
|
||||
let new_settings = SecuritySettings {
|
||||
@ -131,14 +131,14 @@ pub fn set_security(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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.success("The password is valid.")
|
||||
}
|
||||
|
||||
/// 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")?;
|
||||
|
||||
let new_password = r.post_string("newPassword")?;
|
||||
@ -149,14 +149,14 @@ pub fn update_password(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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()?)?;
|
||||
|
||||
r.set_response(AccountImageSettingsAPI::new(&user))
|
||||
}
|
||||
|
||||
/// 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") {
|
||||
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
|
||||
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()?)?;
|
||||
|
||||
r.success("Account image deleted!")
|
||||
}
|
||||
|
||||
/// 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")?);
|
||||
|
||||
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
|
||||
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")?;
|
||||
|
||||
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
|
||||
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")?;
|
||||
|
||||
custom_emojies_helper::delete(&emoji)?;
|
||||
@ -213,14 +213,14 @@ pub fn delete_custom_emoji(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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()?)?;
|
||||
|
||||
r.set_response(DataConservationSettingsAPI::new(&user))
|
||||
}
|
||||
|
||||
/// 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")?;
|
||||
|
||||
let policy = NewDataConservationPolicy {
|
||||
@ -265,14 +265,14 @@ pub fn set_data_conservation_policy(r: &mut HttpRequestHandler) -> RequestResult
|
||||
}
|
||||
|
||||
/// 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()?)?;
|
||||
|
||||
r.set_response(NotificationSettingsAPI::new(&user))
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
user_id: r.user_id()?,
|
||||
allow_notifications_sound: r.post_bool("allow_notifications_sound")?,
|
||||
|
@ -20,7 +20,7 @@ impl HttpRequestHandler {
|
||||
}
|
||||
|
||||
/// 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 survey = r.ok_or_not_found(
|
||||
survey_helper::get_info(post.id),
|
||||
@ -31,7 +31,7 @@ pub fn get_info_single(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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 choice_id = r.post_u64("choiceID")?;
|
||||
|
||||
@ -47,7 +47,7 @@ pub fn send_response(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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)?;
|
||||
|
||||
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
|
||||
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 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
|
||||
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)?;
|
||||
|
||||
survey_helper::block_new_choices_creation(survey_id)?;
|
||||
|
@ -15,7 +15,7 @@ use crate::helpers::user_helper;
|
||||
use crate::helpers::user_helper::find_user_by_id;
|
||||
|
||||
/// 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 = match user_helper::find_user_by_id(&user_id) {
|
||||
Ok(user) => user,
|
||||
@ -30,7 +30,7 @@ pub fn get_single(request: &mut HttpRequestHandler) -> RequestResult {
|
||||
}
|
||||
|
||||
/// 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 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
|
||||
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")?;
|
||||
|
||||
if !user_helper::can_see_user_page(&request.user_id_opt().unwrap_or(UserID::new(0)), &user_id)? {
|
||||
|
@ -171,7 +171,7 @@ mod ws_connections_list {
|
||||
}
|
||||
|
||||
/// 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();
|
||||
|
||||
let access_token = rand_str(WS_ACCESS_TOKEN_LENGTH);
|
||||
|
@ -10,7 +10,7 @@ use crate::data::http_request_handler::HttpRequestHandler;
|
||||
use crate::helpers::{groups_helper, user_helper};
|
||||
|
||||
/// 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 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
|
||||
pub fn find(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
pub async fn find(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
let directory = r.post_virtual_directory("directory")?;
|
||||
|
||||
let user = user_helper::find_user_by_virtual_directory(&directory);
|
||||
|
@ -9,7 +9,7 @@ use crate::helpers::webapp_helper;
|
||||
use crate::routes::RequestResult;
|
||||
|
||||
/// 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()?)?;
|
||||
|
||||
r.set_response(UserMembershipAPI::for_list(&memberships))
|
||||
|
@ -182,7 +182,7 @@ macro_rules! route {
|
||||
$r = Some(Route::get_without_login($uri));
|
||||
|
||||
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));
|
||||
|
||||
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));
|
||||
|
||||
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));
|
||||
|
||||
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));
|
||||
|
||||
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));
|
||||
|
||||
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));
|
||||
|
||||
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));
|
||||
|
||||
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
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user