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

Can get general settings

This commit is contained in:
Pierre HUBERT 2020-07-14 11:15:20 +02:00
parent fb7f56c359
commit dcd8b07b60
7 changed files with 79 additions and 2 deletions

View File

@ -0,0 +1,45 @@
//! # General settings API
//!
//! @author Pierre Hubert
use serde::Serialize;
use crate::data::user::User;
#[derive(Serialize)]
#[allow(non_snake_case)]
pub struct GeneralSettingsAPI {
id: u64,
email: String,
firstName: String,
lastName: String,
is_public: bool,
is_open: bool,
allow_comments: bool,
allow_posts_from_friends: bool,
allow_comunic_mails: bool,
public_friends_list: bool,
virtual_directory: String,
personnal_website: String,
publicNote: String,
}
impl GeneralSettingsAPI {
pub fn new(user: &User) -> GeneralSettingsAPI {
GeneralSettingsAPI {
id: user.id.id(),
email: user.email.clone(),
firstName: user.first_name.clone(),
lastName: user.last_name.clone(),
is_public: user.is_page_public(),
is_open: user.is_page_open(),
allow_comments: !user.block_comments_on_his_page,
allow_posts_from_friends: user.allow_posts_from_friends,
allow_comunic_mails: user.allow_mails,
public_friends_list: user.public_friends_list,
virtual_directory: user.virtual_directory.clone().unwrap_or(String::new()),
personnal_website: user.personal_website.clone().unwrap_or(String::new()),
publicNote: user.public_note.clone().unwrap_or(String::new()),
}
}
}

View File

@ -50,4 +50,5 @@ pub mod res_check_security_answers;
pub mod account_export_api;
pub mod user_like_api;
pub mod survey_response_api;
pub mod entities_constructor;
pub mod entities_constructor;
pub mod general_settings_api;

View File

@ -4,6 +4,7 @@ pub mod server;
pub mod server_controller;
pub mod account_controller;
pub mod user_controller;
pub mod settings_controller;
pub mod friends_controller;
pub mod conversations_controller;
pub mod search_controller;

View File

@ -1,6 +1,6 @@
use std::error::Error;
use crate::controllers::{account_controller, calls_controller, comments_controller, conversations_controller, friends_controller, groups_controller, likes_controller, movies_controller, notifications_controller, posts_controller, search_controller, server_controller, surveys_controller, user_controller, virtual_directory_controller, web_app_controller};
use crate::controllers::{account_controller, calls_controller, comments_controller, conversations_controller, friends_controller, groups_controller, likes_controller, movies_controller, notifications_controller, posts_controller, search_controller, server_controller, settings_controller, surveys_controller, user_controller, virtual_directory_controller, web_app_controller};
use crate::controllers::routes::Method::{GET, POST};
use crate::data::http_request_handler::HttpRequestHandler;
@ -92,6 +92,9 @@ pub fn get_routes() -> Vec<Route> {
Route::post_without_login("/user/getAdvancedUserInfo", Box::new(user_controller::get_advanced_info)),
Route::post_without_login("/user/getAdvancedUserInfos", Box::new(user_controller::get_advanced_info)),
// Settings controller
Route::post("/settings/get_general", Box::new(settings_controller::get_general)),
// Friends controller
Route::post("/friends/getList", Box::new(friends_controller::get_list)),
Route::post("/friends/get_single_infos", Box::new(friends_controller::get_single_friendship_info)),

View File

@ -0,0 +1,15 @@
//! # Settings controller
//!
//! @author Pierre Hubert
use crate::api_data::general_settings_api::GeneralSettingsAPI;
use crate::controllers::routes::RequestResult;
use crate::data::http_request_handler::HttpRequestHandler;
use crate::helpers::user_helper;
/// Get the general settings of the user
pub 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))
}

View File

@ -76,6 +76,7 @@ pub struct User {
pub block_comments_on_his_page: bool,
pub allow_posts_from_friends: bool,
pub account_creation_time: u64,
pub allow_mails: bool,
pub security_question_1: Option<String>,
pub security_answer_1: Option<String>,
pub security_question_2: Option<String>,
@ -83,6 +84,16 @@ pub struct User {
}
impl User {
/// Check if user's page is public
pub fn is_page_public(&self) -> bool {
!matches!(self.status, UserPageStatus::PRIVATE)
}
/// Check if user's page is open
pub fn is_page_open(&self) -> bool {
matches!(self.status, UserPageStatus::OPEN)
}
/// Get the URL pointing to the default account image
pub fn default_account_image_url() -> String {
user_data_url(crate::constants::DEFAULT_ACCOUNT_IMAGE)

View File

@ -64,6 +64,7 @@ fn exec_get_user_query(query: database::QueryInfo) -> ResultBoxError<User> {
block_comments_on_his_page: res.get_legacy_bool("bloquecommentaire")?,
allow_posts_from_friends: res.get_legacy_bool("autoriser_post_amis")?,
account_creation_time: res.get_date_as_time("date_creation")?,
allow_mails: res.get_legacy_bool("autorise_mail")?,
security_question_1: res.get_optional_str("question1")?,
security_answer_1: res.get_optional_str("reponse1")?,
security_question_2: res.get_optional_str("question2")?,