mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-26 06:11:26 +00:00
Fix name for description checker.
This commit is contained in:
parent
5143e0ec30
commit
a99cbbf5bb
4 changed files with 15 additions and 11 deletions
|
@ -36,7 +36,11 @@ use lemmy_utils::{
|
||||||
error::{LemmyErrorExt, LemmyErrorType, LemmyResult},
|
error::{LemmyErrorExt, LemmyErrorType, LemmyResult},
|
||||||
utils::{
|
utils::{
|
||||||
slurs::check_slurs,
|
slurs::check_slurs,
|
||||||
validation::{is_valid_actor_name, is_valid_body_field, site_description_length_check},
|
validation::{
|
||||||
|
is_valid_actor_name,
|
||||||
|
is_valid_body_field,
|
||||||
|
site_or_community_description_length_check,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -66,7 +70,7 @@ pub async fn create_community(
|
||||||
|
|
||||||
let description = data.description.clone();
|
let description = data.description.clone();
|
||||||
if let Some(desc) = &description {
|
if let Some(desc) = &description {
|
||||||
site_description_length_check(desc)?;
|
site_or_community_description_length_check(desc)?;
|
||||||
check_slurs(desc, &slur_regex)?;
|
check_slurs(desc, &slur_regex)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,8 +34,8 @@ use lemmy_utils::{
|
||||||
build_and_check_regex,
|
build_and_check_regex,
|
||||||
check_site_visibility_valid,
|
check_site_visibility_valid,
|
||||||
is_valid_body_field,
|
is_valid_body_field,
|
||||||
site_description_length_check,
|
|
||||||
site_name_length_check,
|
site_name_length_check,
|
||||||
|
site_or_community_description_length_check,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -167,7 +167,7 @@ fn validate_create_payload(local_site: &LocalSite, create_site: &CreateSite) ->
|
||||||
check_slurs(&create_site.name, &slur_regex)?;
|
check_slurs(&create_site.name, &slur_regex)?;
|
||||||
|
|
||||||
if let Some(desc) = &create_site.description {
|
if let Some(desc) = &create_site.description {
|
||||||
site_description_length_check(desc)?;
|
site_or_community_description_length_check(desc)?;
|
||||||
check_slurs(desc, &slur_regex)?;
|
check_slurs(desc, &slur_regex)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,8 +40,8 @@ use lemmy_utils::{
|
||||||
check_site_visibility_valid,
|
check_site_visibility_valid,
|
||||||
check_urls_are_valid,
|
check_urls_are_valid,
|
||||||
is_valid_body_field,
|
is_valid_body_field,
|
||||||
site_description_length_check,
|
|
||||||
site_name_length_check,
|
site_name_length_check,
|
||||||
|
site_or_community_description_length_check,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -219,7 +219,7 @@ fn validate_update_payload(local_site: &LocalSite, edit_site: &EditSite) -> Lemm
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(desc) = &edit_site.description {
|
if let Some(desc) = &edit_site.description {
|
||||||
site_description_length_check(desc)?;
|
site_or_community_description_length_check(desc)?;
|
||||||
check_slurs_opt(&edit_site.description, &slur_regex)?;
|
check_slurs_opt(&edit_site.description, &slur_regex)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -191,8 +191,8 @@ pub fn site_name_length_check(name: &str) -> LemmyResult<()> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks the site description length, the limit as defined in the DB.
|
/// Checks the site / community description length, the limit as defined in the DB.
|
||||||
pub fn site_description_length_check(description: &str) -> LemmyResult<()> {
|
pub fn site_or_community_description_length_check(description: &str) -> LemmyResult<()> {
|
||||||
max_length_check(
|
max_length_check(
|
||||||
description,
|
description,
|
||||||
SITE_DESCRIPTION_MAX_LENGTH,
|
SITE_DESCRIPTION_MAX_LENGTH,
|
||||||
|
@ -368,8 +368,8 @@ mod tests {
|
||||||
is_valid_matrix_id,
|
is_valid_matrix_id,
|
||||||
is_valid_post_title,
|
is_valid_post_title,
|
||||||
is_valid_url,
|
is_valid_url,
|
||||||
site_description_length_check,
|
|
||||||
site_name_length_check,
|
site_name_length_check,
|
||||||
|
site_or_community_description_length_check,
|
||||||
BIO_MAX_LENGTH,
|
BIO_MAX_LENGTH,
|
||||||
SITE_DESCRIPTION_MAX_LENGTH,
|
SITE_DESCRIPTION_MAX_LENGTH,
|
||||||
SITE_NAME_MAX_LENGTH,
|
SITE_NAME_MAX_LENGTH,
|
||||||
|
@ -537,14 +537,14 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_valid_site_description() {
|
fn test_valid_site_description() {
|
||||||
assert!(site_description_length_check(
|
assert!(site_or_community_description_length_check(
|
||||||
&(0..SITE_DESCRIPTION_MAX_LENGTH)
|
&(0..SITE_DESCRIPTION_MAX_LENGTH)
|
||||||
.map(|_| 'A')
|
.map(|_| 'A')
|
||||||
.collect::<String>()
|
.collect::<String>()
|
||||||
)
|
)
|
||||||
.is_ok());
|
.is_ok());
|
||||||
|
|
||||||
let invalid_result = site_description_length_check(
|
let invalid_result = site_or_community_description_length_check(
|
||||||
&(0..SITE_DESCRIPTION_MAX_LENGTH + 1)
|
&(0..SITE_DESCRIPTION_MAX_LENGTH + 1)
|
||||||
.map(|_| 'A')
|
.map(|_| 'A')
|
||||||
.collect::<String>(),
|
.collect::<String>(),
|
||||||
|
|
Loading…
Reference in a new issue