diff options
author | Dessalines <tyhou13@gmx.com> | 2020-02-02 22:51:54 -0500 |
---|---|---|
committer | Dessalines <tyhou13@gmx.com> | 2020-02-02 22:51:54 -0500 |
commit | ee2038a75a137ad53632d76b42588605b52ac422 (patch) | |
tree | 7b53f8a9a447cdc5781b07742db7d9590971af96 /server/src/api/post.rs | |
parent | a2267aa0560731ba090091cd946922cdaac72354 (diff) |
Returning specific slurs from slur filter on failure. Fixes #463
Diffstat (limited to 'server/src/api/post.rs')
-rw-r--r-- | server/src/api/post.rs | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/server/src/api/post.rs b/server/src/api/post.rs index 086705bc..bd276be5 100644 --- a/server/src/api/post.rs +++ b/server/src/api/post.rs @@ -88,8 +88,14 @@ impl Perform<PostResponse> for Oper<CreatePost> { Err(_e) => return Err(APIError::err("not_logged_in").into()), }; - if has_slurs(&data.name) || (data.body.is_some() && has_slurs(&data.body.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 Some(body) = &data.body { + if let Err(slurs) = slur_check(body) { + return Err(APIError::err(&slurs_vec_to_str(slurs)).into()); + } } let user_id = claims.id; @@ -298,8 +304,15 @@ impl Perform<PostResponse> for Oper<CreatePostLike> { impl Perform<PostResponse> for Oper<EditPost> { fn perform(&self, conn: &PgConnection) -> Result<PostResponse, Error> { let data: &EditPost = &self.data; - if has_slurs(&data.name) || (data.body.is_some() && has_slurs(&data.body.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 Some(body) = &data.body { + if let Err(slurs) = slur_check(body) { + return Err(APIError::err(&slurs_vec_to_str(slurs)).into()); + } } let claims = match Claims::decode(&data.auth) { |