add: ability to require account to view profile

This commit is contained in:
trisua 2025-05-16 21:29:25 -04:00
parent dd4f8b6d58
commit 741fe1c986
4 changed files with 74 additions and 35 deletions

View file

@ -98,6 +98,21 @@ macro_rules! get_lang {
#[macro_export] #[macro_export]
macro_rules! check_user_blocked_or_private { macro_rules! check_user_blocked_or_private {
($user:ident, $other_user:ident, $data:ident, $jar:ident) => { ($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 // check if other user is banned
if $other_user.permissions.check_banned() { if $other_user.permissions.check_banned() {
let lang = get_lang!($jar, $data.0); let lang = get_lang!($jar, $data.0);

View file

@ -1216,6 +1216,14 @@
profile_settings, profile_settings,
[ [
[[], "Privacy", "title"], [[], "Privacy", "title"],
[
[
"require_account",
"Require an account to view my profile",
],
"{{ profile.settings.require_account }}",
"checkbox",
],
[ [
[ [
"private_profile", "private_profile",

View file

@ -207,7 +207,9 @@ impl DataManager {
continue; continue;
} }
if let Some(is_following) = seen_user_follow_statuses.get(&(ua.id, ua1.id)) if ua1.id != ua.id {
if let Some(is_following) =
seen_user_follow_statuses.get(&(ua.id, ua1.id))
{ {
if !is_following if !is_following
&& (ua.id != ua1.id) && (ua.id != ua1.id)
@ -230,6 +232,7 @@ impl DataManager {
seen_user_follow_statuses.insert((ua.id, ua1.id), true); seen_user_follow_statuses.insert((ua.id, ua1.id), true);
} }
}
} else { } else {
// private post, but not authenticated // private post, but not authenticated
continue; continue;
@ -307,7 +310,9 @@ impl DataManager {
continue; continue;
} }
if let Some(is_following) = seen_user_follow_statuses.get(&(ua.id, user_id)) { if user_id != ua.id {
if let Some(is_following) = seen_user_follow_statuses.get(&(ua.id, user_id))
{
if !is_following && (ua.id != user_id) { if !is_following && (ua.id != user_id) {
// post owner is not following us // post owner is not following us
continue; continue;
@ -326,6 +331,7 @@ impl DataManager {
seen_user_follow_statuses.insert((ua.id, user_id), true); seen_user_follow_statuses.insert((ua.id, user_id), true);
} }
} }
}
// ... // ...
let community = self.get_community_by_id(community).await?; let community = self.get_community_by_id(community).await?;
@ -1302,6 +1308,11 @@ impl DataManager {
self.incr_question_answer_count(y.context.answering).await?; self.incr_question_answer_count(y.context.answering).await?;
} }
} }
// delete uploads
for upload in y.uploads {
self.delete_upload(upload).await?;
}
} else { } else {
// incr parent comment count // incr parent comment count
if let Some(replying_to) = y.replying_to { if let Some(replying_to) = y.replying_to {
@ -1323,6 +1334,8 @@ impl DataManager {
self.decr_question_answer_count(y.context.answering).await?; self.decr_question_answer_count(y.context.answering).await?;
} }
} }
// unfortunately, uploads will not be restored
} }
// return // return

View file

@ -210,6 +210,9 @@ pub struct UserSettings {
/// The mime type of the user's banner. /// The mime type of the user's banner.
#[serde(default = "mime_avif")] #[serde(default = "mime_avif")]
pub banner_mime: String, pub banner_mime: String,
/// Require an account to view the user's profile.
#[serde(default)]
pub require_account: bool,
} }
fn mime_avif() -> String { fn mime_avif() -> String {