Validate markdown on tagline

This commit is contained in:
Freakazoid182 2024-04-05 23:34:43 +02:00
parent abdfc90dbe
commit b2b8c43757
3 changed files with 12 additions and 6 deletions

View file

@ -9,7 +9,7 @@ use ts_rs::TS;
#[cfg_attr(feature = "full", ts(export))]
/// Create a tagline
pub struct CreateTagline {
pub content: String,
pub content: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]

View file

@ -3,7 +3,7 @@ use actix_web::web::Json;
use lemmy_api_common::{
context::LemmyContext,
tagline::{CreateTagline, TaglineResponse},
utils::is_admin,
utils::{get_url_blocklist, is_admin, local_site_to_slur_regex, process_markdown_opt},
};
use lemmy_db_schema::{
source::{
@ -13,7 +13,7 @@ use lemmy_db_schema::{
traits::Crud,
};
use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::error::LemmyError;
use lemmy_utils::{error::LemmyError, utils::validation::is_valid_body_field};
#[tracing::instrument(skip(context))]
pub async fn create_tagline(
@ -21,13 +21,19 @@ pub async fn create_tagline(
context: Data<LemmyContext>,
local_user_view: LocalUserView,
) -> Result<Json<TaglineResponse>, LemmyError> {
let local_site = LocalSite::read(&mut context.pool()).await?;
// Make sure user is an admin
is_admin(&local_user_view)?;
let local_site = LocalSite::read(&mut context.pool()).await?;
let slur_regex = local_site_to_slur_regex(&local_site);
let url_blocklist = get_url_blocklist(&context).await?;
let content = process_markdown_opt(&data.content, &slur_regex, &url_blocklist, &context).await?;
is_valid_body_field(&content, false)?;
let tagline_form = TaglineInsertForm {
local_site_id: local_site.id,
content: data.content.to_string(),
content,
};
let tagline = Tagline::create(&mut context.pool(), &tagline_form).await?;

View file

@ -34,7 +34,7 @@ pub struct Tagline {
#[cfg_attr(feature = "full", diesel(table_name = tagline))]
pub struct TaglineInsertForm {
pub local_site_id: LocalSiteId,
pub content: String,
pub content: Option<String>,
}
#[derive(Clone, Default)]