Throw error when non-mod posts to mod-only comm (#4966)

This commit is contained in:
flamingos-cant 2024-08-13 19:56:26 +01:00 committed by GitHub
parent 128e78f7c2
commit ea18d462b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -41,7 +41,11 @@ use lemmy_db_views_actor::structs::CommunityModeratorView;
use lemmy_utils::{
error::{LemmyError, LemmyErrorType, LemmyResult},
spawn_try_task,
utils::{markdown::markdown_to_html, slurs::check_slurs_opt, validation::is_valid_url},
utils::{
markdown::markdown_to_html,
slurs::check_slurs_opt,
validation::{is_url_blocked, is_valid_url},
},
};
use std::ops::Deref;
use stringreader::StringReader;
@ -180,8 +184,15 @@ impl Object for ApubPost {
let creator = page.creator()?.dereference(context).await?;
let community = page.community(context).await?;
if community.posting_restricted_to_mods {
CommunityModeratorView::is_community_moderator(&mut context.pool(), community.id, creator.id)
.await?;
let is_mod = CommunityModeratorView::is_community_moderator(
&mut context.pool(),
community.id,
creator.id,
)
.await?;
if !is_mod {
Err(LemmyErrorType::OnlyModsCanPostInCommunity)?
}
}
let mut name = page
.name
@ -220,14 +231,16 @@ impl Object for ApubPost {
None
};
let url_blocklist = get_url_blocklist(context).await?;
if let Some(url) = &url {
is_url_blocked(url, &url_blocklist)?;
is_valid_url(url)?;
}
let alt_text = first_attachment.cloned().and_then(Attachment::alt_text);
let slur_regex = &local_site_opt_to_slur_regex(&local_site);
let url_blocklist = get_url_blocklist(context).await?;
let body = read_from_string_or_source_opt(&page.content, &page.media_type, &page.source);
let body = process_markdown_opt(&body, slur_regex, &url_blocklist, context).await?;