Check for community ban when parsing post/comment (fixes #1287)
This commit is contained in:
parent
7649dd048b
commit
32c4d3224c
4 changed files with 34 additions and 2 deletions
|
@ -259,7 +259,7 @@ async fn handle_undo_follow(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
async fn check_community_or_site_ban(
|
||||
pub(crate) async fn check_community_or_site_ban(
|
||||
user: &User_,
|
||||
community: &Community,
|
||||
pool: &DbPool,
|
||||
|
|
|
@ -7,6 +7,7 @@ use crate::{
|
|||
},
|
||||
objects::{
|
||||
check_object_domain,
|
||||
check_object_for_community_or_site_ban,
|
||||
create_tombstone,
|
||||
get_object_from_apub,
|
||||
get_source_markdown_value,
|
||||
|
@ -101,6 +102,8 @@ impl FromApub for Comment {
|
|||
expected_domain: Option<Url>,
|
||||
request_counter: &mut i32,
|
||||
) -> Result<Comment, LemmyError> {
|
||||
check_object_for_community_or_site_ban(note, context, request_counter).await?;
|
||||
|
||||
let comment: Comment =
|
||||
get_object_from_apub(note, context, expected_domain, request_counter).await?;
|
||||
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
use crate::check_is_apub_id_valid;
|
||||
use crate::{
|
||||
check_is_apub_id_valid,
|
||||
fetcher::{get_or_fetch_and_upsert_community, get_or_fetch_and_upsert_user},
|
||||
inbox::community_inbox::check_community_or_site_ban,
|
||||
};
|
||||
use activitystreams::{
|
||||
base::{AsBase, BaseExt, ExtendsExt},
|
||||
markers::Base,
|
||||
|
@ -205,3 +209,26 @@ where
|
|||
Ok(to)
|
||||
}
|
||||
}
|
||||
|
||||
pub(in crate::objects) async fn check_object_for_community_or_site_ban<T, Kind>(
|
||||
object: &T,
|
||||
context: &LemmyContext,
|
||||
request_counter: &mut i32,
|
||||
) -> Result<(), LemmyError>
|
||||
where
|
||||
T: ObjectExt<Kind>,
|
||||
{
|
||||
let user_id = object
|
||||
.attributed_to()
|
||||
.context(location_info!())?
|
||||
.as_single_xsd_any_uri()
|
||||
.context(location_info!())?;
|
||||
let user = get_or_fetch_and_upsert_user(user_id, context, request_counter).await?;
|
||||
let community_id = object
|
||||
.to()
|
||||
.context(location_info!())?
|
||||
.as_single_xsd_any_uri()
|
||||
.context(location_info!())?;
|
||||
let community = get_or_fetch_and_upsert_community(community_id, context, request_counter).await?;
|
||||
check_community_or_site_ban(&user, &community, context.pool()).await
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ use crate::{
|
|||
fetcher::{get_or_fetch_and_upsert_community, get_or_fetch_and_upsert_user},
|
||||
objects::{
|
||||
check_object_domain,
|
||||
check_object_for_community_or_site_ban,
|
||||
create_tombstone,
|
||||
get_object_from_apub,
|
||||
get_source_markdown_value,
|
||||
|
@ -112,6 +113,7 @@ impl FromApub for Post {
|
|||
expected_domain: Option<Url>,
|
||||
request_counter: &mut i32,
|
||||
) -> Result<Post, LemmyError> {
|
||||
check_object_for_community_or_site_ban(page, context, request_counter).await?;
|
||||
get_object_from_apub(page, context, expected_domain, request_counter).await
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue