diff options
author | Felix Ableitner <me@nutomic.com> | 2020-01-02 12:30:00 +0100 |
---|---|---|
committer | Felix Ableitner <me@nutomic.com> | 2020-01-02 12:30:00 +0100 |
commit | d08e09fbdc9d0e50e4b81410ae513b034170c36b (patch) | |
tree | a2cb974941f730960594dd9c66e72ed52f85c580 /server/src/api/comment.rs | |
parent | 081d8ddd127ccd1ed58b275424837b24eef52070 (diff) |
Apply changes suggested by cargo clippy (fixes #395)
Diffstat (limited to 'server/src/api/comment.rs')
-rw-r--r-- | server/src/api/comment.rs | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/server/src/api/comment.rs b/server/src/api/comment.rs index 9a057f80..ed658985 100644 --- a/server/src/api/comment.rs +++ b/server/src/api/comment.rs @@ -51,7 +51,7 @@ impl Perform<CommentResponse> for Oper<CreateComment> { let claims = match Claims::decode(&data.auth) { Ok(claims) => claims.claims, - Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?, + Err(_e) => return Err(APIError::err(&self.op, "not_logged_in").into()), }; let user_id = claims.id; @@ -59,12 +59,12 @@ impl Perform<CommentResponse> for Oper<CreateComment> { // Check for a community ban let post = Post::read(&conn, data.post_id)?; if CommunityUserBanView::get(&conn, user_id, post.community_id).is_ok() { - return Err(APIError::err(&self.op, "community_ban"))?; + return Err(APIError::err(&self.op, "community_ban").into()); } // Check for a site ban if UserView::read(&conn, user_id)?.banned { - return Err(APIError::err(&self.op, "site_ban"))?; + return Err(APIError::err(&self.op, "site_ban").into()); } let content_slurs_removed = remove_slurs(&data.content.to_owned()); @@ -82,14 +82,14 @@ impl Perform<CommentResponse> for Oper<CreateComment> { let inserted_comment = match Comment::create(&conn, &comment_form) { Ok(comment) => comment, - Err(_e) => return Err(APIError::err(&self.op, "couldnt_create_comment"))?, + Err(_e) => return Err(APIError::err(&self.op, "couldnt_create_comment").into()), }; // Scan the comment for user mentions, add those rows let extracted_usernames = extract_usernames(&comment_form.content); for username_mention in &extracted_usernames { - let mention_user = User_::read_from_name(&conn, username_mention.to_string()); + let mention_user = User_::read_from_name(&conn, (*username_mention).to_string()); if mention_user.is_ok() { let mention_user_id = mention_user?.id; @@ -124,7 +124,7 @@ impl Perform<CommentResponse> for Oper<CreateComment> { let _inserted_like = match CommentLike::like(&conn, &like_form) { Ok(like) => like, - Err(_e) => return Err(APIError::err(&self.op, "couldnt_like_comment"))?, + Err(_e) => return Err(APIError::err(&self.op, "couldnt_like_comment").into()), }; let comment_view = CommentView::read(&conn, inserted_comment.id, Some(user_id))?; @@ -143,7 +143,7 @@ impl Perform<CommentResponse> for Oper<EditComment> { let claims = match Claims::decode(&data.auth) { Ok(claims) => claims.claims, - Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?, + Err(_e) => return Err(APIError::err(&self.op, "not_logged_in").into()), }; let user_id = claims.id; @@ -163,17 +163,17 @@ impl Perform<CommentResponse> for Oper<EditComment> { editors.append(&mut UserView::admins(&conn)?.into_iter().map(|a| a.id).collect()); if !editors.contains(&user_id) { - return Err(APIError::err(&self.op, "no_comment_edit_allowed"))?; + return Err(APIError::err(&self.op, "no_comment_edit_allowed").into()); } // Check for a community ban if CommunityUserBanView::get(&conn, user_id, orig_comment.community_id).is_ok() { - return Err(APIError::err(&self.op, "community_ban"))?; + return Err(APIError::err(&self.op, "community_ban").into()); } // Check for a site ban if UserView::read(&conn, user_id)?.banned { - return Err(APIError::err(&self.op, "site_ban"))?; + return Err(APIError::err(&self.op, "site_ban").into()); } } @@ -196,14 +196,14 @@ impl Perform<CommentResponse> for Oper<EditComment> { let _updated_comment = match Comment::update(&conn, data.edit_id, &comment_form) { Ok(comment) => comment, - Err(_e) => return Err(APIError::err(&self.op, "couldnt_update_comment"))?, + Err(_e) => return Err(APIError::err(&self.op, "couldnt_update_comment").into()), }; // Scan the comment for user mentions, add those rows let extracted_usernames = extract_usernames(&comment_form.content); for username_mention in &extracted_usernames { - let mention_user = User_::read_from_name(&conn, username_mention.to_string()); + let mention_user = User_::read_from_name(&conn, (*username_mention).to_string()); if mention_user.is_ok() { let mention_user_id = mention_user?.id; @@ -255,7 +255,7 @@ impl Perform<CommentResponse> for Oper<SaveComment> { let claims = match Claims::decode(&data.auth) { Ok(claims) => claims.claims, - Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?, + Err(_e) => return Err(APIError::err(&self.op, "not_logged_in").into()), }; let user_id = claims.id; @@ -268,12 +268,12 @@ impl Perform<CommentResponse> for Oper<SaveComment> { if data.save { match CommentSaved::save(&conn, &comment_saved_form) { Ok(comment) => comment, - Err(_e) => return Err(APIError::err(&self.op, "couldnt_save_comment"))?, + Err(_e) => return Err(APIError::err(&self.op, "couldnt_save_comment").into()), }; } else { match CommentSaved::unsave(&conn, &comment_saved_form) { Ok(comment) => comment, - Err(_e) => return Err(APIError::err(&self.op, "couldnt_save_comment"))?, + Err(_e) => return Err(APIError::err(&self.op, "couldnt_save_comment").into()), }; } @@ -293,7 +293,7 @@ impl Perform<CommentResponse> for Oper<CreateCommentLike> { let claims = match Claims::decode(&data.auth) { Ok(claims) => claims.claims, - Err(_e) => return Err(APIError::err(&self.op, "not_logged_in"))?, + Err(_e) => return Err(APIError::err(&self.op, "not_logged_in").into()), }; let user_id = claims.id; @@ -301,20 +301,20 @@ impl Perform<CommentResponse> for Oper<CreateCommentLike> { // Don't do a downvote if site has downvotes disabled if data.score == -1 { let site = SiteView::read(&conn)?; - if site.enable_downvotes == false { - return Err(APIError::err(&self.op, "downvotes_disabled"))?; + if !site.enable_downvotes { + return Err(APIError::err(&self.op, "downvotes_disabled").into()); } } // Check for a community ban let post = Post::read(&conn, data.post_id)?; if CommunityUserBanView::get(&conn, user_id, post.community_id).is_ok() { - return Err(APIError::err(&self.op, "community_ban"))?; + return Err(APIError::err(&self.op, "community_ban").into()); } // Check for a site ban if UserView::read(&conn, user_id)?.banned { - return Err(APIError::err(&self.op, "site_ban"))?; + return Err(APIError::err(&self.op, "site_ban").into()); } let like_form = CommentLikeForm { @@ -332,7 +332,7 @@ impl Perform<CommentResponse> for Oper<CreateCommentLike> { if do_add { let _inserted_like = match CommentLike::like(&conn, &like_form) { Ok(like) => like, - Err(_e) => return Err(APIError::err(&self.op, "couldnt_like_comment"))?, + Err(_e) => return Err(APIError::err(&self.op, "couldnt_like_comment").into()), }; } |