Change federation community restricted check to apply only locally (#5343)

* Revert "Fetch community mods synchronously (#5169)"

This reverts commit 542e59bcae.

* change restricted check (fixes #5337)
This commit is contained in:
Nutomic 2025-01-22 20:46:07 +00:00 committed by GitHub
parent af71cc55ab
commit 72b74679aa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 9 deletions

View file

@ -193,16 +193,10 @@ impl Object for ApubCommunity {
LanguageTag::to_language_id_multiple(group.language, &mut context.pool()).await?;
let timestamp = group.updated.or(group.published).unwrap_or_else(Utc::now);
let community: ApubCommunity = Community::insert_apub(&mut context.pool(), timestamp, &form)
.await?
.into();
let community = Community::insert_apub(&mut context.pool(), timestamp, &form).await?;
CommunityLanguage::update(&mut context.pool(), languages, community.id).await?;
// Need to fetch mods synchronously, otherwise fetching a post in community with
// `posting_restricted_to_mods` can fail if mods havent been fetched yet.
if let Some(moderators) = group.attributed_to {
moderators.dereference(&community, context).await.ok();
}
let community: ApubCommunity = community.into();
// These collections are not necessary for Lemmy to work, so ignore errors.
let community_ = community.clone();
@ -215,6 +209,9 @@ impl Object for ApubCommunity {
if let Some(featured) = group.featured {
featured.dereference(&community_, &context_).await.ok();
}
if let Some(moderators) = group.attributed_to {
moderators.dereference(&community_, &context_).await.ok();
}
Ok(())
});

View file

@ -177,7 +177,11 @@ impl Object for ApubPost {
async fn from_json(page: Page, context: &Data<Self::DataType>) -> LemmyResult<ApubPost> {
let creator = page.creator()?.dereference(context).await?;
let community = page.community(context).await?;
if community.posting_restricted_to_mods {
// Prevent posts from non-mod users in local, restricted community. If its a remote community
// then its possible that the restricted setting was enabled recently, so existing user posts
// should still be fetched.
if community.local && community.posting_restricted_to_mods {
CommunityModeratorView::check_is_community_moderator(
&mut context.pool(),
community.id,