summaryrefslogtreecommitdiffstats
path: root/server/src/api/post.rs
diff options
context:
space:
mode:
authorFelix Ableitner <me@nutomic.com>2020-01-02 12:30:00 +0100
committerFelix Ableitner <me@nutomic.com>2020-01-02 12:30:00 +0100
commitd08e09fbdc9d0e50e4b81410ae513b034170c36b (patch)
treea2cb974941f730960594dd9c66e72ed52f85c580 /server/src/api/post.rs
parent081d8ddd127ccd1ed58b275424837b24eef52070 (diff)
Apply changes suggested by cargo clippy (fixes #395)
Diffstat (limited to 'server/src/api/post.rs')
-rw-r--r--server/src/api/post.rs52
1 files changed, 26 insertions, 26 deletions
diff --git a/server/src/api/post.rs b/server/src/api/post.rs
index 4b2395a8..5bc31def 100644
--- a/server/src/api/post.rs
+++ b/server/src/api/post.rs
@@ -93,23 +93,23 @@ impl Perform<PostResponse> for Oper<CreatePost> {
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()),
};
if has_slurs(&data.name) || (data.body.is_some() && has_slurs(&data.body.to_owned().unwrap())) {
- return Err(APIError::err(&self.op, "no_slurs"))?;
+ return Err(APIError::err(&self.op, "no_slurs").into());
}
let user_id = claims.id;
// Check for a community ban
if CommunityUserBanView::get(&conn, user_id, data.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 post_form = PostForm {
@@ -128,7 +128,7 @@ impl Perform<PostResponse> for Oper<CreatePost> {
let inserted_post = match Post::create(&conn, &post_form) {
Ok(post) => post,
- Err(_e) => return Err(APIError::err(&self.op, "couldnt_create_post"))?,
+ Err(_e) => return Err(APIError::err(&self.op, "couldnt_create_post").into()),
};
// They like their own post by default
@@ -141,13 +141,13 @@ impl Perform<PostResponse> for Oper<CreatePost> {
// Only add the like if the score isnt 0
let _inserted_like = match PostLike::like(&conn, &like_form) {
Ok(like) => like,
- Err(_e) => return Err(APIError::err(&self.op, "couldnt_like_post"))?,
+ Err(_e) => return Err(APIError::err(&self.op, "couldnt_like_post").into()),
};
// Refetch the view
let post_view = match PostView::read(&conn, inserted_post.id, Some(user_id)) {
Ok(post) => post,
- Err(_e) => return Err(APIError::err(&self.op, "couldnt_find_post"))?,
+ Err(_e) => return Err(APIError::err(&self.op, "couldnt_find_post").into()),
};
Ok(PostResponse {
@@ -175,7 +175,7 @@ impl Perform<GetPostResponse> for Oper<GetPost> {
let post_view = match PostView::read(&conn, data.id, user_id) {
Ok(post) => post,
- Err(_e) => return Err(APIError::err(&self.op, "couldnt_find_post"))?,
+ Err(_e) => return Err(APIError::err(&self.op, "couldnt_find_post").into()),
};
let comments = CommentQueryBuilder::create(&conn)
@@ -243,7 +243,7 @@ impl Perform<GetPostsResponse> for Oper<GetPosts> {
.list()
{
Ok(posts) => posts,
- Err(_e) => return Err(APIError::err(&self.op, "couldnt_get_posts"))?,
+ Err(_e) => return Err(APIError::err(&self.op, "couldnt_get_posts").into()),
};
Ok(GetPostsResponse {
@@ -260,7 +260,7 @@ impl Perform<CreatePostLikeResponse> for Oper<CreatePostLike> {
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,20 +268,20 @@ impl Perform<CreatePostLikeResponse> for Oper<CreatePostLike> {
// 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 = PostLikeForm {
@@ -294,17 +294,17 @@ impl Perform<CreatePostLikeResponse> for Oper<CreatePostLike> {
PostLike::remove(&conn, &like_form)?;
// Only add the like if the score isnt 0
- let do_add = &like_form.score != &0 && (&like_form.score == &1 || &like_form.score == &-1);
+ let do_add = like_form.score != 0 && (like_form.score == 1 || like_form.score == -1);
if do_add {
let _inserted_like = match PostLike::like(&conn, &like_form) {
Ok(like) => like,
- Err(_e) => return Err(APIError::err(&self.op, "couldnt_like_post"))?,
+ Err(_e) => return Err(APIError::err(&self.op, "couldnt_like_post").into()),
};
}
let post_view = match PostView::read(&conn, data.post_id, Some(user_id)) {
Ok(post) => post,
- Err(_e) => return Err(APIError::err(&self.op, "couldnt_find_post"))?,
+ Err(_e) => return Err(APIError::err(&self.op, "couldnt_find_post").into()),
};
// just output the score
@@ -319,14 +319,14 @@ impl Perform<PostResponse> for Oper<EditPost> {
fn perform(&self) -> 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(&self.op, "no_slurs"))?;
+ return Err(APIError::err(&self.op, "no_slurs").into());
}
let conn = establish_connection();
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;
@@ -341,17 +341,17 @@ impl Perform<PostResponse> for Oper<EditPost> {
);
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_post_edit_allowed"))?;
+ return Err(APIError::err(&self.op, "no_post_edit_allowed").into());
}
// Check for a community ban
if CommunityUserBanView::get(&conn, user_id, data.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 post_form = PostForm {
@@ -370,7 +370,7 @@ impl Perform<PostResponse> for Oper<EditPost> {
let _updated_post = match Post::update(&conn, data.edit_id, &post_form) {
Ok(post) => post,
- Err(_e) => return Err(APIError::err(&self.op, "couldnt_update_post"))?,
+ Err(_e) => return Err(APIError::err(&self.op, "couldnt_update_post").into()),
};
// Mod tables
@@ -418,7 +418,7 @@ impl Perform<PostResponse> for Oper<SavePost> {
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;
@@ -431,12 +431,12 @@ impl Perform<PostResponse> for Oper<SavePost> {
if data.save {
match PostSaved::save(&conn, &post_saved_form) {
Ok(post) => post,
- Err(_e) => return Err(APIError::err(&self.op, "couldnt_save_post"))?,
+ Err(_e) => return Err(APIError::err(&self.op, "couldnt_save_post").into()),
};
} else {
match PostSaved::unsave(&conn, &post_saved_form) {
Ok(post) => post,
- Err(_e) => return Err(APIError::err(&self.op, "couldnt_save_post"))?,
+ Err(_e) => return Err(APIError::err(&self.op, "couldnt_save_post").into()),
};
}