From ee2038a75a137ad53632d76b42588605b52ac422 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sun, 2 Feb 2020 22:51:54 -0500 Subject: Returning specific slurs from slur filter on failure. Fixes #463 --- server/src/api/community.rs | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'server/src/api/community.rs') diff --git a/server/src/api/community.rs b/server/src/api/community.rs index 80cc2b65..936e54cd 100644 --- a/server/src/api/community.rs +++ b/server/src/api/community.rs @@ -176,11 +176,18 @@ impl Perform for Oper { Err(_e) => return Err(APIError::err("not_logged_in").into()), }; - if has_slurs(&data.name) - || has_slurs(&data.title) - || (data.description.is_some() && has_slurs(&data.description.to_owned().unwrap())) - { - return Err(APIError::err("no_slurs").into()); + if let Err(slurs) = slur_check(&data.name) { + return Err(APIError::err(&slurs_vec_to_str(slurs)).into()); + } + + if let Err(slurs) = slur_check(&data.title) { + return Err(APIError::err(&slurs_vec_to_str(slurs)).into()); + } + + if let Some(description) = &data.description { + if let Err(slurs) = slur_check(description) { + return Err(APIError::err(&slurs_vec_to_str(slurs)).into()); + } } let user_id = claims.id; @@ -242,8 +249,18 @@ impl Perform for Oper { fn perform(&self, conn: &PgConnection) -> Result { let data: &EditCommunity = &self.data; - if has_slurs(&data.name) || has_slurs(&data.title) { - return Err(APIError::err("no_slurs").into()); + if let Err(slurs) = slur_check(&data.name) { + return Err(APIError::err(&slurs_vec_to_str(slurs)).into()); + } + + if let Err(slurs) = slur_check(&data.title) { + return Err(APIError::err(&slurs_vec_to_str(slurs)).into()); + } + + if let Some(description) = &data.description { + if let Err(slurs) = slur_check(description) { + return Err(APIError::err(&slurs_vec_to_str(slurs)).into()); + } } let claims = match Claims::decode(&data.auth) { -- cgit v1.2.3