From 4ffb3e007cc8b548b8373394bc793abf64c70a58 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 14 Mar 2024 16:33:22 +0100 Subject: [PATCH] Dont allow admins to post in community with `posting_restricted_to_mods` (fixes #3571) --- crates/api_crud/src/post/create.rs | 7 +++---- crates/apub/src/objects/post.rs | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/crates/api_crud/src/post/create.rs b/crates/api_crud/src/post/create.rs index c52cfaf80..ddadf8c0f 100644 --- a/crates/api_crud/src/post/create.rs +++ b/crates/api_crud/src/post/create.rs @@ -16,7 +16,7 @@ use lemmy_api_common::{ proxy_image_link_opt_apub, EndpointType, }, -}; +};use lemmy_db_views_actor::structs::CommunityModeratorView; use lemmy_db_schema::{ impls::actor_language::default_post_language, source::{ @@ -29,7 +29,6 @@ use lemmy_db_schema::{ CommunityVisibility, }; use lemmy_db_views::structs::LocalUserView; -use lemmy_db_views_actor::structs::CommunityView; use lemmy_utils::{ error::{LemmyError, LemmyErrorExt, LemmyErrorType}, spawn_try_task, @@ -83,10 +82,10 @@ pub async fn create_post( let community = Community::read(&mut context.pool(), community_id).await?; if community.posting_restricted_to_mods { let community_id = data.community_id; - let is_mod = CommunityView::is_mod_or_admin( + let is_mod = CommunityModeratorView::is_community_moderator( &mut context.pool(), - local_user_view.local_user.person_id, community_id, + local_user_view.local_user.person_id, ) .await?; if !is_mod { diff --git a/crates/apub/src/objects/post.rs b/crates/apub/src/objects/post.rs index 8b8ae093b..403f3775b 100644 --- a/crates/apub/src/objects/post.rs +++ b/crates/apub/src/objects/post.rs @@ -26,7 +26,6 @@ use lemmy_api_common::{ context::LemmyContext, request::fetch_link_metadata_opt, utils::{ - is_mod_or_admin, local_site_opt_to_sensitive, local_site_opt_to_slur_regex, process_markdown_opt, @@ -50,6 +49,7 @@ use lemmy_utils::{ use std::ops::Deref; use stringreader::StringReader; use url::Url; +use lemmy_db_views_actor::structs::CommunityModeratorView; const MAX_TITLE_LENGTH: usize = 200; @@ -179,7 +179,7 @@ impl Object for ApubPost { let creator = page.creator()?.dereference(context).await?; let community = page.community(context).await?; if community.posting_restricted_to_mods { - is_mod_or_admin(&mut context.pool(), &creator, community.id).await?; + CommunityModeratorView::is_community_moderator(&mut context.pool(), community.id, creator.id).await?; } let mut name = page .name