mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-10-30 17:20:02 +00:00
Throw error when non-mod posts to mod-only comm (#4966)
This commit is contained in:
parent
128e78f7c2
commit
ea18d462b0
1 changed files with 17 additions and 4 deletions
|
@ -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?;
|
||||
|
|
Loading…
Reference in a new issue