1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-26 23:39:22 +00:00

Can get account image settings

This commit is contained in:
Pierre HUBERT 2021-01-19 18:14:17 +01:00
parent 6c7fa3afa5
commit 364a98634f
5 changed files with 50 additions and 1 deletions

View File

@ -0,0 +1,29 @@
//! # Account image settings API
use serde::Serialize;
use crate::constants::DEFAULT_ACCOUNT_IMAGE;
use crate::data::user::User;
use crate::utils::user_data_utils::user_data_url;
#[derive(Serialize)]
#[allow(non_snake_case)]
pub struct AccountImageSettingsAPI
{
has_image: bool,
image_url: String,
visibility: String,
}
impl AccountImageSettingsAPI {
pub fn new(user: &User) -> AccountImageSettingsAPI
{
AccountImageSettingsAPI
{
has_image: user.has_account_image(),
image_url: user_data_url(user.account_image_path
.as_ref().unwrap_or(&DEFAULT_ACCOUNT_IMAGE.to_string())),
visibility: user.account_image_visibility.to_api(),
}
}
}

View File

@ -54,3 +54,4 @@ pub mod entities_constructor;
pub mod general_settings_api; pub mod general_settings_api;
pub mod language_settings_api; pub mod language_settings_api;
pub mod security_settings_api; pub mod security_settings_api;
pub mod account_image_settings_api;

View File

@ -102,6 +102,7 @@ pub fn get_routes() -> Vec<Route> {
Route::post("/settings/set_security", Box::new(settings_controller::set_security)), Route::post("/settings/set_security", Box::new(settings_controller::set_security)),
Route::post("/settings/check_password", Box::new(settings_controller::check_password)), Route::post("/settings/check_password", Box::new(settings_controller::check_password)),
Route::post("/settings/update_password", Box::new(settings_controller::update_password)), Route::post("/settings/update_password", Box::new(settings_controller::update_password)),
Route::post("/settings/get_account_image", Box::new(settings_controller::get_account_image_settings)),
// Friends controller // Friends controller

View File

@ -14,6 +14,7 @@ use crate::data::security_settings::{SecurityQuestion, SecuritySettings};
use crate::data::user::UserPageStatus; use crate::data::user::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;
use crate::api_data::account_image_settings_api::AccountImageSettingsAPI;
/// Get the general settings of the user /// Get the general settings of the user
pub fn get_general(r: &mut HttpRequestHandler) -> RequestResult { pub fn get_general(r: &mut HttpRequestHandler) -> RequestResult {
@ -135,3 +136,10 @@ pub fn update_password(r: &mut HttpRequestHandler) -> RequestResult {
r.success("Password updated !") r.success("Password updated !")
} }
/// Get account image settings
pub 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))
}

View File

@ -59,6 +59,16 @@ pub enum AccountImageVisibility {
EVERYONE, EVERYONE,
} }
impl AccountImageVisibility {
pub fn to_api(&self) -> String {
match self {
AccountImageVisibility::FRIENDS => "friends".to_string(),
AccountImageVisibility::COMUNIC_USERS => "public".to_string(),
AccountImageVisibility::EVERYONE => "open".to_string(),
}
}
}
#[derive(Debug)] #[derive(Debug)]
pub struct User { pub struct User {
pub id: UserID, pub id: UserID,