From 741fe1c98632fb8934a1b98d0dc101554a2621f4 Mon Sep 17 00:00:00 2001 From: trisua Date: Fri, 16 May 2025 21:29:25 -0400 Subject: [PATCH] add: ability to require account to view profile --- crates/app/src/macros.rs | 15 ++++ .../app/src/public/html/profile/settings.html | 8 ++ crates/core/src/database/posts.rs | 83 +++++++++++-------- crates/core/src/model/auth.rs | 3 + 4 files changed, 74 insertions(+), 35 deletions(-) diff --git a/crates/app/src/macros.rs b/crates/app/src/macros.rs index 2b87228..edfb8de 100644 --- a/crates/app/src/macros.rs +++ b/crates/app/src/macros.rs @@ -98,6 +98,21 @@ macro_rules! get_lang { #[macro_export] macro_rules! check_user_blocked_or_private { ($user:ident, $other_user:ident, $data:ident, $jar:ident) => { + // check require_account + if $user.is_none() && $other_user.settings.require_account { + return Err(Html( + render_error( + Error::MiscError( + "This profile requires you are logged in to view it.".to_string(), + ), + &$jar, + &$data, + &$user, + ) + .await, + )); + } + // check if other user is banned if $other_user.permissions.check_banned() { let lang = get_lang!($jar, $data.0); diff --git a/crates/app/src/public/html/profile/settings.html b/crates/app/src/public/html/profile/settings.html index 832cada..d24444d 100644 --- a/crates/app/src/public/html/profile/settings.html +++ b/crates/app/src/public/html/profile/settings.html @@ -1216,6 +1216,14 @@ profile_settings, [ [[], "Privacy", "title"], + [ + [ + "require_account", + "Require an account to view my profile", + ], + "{{ profile.settings.require_account }}", + "checkbox", + ], [ [ "private_profile", diff --git a/crates/core/src/database/posts.rs b/crates/core/src/database/posts.rs index 3835797..1b1d76c 100644 --- a/crates/core/src/database/posts.rs +++ b/crates/core/src/database/posts.rs @@ -207,28 +207,31 @@ impl DataManager { continue; } - if let Some(is_following) = seen_user_follow_statuses.get(&(ua.id, ua1.id)) - { - if !is_following - && (ua.id != ua1.id) - && !ua1.permissions.check(FinePermission::MANAGE_POSTS) + if ua1.id != ua.id { + if let Some(is_following) = + seen_user_follow_statuses.get(&(ua.id, ua1.id)) { - // post owner is not following us - continue; - } - } else { - if self - .get_userfollow_by_initiator_receiver(ua.id, ua1.id) - .await - .is_err() - && !ua1.permissions.check(FinePermission::MANAGE_POSTS) - { - // post owner is not following us - seen_user_follow_statuses.insert((ua.id, ua1.id), false); - continue; - } + if !is_following + && (ua.id != ua1.id) + && !ua1.permissions.check(FinePermission::MANAGE_POSTS) + { + // post owner is not following us + continue; + } + } else { + if self + .get_userfollow_by_initiator_receiver(ua.id, ua1.id) + .await + .is_err() + && !ua1.permissions.check(FinePermission::MANAGE_POSTS) + { + // post owner is not following us + seen_user_follow_statuses.insert((ua.id, ua1.id), false); + continue; + } - seen_user_follow_statuses.insert((ua.id, ua1.id), true); + seen_user_follow_statuses.insert((ua.id, ua1.id), true); + } } } else { // private post, but not authenticated @@ -307,23 +310,26 @@ impl DataManager { continue; } - if let Some(is_following) = seen_user_follow_statuses.get(&(ua.id, user_id)) { - if !is_following && (ua.id != user_id) { - // post owner is not following us - continue; - } - } else { - if self - .get_userfollow_by_initiator_receiver(ua.id, user_id) - .await - .is_err() + if user_id != ua.id { + if let Some(is_following) = seen_user_follow_statuses.get(&(ua.id, user_id)) { - // post owner is not following us - seen_user_follow_statuses.insert((ua.id, user_id), false); - continue; - } + if !is_following && (ua.id != user_id) { + // post owner is not following us + continue; + } + } else { + if self + .get_userfollow_by_initiator_receiver(ua.id, user_id) + .await + .is_err() + { + // post owner is not following us + seen_user_follow_statuses.insert((ua.id, user_id), false); + continue; + } - seen_user_follow_statuses.insert((ua.id, user_id), true); + seen_user_follow_statuses.insert((ua.id, user_id), true); + } } } @@ -1302,6 +1308,11 @@ impl DataManager { self.incr_question_answer_count(y.context.answering).await?; } } + + // delete uploads + for upload in y.uploads { + self.delete_upload(upload).await?; + } } else { // incr parent comment count if let Some(replying_to) = y.replying_to { @@ -1323,6 +1334,8 @@ impl DataManager { self.decr_question_answer_count(y.context.answering).await?; } } + + // unfortunately, uploads will not be restored } // return diff --git a/crates/core/src/model/auth.rs b/crates/core/src/model/auth.rs index 89880ae..9cd761b 100644 --- a/crates/core/src/model/auth.rs +++ b/crates/core/src/model/auth.rs @@ -210,6 +210,9 @@ pub struct UserSettings { /// The mime type of the user's banner. #[serde(default = "mime_avif")] pub banner_mime: String, + /// Require an account to view the user's profile. + #[serde(default)] + pub require_account: bool, } fn mime_avif() -> String {