add: allow users to block users who have blocked them/private users

fix: anonymous post page panic
add: allow users to select home timeline
This commit is contained in:
trisua 2025-04-24 16:40:03 -04:00
parent 2460e2f8c5
commit d42375441f
15 changed files with 313 additions and 122 deletions

View file

@ -1,5 +1,8 @@
use super::{render_error, PaginatedQuery, ProfileQuery};
use crate::{assets::initial_context, get_lang, get_user_from_token, sanitize::clean_settings, State};
use crate::{
assets::initial_context, check_user_blocked_or_private, get_lang, get_user_from_token,
sanitize::clean_settings, State,
};
use axum::{
Extension,
extract::{Path, Query},
@ -173,69 +176,7 @@ pub async fn posts_request(
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
};
// check if we're blocked
if let Some(ref ua) = user {
if data
.0
.get_userblock_by_initiator_receiver(other_user.id, ua.id)
.await
.is_ok()
{
return Err(Html(
render_error(Error::NotAllowed, &jar, &data, &user).await,
));
}
}
// check for private profile
if other_user.settings.private_profile {
if let Some(ref ua) = user {
if (ua.id != other_user.id)
&& !ua.permissions.check(FinePermission::MANAGE_USERS)
&& data
.0
.get_userfollow_by_initiator_receiver(other_user.id, ua.id)
.await
.is_err()
{
let lang = get_lang!(jar, data.0);
let mut context = initial_context(&data.0.0, lang, &user).await;
context.insert("profile", &other_user);
context.insert(
"follow_requested",
&data
.0
.get_request_by_id_linked_asset(ua.id, other_user.id)
.await
.is_ok(),
);
context.insert(
"is_following",
&data
.0
.get_userfollow_by_initiator_receiver(ua.id, other_user.id)
.await
.is_ok(),
);
return Ok(Html(
data.1.render("profile/private.html", &context).unwrap(),
));
}
} else {
let lang = get_lang!(jar, data.0);
let mut context = initial_context(&data.0.0, lang, &user).await;
context.insert("profile", &other_user);
context.insert("follow_requested", &false);
context.insert("is_following", &false);
return Ok(Html(
data.1.render("profile/private.html", &context).unwrap(),
));
}
}
check_user_blocked_or_private!(user, other_user, data, jar);
// check for warning
if props.warning {
@ -371,19 +312,7 @@ pub async fn following_request(
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
};
// check if we're blocked
if let Some(ref ua) = user {
if data
.0
.get_userblock_by_initiator_receiver(other_user.id, ua.id)
.await
.is_ok()
{
return Err(Html(
render_error(Error::NotAllowed, &jar, &data, &user).await,
));
}
}
check_user_blocked_or_private!(user, other_user, data, jar);
// check for private profile
if other_user.settings.private_profile {
@ -498,40 +427,7 @@ pub async fn followers_request(
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
};
// check if we're blocked
if let Some(ref ua) = user {
if data
.0
.get_userblock_by_initiator_receiver(other_user.id, ua.id)
.await
.is_ok()
{
return Err(Html(
render_error(Error::NotAllowed, &jar, &data, &user).await,
));
}
}
// check for private profile
if other_user.settings.private_profile {
if let Some(ref ua) = user {
if ua.id != other_user.id
&& data
.0
.get_userfollow_by_initiator_receiver(other_user.id, ua.id)
.await
.is_err()
{
return Err(Html(
render_error(Error::NotAllowed, &jar, &data, &user).await,
));
}
} else {
return Err(Html(
render_error(Error::NotAllowed, &jar, &data, &user).await,
));
}
}
check_user_blocked_or_private!(user, other_user, data, jar);
// fetch data
let list = match data