From b5d24104136e8cae17cf1caaed2bcc1173931af5 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 16 Apr 2021 14:56:47 +0200 Subject: [PATCH] Add new user information --- docs/db_struct.sql | 2 +- docs/migration.sql | 2 +- src/api_data/account_export_api.rs | 4 ++-- src/api_data/user_info.rs | 29 ++++++++++++++++++----------- src/data/user.rs | 4 ++++ src/helpers/user_helper.rs | 4 ++++ 6 files changed, 30 insertions(+), 15 deletions(-) diff --git a/docs/db_struct.sql b/docs/db_struct.sql index 7515202..4443660 100644 --- a/docs/db_struct.sql +++ b/docs/db_struct.sql @@ -250,7 +250,7 @@ CREATE TABLE `utilisateurs` ( `delete_likes_after` int DEFAULT '0', `allow_notif_conv` int DEFAULT '1', `allow_notif_sound` int DEFAULT '1', - `is_email_visible` int DEFAULT '0', + `is_email_public` int DEFAULT '0', `location` varchar(45) DEFAULT NULL, PRIMARY KEY (`ID`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4; diff --git a/docs/migration.sql b/docs/migration.sql index dfabbef..84a3b19 100644 --- a/docs/migration.sql +++ b/docs/migration.sql @@ -1,4 +1,4 @@ -- Nothing yet ALTER TABLE `utilisateurs` - ADD COLUMN `is_email_visible` INT NULL DEFAULT 0 AFTER `allow_notif_sound`, + ADD COLUMN `is_email_public` INT NULL DEFAULT 0 AFTER `allow_notif_sound`, ADD COLUMN `location` VARCHAR(45) NULL AFTER `is_email_visible`; diff --git a/src/api_data/account_export_api.rs b/src/api_data/account_export_api.rs index 96c3103..9c64384 100644 --- a/src/api_data/account_export_api.rs +++ b/src/api_data/account_export_api.rs @@ -13,7 +13,7 @@ use crate::api_data::friend_api::FriendAPI; use crate::api_data::group_api::GroupApi; use crate::api_data::post_api::PostAPI; use crate::api_data::survey_response_api::SurveyResponseAPI; -use crate::api_data::user_info::APIUserInfo; +use crate::api_data::user_info::{APIUserInfo, APIAdvancedInfo}; use crate::api_data::user_like_api::UserLikeAPI; use crate::data::account_export::AccountExport; use crate::data::error::ResultBoxError; @@ -26,7 +26,7 @@ use crate::helpers::user_helper; #[allow(non_snake_case)] pub struct AccountExportAPI { userID: u64, - advanced_info: APIUserInfo, + advanced_info: APIAdvancedInfo, posts: Vec, comments: Vec, likes: Vec, diff --git a/src/api_data/user_info.rs b/src/api_data/user_info.rs index 26ddf11..c12abd3 100644 --- a/src/api_data/user_info.rs +++ b/src/api_data/user_info.rs @@ -22,17 +22,17 @@ pub struct APIUserInfo { virtualDirectory: String, accountImage: String, customEmojis: Vec, - - #[serde(flatten)] - advanced_info: Option, } #[derive(Serialize)] #[allow(non_snake_case)] -struct APIAdvancedInfo { +pub struct APIAdvancedInfo { friend_list_public: bool, personnalWebsite: String, publicNote: String, + location: Option, + is_email_public: bool, + email_address: Option, noCommentOnHisPage: bool, allowPostFromFriendOnHisPage: bool, account_creation_time: u64, @@ -41,6 +41,9 @@ struct APIAdvancedInfo { pageLikes: usize, user_like_page: bool, can_post_texts: bool, + + #[serde(flatten)] + base_info: APIUserInfo, } impl APIUserInfo { @@ -59,13 +62,12 @@ impl APIUserInfo { .iter() .map(|f| CustomEmojiAPI::new(f)) .collect(), - advanced_info: None, }) } /// Get advanced user information - pub fn new_advanced_info(user_id: &Option, info: &User) -> ResultBoxError { - let mut user = APIUserInfo::new(&user_id, info)?; + pub fn new_advanced_info(user_id: &Option, info: &User) -> ResultBoxError { + let user = APIUserInfo::new(&user_id, info)?; let curr_user_id = user_id.clone().unwrap_or(UserID::new(0)); let signed_in = user_id.is_some(); @@ -79,10 +81,17 @@ impl APIUserInfo { } else { false }; // Set advanced user information - user.advanced_info = Some(APIAdvancedInfo { + Ok(APIAdvancedInfo { + base_info: user, friend_list_public: info.public_friends_list, personnalWebsite: info.personal_website.clone().unwrap_or(String::new()), publicNote: info.public_note.clone().unwrap_or(String::new()), + location: info.location.clone(), + is_email_public: info.is_email_public, + email_address: match info.is_email_public { + true => Some(info.email.clone()), + false => None, + }, noCommentOnHisPage: info.block_comments_on_his_page, allowPostFromFriendOnHisPage: info.allow_posts_from_friends, account_creation_time: info.account_creation_time, @@ -91,9 +100,7 @@ impl APIUserInfo { pageLikes: likes_helper::count(info.id.id(), LikeType::USER)?, user_like_page: likes_page, can_post_texts: user_helper::can_create_posts(&curr_user_id, &info.id)?, - }); - - Ok(user) + }) } /// Get the URL of a specific user account image diff --git a/src/data/user.rs b/src/data/user.rs index a3dab88..8f347a5 100644 --- a/src/data/user.rs +++ b/src/data/user.rs @@ -115,13 +115,17 @@ pub struct User { pub account_image_path: Option, pub account_image_visibility: AccountImageVisibility, pub public_friends_list: bool, + pub is_email_public: bool, pub personal_website: Option, pub public_note: Option, + pub location: Option, pub block_comments_on_his_page: bool, pub allow_posts_from_friends: bool, pub account_creation_time: u64, pub allow_mails: bool, pub lang: String, + + /// Security questions pub security_question_1: Option, pub security_answer_1: Option, pub security_question_2: Option, diff --git a/src/helpers/user_helper.rs b/src/helpers/user_helper.rs index 02a54d4..7727351 100644 --- a/src/helpers/user_helper.rs +++ b/src/helpers/user_helper.rs @@ -68,13 +68,17 @@ fn db_to_user(res: &database::RowResult) -> ResultBoxError { account_image_path: res.get_optional_str("account_image_path")?, account_image_visibility, public_friends_list: res.get_legacy_bool("liste_amis_publique")?, + is_email_public: res.get_legacy_bool("is_email_public")?, personal_website: res.get_optional_str("site_web")?, public_note: res.get_optional_str("public_note")?, + location: res.get_optional_str("location")?, 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")?, lang: res.get_str("lang")?, + + // Security questions security_question_1: res.get_optional_str("question1")?, security_answer_1: res.get_optional_str("reponse1")?, security_question_2: res.get_optional_str("question2")?,