mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-26 07:19:22 +00:00
Can update account image visibility
This commit is contained in:
parent
33eab5919b
commit
1fd3a8e6d9
@ -105,6 +105,7 @@ pub fn get_routes() -> Vec<Route> {
|
|||||||
Route::post("/settings/get_account_image", Box::new(settings_controller::get_account_image_settings)),
|
Route::post("/settings/get_account_image", Box::new(settings_controller::get_account_image_settings)),
|
||||||
Route::post("/settings/upload_account_image", Box::new(settings_controller::upload_account_image)),
|
Route::post("/settings/upload_account_image", Box::new(settings_controller::upload_account_image)),
|
||||||
Route::post("/settings/delete_account_image", Box::new(settings_controller::delete_account_image)),
|
Route::post("/settings/delete_account_image", Box::new(settings_controller::delete_account_image)),
|
||||||
|
Route::post("/settings/set_account_image_visibility", Box::new(settings_controller::set_account_image_visibility)),
|
||||||
|
|
||||||
|
|
||||||
// Friends controller
|
// Friends controller
|
||||||
|
@ -12,7 +12,7 @@ use crate::data::general_settings::GeneralSettings;
|
|||||||
use crate::data::http_request_handler::HttpRequestHandler;
|
use crate::data::http_request_handler::HttpRequestHandler;
|
||||||
use crate::data::lang_settings::LangSettings;
|
use crate::data::lang_settings::LangSettings;
|
||||||
use crate::data::security_settings::{SecurityQuestion, SecuritySettings};
|
use crate::data::security_settings::{SecurityQuestion, SecuritySettings};
|
||||||
use crate::data::user::UserPageStatus;
|
use crate::data::user::{AccountImageVisibility, UserPageStatus};
|
||||||
use crate::helpers::{account_helper, user_helper};
|
use crate::helpers::{account_helper, user_helper};
|
||||||
use crate::helpers::virtual_directory_helper::VirtualDirType;
|
use crate::helpers::virtual_directory_helper::VirtualDirType;
|
||||||
|
|
||||||
@ -163,3 +163,12 @@ pub fn delete_account_image(r: &mut HttpRequestHandler) -> RequestResult {
|
|||||||
|
|
||||||
r.success("Account image deleted!")
|
r.success("Account image deleted!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Change account image visibility
|
||||||
|
pub 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)?;
|
||||||
|
|
||||||
|
r.success("Image image visibility level updated!")
|
||||||
|
}
|
@ -67,6 +67,22 @@ impl AccountImageVisibility {
|
|||||||
AccountImageVisibility::EVERYONE => "open".to_string(),
|
AccountImageVisibility::EVERYONE => "open".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn from_api(s: &str) -> Self {
|
||||||
|
match s {
|
||||||
|
"friends" => AccountImageVisibility::FRIENDS,
|
||||||
|
"public" => AccountImageVisibility::COMUNIC_USERS,
|
||||||
|
"open" | _ => AccountImageVisibility::EVERYONE,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn to_db(&self) -> String {
|
||||||
|
match self {
|
||||||
|
AccountImageVisibility::FRIENDS => "friends".to_string(),
|
||||||
|
AccountImageVisibility::COMUNIC_USERS => "comunic_users".to_string(),
|
||||||
|
AccountImageVisibility::EVERYONE => "everyone".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -6,13 +6,13 @@ use crate::data::error::{ExecError, ResultBoxError};
|
|||||||
use crate::data::general_settings::GeneralSettings;
|
use crate::data::general_settings::GeneralSettings;
|
||||||
use crate::data::lang_settings::LangSettings;
|
use crate::data::lang_settings::LangSettings;
|
||||||
use crate::data::new_account::NewAccount;
|
use crate::data::new_account::NewAccount;
|
||||||
use crate::data::user::{UserID, UserPageStatus};
|
use crate::data::security_settings::SecuritySettings;
|
||||||
|
use crate::data::user::{AccountImageVisibility, UserID, UserPageStatus};
|
||||||
use crate::data::user_token::UserAccessToken;
|
use crate::data::user_token::UserAccessToken;
|
||||||
use crate::helpers::{comments_helper, conversations_helper, database, friends_helper, groups_helper, likes_helper, movies_helper, posts_helper, survey_helper, user_helper};
|
use crate::helpers::{comments_helper, conversations_helper, database, friends_helper, groups_helper, likes_helper, movies_helper, posts_helper, survey_helper, user_helper};
|
||||||
use crate::helpers::database::{DeleteQuery, InsertQuery, QueryInfo};
|
use crate::helpers::database::{DeleteQuery, InsertQuery, QueryInfo};
|
||||||
use crate::utils::crypt_utils::{crypt_pass, rand_str};
|
use crate::utils::crypt_utils::{crypt_pass, rand_str};
|
||||||
use crate::utils::date_utils::{mysql_date, time};
|
use crate::utils::date_utils::{mysql_date, time};
|
||||||
use crate::data::security_settings::SecuritySettings;
|
|
||||||
use crate::utils::user_data_utils::user_data_path;
|
use crate::utils::user_data_utils::user_data_path;
|
||||||
|
|
||||||
/// Account helper
|
/// Account helper
|
||||||
@ -266,6 +266,14 @@ pub fn set_account_image(user_id: &UserID, uri: &String) -> ResultBoxError {
|
|||||||
.exec()
|
.exec()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set account image visibility level
|
||||||
|
pub fn set_account_image_visibility(user_id: &UserID, level: AccountImageVisibility) -> ResultBoxError {
|
||||||
|
database::UpdateInfo::new(USERS_TABLE)
|
||||||
|
.cond_user_id("ID", user_id)
|
||||||
|
.set_str("account_image_visibility", &level.to_db())
|
||||||
|
.exec()
|
||||||
|
}
|
||||||
|
|
||||||
/// Export an account's data
|
/// Export an account's data
|
||||||
pub fn export(user_id: &UserID) -> ResultBoxError<AccountExport> {
|
pub fn export(user_id: &UserID) -> ResultBoxError<AccountExport> {
|
||||||
let mut data = AccountExport {
|
let mut data = AccountExport {
|
||||||
|
@ -44,8 +44,7 @@ fn exec_get_user_query(query: database::QueryInfo) -> ResultBoxError<User> {
|
|||||||
let account_image_visibility = match res.get_str("account_image_visibility")?.as_ref() {
|
let account_image_visibility = match res.get_str("account_image_visibility")?.as_ref() {
|
||||||
"friends" => AccountImageVisibility::FRIENDS,
|
"friends" => AccountImageVisibility::FRIENDS,
|
||||||
"comunic_users" => AccountImageVisibility::COMUNIC_USERS,
|
"comunic_users" => AccountImageVisibility::COMUNIC_USERS,
|
||||||
"everyone" => AccountImageVisibility::EVERYONE,
|
"everyone" | _ => AccountImageVisibility::EVERYONE,
|
||||||
_ => unreachable!()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(User {
|
Ok(User {
|
||||||
|
Loading…
Reference in New Issue
Block a user