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_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);

View file

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

View file

@ -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

View file

@ -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 {