fix: check blocks when adding users to chats

This commit is contained in:
trisua 2025-09-03 17:17:49 -04:00
parent 82eafdadb3
commit 1c1eb3be5d
2 changed files with 9 additions and 9 deletions

View file

@ -3,6 +3,7 @@ use crate::{
database::DataManager,
get_user_from_token,
model::{Chat, ChatStyle, GroupChatInfo, SocketMessage, SocketMethod},
routes::pages::misc::check_user_is_blocked,
};
use axum::{
Extension, Json,
@ -87,6 +88,10 @@ pub async fn create_request(
continue;
}
if check_user_is_blocked(&x, &user, data).await {
continue;
}
x.id
}
Err(e) => return Json(e.into()),
@ -170,12 +175,7 @@ pub async fn add_member_request(
Err(e) => return Json(e.into()),
};
if data
.2
.get_userblock_by_initiator_receiver(other_user.id, user.id)
.await
.is_ok()
{
if check_user_is_blocked(&other_user, &user, data).await {
return Json(Error::NotAllowed.into());
}

View file

@ -57,7 +57,7 @@ pub async fn login_request(jar: CookieJar, Extension(data): Extension<State>) ->
)
}
async fn check_user_is_blocked(user: &User, other_user: &User, data: &DataManager) -> bool {
pub async fn check_user_is_blocked(user: &User, other_user: &User, data: &DataManager) -> bool {
(data
.2
.get_userblock_by_initiator_receiver(other_user.id, user.id)
@ -71,7 +71,7 @@ async fn check_user_is_blocked(user: &User, other_user: &User, data: &DataManage
&& !user.permissions.check(FinePermission::MANAGE_USERS)
}
async fn check_user_blocked_or_private(
pub async fn check_user_blocked_or_private(
user: &Option<User>,
other_user: &User,
data: &DataManager,
@ -86,7 +86,7 @@ async fn check_user_blocked_or_private(
{
// private profile and other_user isn't following user
return Err(Error::NotAllowed);
} else if check_user_is_blocked(ua, other_user, data).await {
} else if check_user_is_blocked(other_user, ua, data).await {
// blocked
return Err(Error::NotAllowed);
}