Check markdown for tagline

This commit is contained in:
Freakazoid182 2024-04-05 23:20:59 +02:00
parent ead51517e4
commit abdfc90dbe
2 changed files with 15 additions and 5 deletions

View file

@ -18,7 +18,7 @@ pub struct CreateTagline {
/// Update a tagline
pub struct UpdateTagline {
pub id: TaglineId,
pub content: String,
pub content: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]

View file

@ -3,15 +3,18 @@ use actix_web::web::Json;
use lemmy_api_common::{
context::LemmyContext,
tagline::{TaglineResponse, UpdateTagline},
utils::is_admin,
utils::{get_url_blocklist, is_admin, local_site_to_slur_regex, process_markdown_opt},
};
use lemmy_db_schema::{
source::tagline::{Tagline, TaglineUpdateForm},
source::{
local_site::LocalSite,
tagline::{Tagline, TaglineUpdateForm},
},
traits::Crud,
utils::naive_now,
};
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 update_tagline(
@ -22,8 +25,15 @@ pub async fn update_tagline(
// 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 = TaglineUpdateForm {
content: Some(data.content.to_string()),
content,
updated: Some(Some(naive_now())),
};