summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorDessalines <tyhou13@gmx.com>2019-05-05 09:20:30 -0700
committerDessalines <tyhou13@gmx.com>2019-05-05 09:20:30 -0700
commitf8615b6178ed2c2863de6cb98988b97d01b46786 (patch)
tree1ae761898c6375bb7f59eacfbac663f89c5b29aa /server
parent7fb6a0b1387d4c256061fd9402ac8405fcedcf83 (diff)
Done with reorg
Diffstat (limited to 'server')
-rw-r--r--server/src/api/comment.rs42
-rw-r--r--server/src/api/community.rs66
-rw-r--r--server/src/api/mod.rs6
-rw-r--r--server/src/api/post.rs58
-rw-r--r--server/src/api/site.rs28
-rw-r--r--server/src/api/user.rs50
-rw-r--r--server/src/db/category.rs1
-rw-r--r--server/src/db/comment.rs2
-rw-r--r--server/src/db/comment_view.rs2
-rw-r--r--server/src/db/community.rs2
-rw-r--r--server/src/db/mod.rs9
-rw-r--r--server/src/db/moderator.rs1
-rw-r--r--server/src/db/post.rs2
-rw-r--r--server/src/db/post_view.rs1
-rw-r--r--server/src/db/user.rs4
-rw-r--r--server/src/lib.rs6
-rw-r--r--server/src/main.rs71
-rw-r--r--server/src/websocket/server.rs35
18 files changed, 158 insertions, 228 deletions
diff --git a/server/src/api/comment.rs b/server/src/api/comment.rs
index 36a44b36..65516aca 100644
--- a/server/src/api/comment.rs
+++ b/server/src/api/comment.rs
@@ -47,13 +47,13 @@ pub struct CreateCommentLike {
impl Perform<CommentResponse> for Oper<CreateComment> {
fn perform(&self) -> Result<CommentResponse, Error> {
- let data: CreateComment = self.data;
+ let data: &CreateComment = &self.data;
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."))?
+ return Err(APIError::err(&self.op, "Not logged in."))?
}
};
@@ -62,12 +62,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, "You have been banned from this community"))?
+ return Err(APIError::err(&self.op, "You have been banned from this community"))?
}
// Check for a site ban
if UserView::read(&conn, user_id)?.banned {
- return Err(APIError::err(self.op, "You have been banned from the site"))?
+ return Err(APIError::err(&self.op, "You have been banned from the site"))?
}
let content_slurs_removed = remove_slurs(&data.content.to_owned());
@@ -86,7 +86,7 @@ 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, "Couldn't create Comment"))?
+ return Err(APIError::err(&self.op, "Couldn't create Comment"))?
}
};
@@ -101,7 +101,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, "Couldn't like comment."))?
+ return Err(APIError::err(&self.op, "Couldn't like comment."))?
}
};
@@ -118,13 +118,13 @@ impl Perform<CommentResponse> for Oper<CreateComment> {
impl Perform<CommentResponse> for Oper<EditComment> {
fn perform(&self) -> Result<CommentResponse, Error> {
- let data: EditComment = self.data;
+ let data: &EditComment = &self.data;
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."))?
+ return Err(APIError::err(&self.op, "Not logged in."))?
}
};
@@ -153,17 +153,17 @@ impl Perform<CommentResponse> for Oper<EditComment> {
);
if !editors.contains(&user_id) {
- return Err(APIError::err(self.op, "Not allowed to edit comment."))?
+ return Err(APIError::err(&self.op, "Not allowed to edit comment."))?
}
// Check for a community ban
if CommunityUserBanView::get(&conn, user_id, orig_comment.community_id).is_ok() {
- return Err(APIError::err(self.op, "You have been banned from this community"))?
+ return Err(APIError::err(&self.op, "You have been banned from this community"))?
}
// Check for a site ban
if UserView::read(&conn, user_id)?.banned {
- return Err(APIError::err(self.op, "You have been banned from the site"))?
+ return Err(APIError::err(&self.op, "You have been banned from the site"))?
}
}
@@ -184,7 +184,7 @@ 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, "Couldn't update Comment"))?
+ return Err(APIError::err(&self.op, "Couldn't update Comment"))?
}
};
@@ -214,13 +214,13 @@ impl Perform<CommentResponse> for Oper<EditComment> {
impl Perform<CommentResponse> for Oper<SaveComment> {
fn perform(&self) -> Result<CommentResponse, Error> {
- let data: SaveComment = self.data;
+ let data: &SaveComment = &self.data;
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."))?
+ return Err(APIError::err(&self.op, "Not logged in."))?
}
};
@@ -235,14 +235,14 @@ impl Perform<CommentResponse> for Oper<SaveComment> {
match CommentSaved::save(&conn, &comment_saved_form) {
Ok(comment) => comment,
Err(_e) => {
- return Err(APIError::err(self.op, "Couldnt do comment save"))?
+ return Err(APIError::err(&self.op, "Couldnt do comment save"))?
}
};
} else {
match CommentSaved::unsave(&conn, &comment_saved_form) {
Ok(comment) => comment,
Err(_e) => {
- return Err(APIError::err(self.op, "Couldnt do comment save"))?
+ return Err(APIError::err(&self.op, "Couldnt do comment save"))?
}
};
}
@@ -260,13 +260,13 @@ impl Perform<CommentResponse> for Oper<SaveComment> {
impl Perform<CommentResponse> for Oper<CreateCommentLike> {
fn perform(&self) -> Result<CommentResponse, Error> {
- let data: CreateCommentLike = self.data;
+ let data: &CreateCommentLike = &self.data;
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."))?
+ return Err(APIError::err(&self.op, "Not logged in."))?
}
};
@@ -275,12 +275,12 @@ impl Perform<CommentResponse> for Oper<CreateCommentLike> {
// 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, "You have been banned from this community"))?
+ return Err(APIError::err(&self.op, "You have been banned from this community"))?
}
// Check for a site ban
if UserView::read(&conn, user_id)?.banned {
- return Err(APIError::err(self.op, "You have been banned from the site"))?
+ return Err(APIError::err(&self.op, "You have been banned from the site"))?
}
let like_form = CommentLikeForm {
@@ -298,7 +298,7 @@ impl Perform<CommentResponse> for Oper<CreateCommentLike> {
let _inserted_like = match CommentLike::like(&conn, &like_form) {
Ok(like) => like,
Err(_e) => {
- return Err(APIError::err(self.op, "Couldn't like comment."))?
+ return Err(APIError::err(&self.op, "Couldn't like comment."))?
}
};
}
diff --git a/server/src/api/community.rs b/server/src/api/community.rs
index 5059b17f..be4bb41a 100644
--- a/server/src/api/community.rs
+++ b/server/src/api/community.rs
@@ -46,7 +46,7 @@ pub struct ListCommunitiesResponse {
communities: Vec<CommunityView>
}
-#[derive(Serialize, Deserialize)]
+#[derive(Serialize, Deserialize, Clone)]
pub struct BanFromCommunity {
pub community_id: i32,
user_id: i32,
@@ -111,7 +111,7 @@ pub struct GetFollowedCommunitiesResponse {
impl Perform<GetCommunityResponse> for Oper<GetCommunity> {
fn perform(&self) -> Result<GetCommunityResponse, Error> {
- let data: GetCommunity = self.data;
+ let data: &GetCommunity = &self.data;
let conn = establish_connection();
let user_id: Option<i32> = match &data.auth {
@@ -135,14 +135,14 @@ impl Perform<GetCommunityResponse> for Oper<GetCommunity> {
let community_view = match CommunityView::read(&conn, community_id, user_id) {
Ok(community) => community,
Err(_e) => {
- return Err(APIError::err(self.op, "Couldn't find Community"))?
+ return Err(APIError::err(&self.op, "Couldn't find Community"))?
}
};
let moderators = match CommunityModeratorView::for_community(&conn, community_id) {
Ok(moderators) => moderators,
Err(_e) => {
- return Err(APIError::err(self.op, "Couldn't find Community"))?
+ return Err(APIError::err(&self.op, "Couldn't find Community"))?
}
};
@@ -162,27 +162,27 @@ impl Perform<GetCommunityResponse> for Oper<GetCommunity> {
impl Perform<CommunityResponse> for Oper<CreateCommunity> {
fn perform(&self) -> Result<CommunityResponse, Error> {
- let data: CreateCommunity = self.data;
+ let data: &CreateCommunity = &self.data;
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."))?
+ return Err(APIError::err(&self.op, "Not logged in."))?
}
};
if has_slurs(&data.name) ||
has_slurs(&data.title) ||
(data.description.is_some() && has_slurs(&data.description.to_owned().unwrap())) {
- return Err(APIError::err(self.op, "No slurs"))?
+ return Err(APIError::err(&self.op, "No slurs"))?
}
let user_id = claims.id;
// Check for a site ban
if UserView::read(&conn, user_id)?.banned {
- return Err(APIError::err(self.op, "You have been banned from the site"))?
+ return Err(APIError::err(&self.op, "You have been banned from the site"))?
}
// When you create a community, make sure the user becomes a moderator and a follower
@@ -200,7 +200,7 @@ impl Perform<CommunityResponse> for Oper<CreateCommunity> {
let inserted_community = match Community::create(&conn, &community_form) {
Ok(community) => community,
Err(_e) => {
- return Err(APIError::err(self.op, "Community already exists."))?
+ return Err(APIError::err(&self.op, "Community already exists."))?
}
};
@@ -212,7 +212,7 @@ impl Perform<CommunityResponse> for Oper<CreateCommunity> {
let _inserted_community_moderator = match CommunityModerator::join(&conn, &community_moderator_form) {
Ok(user) => user,
Err(_e) => {
- return Err(APIError::err(self.op, "Community moderator already exists."))?
+ return Err(APIError::err(&self.op, "Community moderator already exists."))?
}
};
@@ -224,7 +224,7 @@ impl Perform<CommunityResponse> for Oper<CreateCommunity> {
let _inserted_community_follower = match CommunityFollower::follow(&conn, &community_follower_form) {
Ok(user) => user,
Err(_e) => {
- return Err(APIError::err(self.op, "Community follower already exists."))?
+ return Err(APIError::err(&self.op, "Community follower already exists."))?
}
};
@@ -241,10 +241,10 @@ impl Perform<CommunityResponse> for Oper<CreateCommunity> {
impl Perform<CommunityResponse> for Oper<EditCommunity> {
fn perform(&self) -> Result<CommunityResponse, Error> {
- let data: EditCommunity = self.data;
+ let data: &EditCommunity = &self.data;
if has_slurs(&data.name) || has_slurs(&data.title) {
- return Err(APIError::err(self.op, "No slurs"))?
+ return Err(APIError::err(&self.op, "No slurs"))?
}
let conn = establish_connection();
@@ -252,7 +252,7 @@ impl Perform<CommunityResponse> for Oper<EditCommunity> {
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
Err(_e) => {
- return Err(APIError::err(self.op, "Not logged in."))?
+ return Err(APIError::err(&self.op, "Not logged in."))?
}
};
@@ -260,7 +260,7 @@ impl Perform<CommunityResponse> for Oper<EditCommunity> {
// Check for a site ban
if UserView::read(&conn, user_id)?.banned {
- return Err(APIError::err(self.op, "You have been banned from the site"))?
+ return Err(APIError::err(&self.op, "You have been banned from the site"))?
}
// Verify its a mod
@@ -280,7 +280,7 @@ impl Perform<CommunityResponse> for Oper<EditCommunity> {
.collect()
);
if !editors.contains(&user_id) {
- return Err(APIError::err(self.op, "Not allowed to edit community"))?
+ return Err(APIError::err(&self.op, "Not allowed to edit community"))?
}
let community_form = CommunityForm {
@@ -297,7 +297,7 @@ impl Perform<CommunityResponse> for Oper<EditCommunity> {
let _updated_community = match Community::update(&conn, data.edit_id, &community_form) {
Ok(community) => community,
Err(_e) => {
- return Err(APIError::err(self.op, "Couldn't update Community"))?
+ return Err(APIError::err(&self.op, "Couldn't update Community"))?
}
};
@@ -330,7 +330,7 @@ impl Perform<CommunityResponse> for Oper<EditCommunity> {
impl Perform<ListCommunitiesResponse> for Oper<ListCommunities> {
fn perform(&self) -> Result<ListCommunitiesResponse, Error> {
- let data: ListCommunities = self.data;
+ let data: &ListCommunities = &self.data;
let conn = establish_connection();
let user_id: Option<i32> = match &data.auth {
@@ -363,13 +363,13 @@ impl Perform<ListCommunitiesResponse> for Oper<ListCommunities> {
impl Perform<CommunityResponse> for Oper<FollowCommunity> {
fn perform(&self) -> Result<CommunityResponse, Error> {
- let data: FollowCommunity = self.data;
+ let data: &FollowCommunity = &self.data;
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."))?
+ return Err(APIError::err(&self.op, "Not logged in."))?
}
};
@@ -384,14 +384,14 @@ impl Perform<CommunityResponse> for Oper<FollowCommunity> {
match CommunityFollower::follow(&conn, &community_follower_form) {
Ok(user) => user,
Err(_e) => {
- return Err(APIError::err(self.op, "Community follower already exists."))?
+ return Err(APIError::err(&self.op, "Community follower already exists."))?
}
};
} else {
match CommunityFollower::ignore(&conn, &community_follower_form) {
Ok(user) => user,
Err(_e) => {
- return Err(APIError::err(self.op, "Community follower already exists."))?
+ return Err(APIError::err(&self.op, "Community follower already exists."))?
}
};
}
@@ -410,13 +410,13 @@ impl Perform<CommunityResponse> for Oper<FollowCommunity> {
impl Perform<GetFollowedCommunitiesResponse> for Oper<GetFollowedCommunities> {
fn perform(&self) -> Result<GetFollowedCommunitiesResponse, Error> {
- let data: GetFollowedCommunities = self.data;
+ let data: &GetFollowedCommunities = &self.data;
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."))?
+ return Err(APIError::err(&self.op, "Not logged in."))?
}
};
@@ -425,7 +425,7 @@ impl Perform<GetFollowedCommunitiesResponse> for Oper<GetFollowedCommunities> {
let communities: Vec<CommunityFollowerView> = match CommunityFollowerView::for_user(&conn, user_id) {
Ok(communities) => communities,
Err(_e) => {
- return Err(APIError::err(self.op, "System error, try logging out and back in."))?
+ return Err(APIError::err(&self.op, "System error, try logging out and back in."))?
}
};
@@ -442,13 +442,13 @@ impl Perform<GetFollowedCommunitiesResponse> for Oper<GetFollowedCommunities> {
impl Perform<BanFromCommunityResponse> for Oper<BanFromCommunity> {
fn perform(&self) -> Result<BanFromCommunityResponse, Error> {
- let data: BanFromCommunity = self.data;
+ let data: &BanFromCommunity = &self.data;
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."))?
+ return Err(APIError::err(&self.op, "Not logged in."))?
}
};
@@ -463,14 +463,14 @@ impl Perform<BanFromCommunityResponse> for Oper<BanFromCommunity> {
match CommunityUserBan::ban(&conn, &community_user_ban_form) {
Ok(user) => user,
Err(_e) => {
- return Err(APIError::err(self.op, "Community user ban already exists"))?
+ return Err(APIError::err(&self.op, "Community user ban already exists"))?
}
};
} else {
match CommunityUserBan::unban(&conn, &community_user_ban_form) {
Ok(user) => user,
Err(_e) => {
- return Err(APIError::err(self.op, "Community user ban already exists"))?
+ return Err(APIError::err(&self.op, "Community user ban already exists"))?
}
};
}
@@ -505,13 +505,13 @@ impl Perform<BanFromCommunityResponse> for Oper<BanFromCommunity> {
impl Perform<AddModToCommunityResponse> for Oper<AddModToCommunity> {
fn perform(&self) -> Result<AddModToCommunityResponse, Error> {
- let data: AddModToCommunity = self.data;
+ let data: &AddModToCommunity = &self.data;
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."))?
+ return Err(APIError::err(&self.op, "Not logged in."))?
}
};
@@ -526,14 +526,14 @@ impl Perform<AddModToCommunityResponse> for Oper<AddModToCommunity> {
match CommunityModerator::join(&conn, &community_moderator_form) {
Ok(user) => user,
Err(_e) => {
- return Err(APIError::err(self.op, "Community moderator already exists."))?
+ return Err(APIError::err(&self.op, "Community moderator already exists."))?
}
};
} else {
match CommunityModerator::leave(&conn, &community_moderator_form) {
Ok(user) => user,
Err(_e) => {
- return Err(APIError::err(self.op, "Community moderator already exists."))?
+ return Err(APIError::err(&self.op, "Community moderator already exists."))?
}
};
}
diff --git a/server/src/api/mod.rs b/server/src/api/mod.rs
index 4bf6f7fe..6e3e8269 100644
--- a/server/src/api/mod.rs
+++ b/server/src/api/mod.rs
@@ -28,12 +28,12 @@ pub enum UserOperation {
#[derive(Fail, Debug)]
#[fail(display = "{{\"op\":\"{}\", \"error\":\"{}\"}}", op, message)]
pub struct APIError {
- op: String,
- message: String,
+ pub op: String,
+ pub message: String,
}
impl APIError {
- pub fn err(op: UserOperation, msg: &str) -> Self {
+ pub fn err(op: &UserOperation, msg: &str) -> Self {
APIError {
op: op.to_string(),
message: msg.to_string(),
diff --git a/server/src/api/post.rs b/server/src/api/post.rs
index e7bec69e..39df9546 100644
--- a/server/src/api/post.rs
+++ b/server/src/api/post.rs
@@ -87,32 +87,32 @@ pub struct SavePost {
impl Perform<PostResponse> for Oper<CreatePost> {
fn perform(&self) -> Result<PostResponse, Error> {
- let data: CreatePost = self.data;
+ let data: &CreatePost = &self.data;
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."))?
+ return Err(APIError::err(&self.op, "Not logged in."))?
}
};
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"))?
}
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, "You have been banned from this community"))?
+ return Err(APIError::err(&self.op, "You have been banned from this community"))?
}
// Check for a site ban
if UserView::read(&conn, user_id)?.banned {
- return Err(APIError::err(self.op, "You have been banned from the site"))?
+ return Err(APIError::err(&self.op, "You have been banned from the site"))?
}
let post_form = PostForm {
@@ -130,7 +130,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, "Couldn't create Post"))?
+ return Err(APIError::err(&self.op, "Couldn't create Post"))?
}
};
@@ -145,7 +145,7 @@ impl Perform<PostResponse> for Oper<CreatePost> {
let _inserted_like = match PostLike::like(&conn, &like_form) {
Ok(like) => like,
Err(_e) => {
- return Err(APIError::err(self.op, "Couldn't like post."))?
+ return Err(APIError::err(&self.op, "Couldn't like post."))?
}
};
@@ -153,7 +153,7 @@ impl Perform<PostResponse> for Oper<CreatePost> {
let post_view = match PostView::read(&conn, inserted_post.id, Some(user_id)) {
Ok(post) => post,
Err(_e) => {
- return Err(APIError::err(self.op, "Couldn't find Post"))?
+ return Err(APIError::err(&self.op, "Couldn't find Post"))?
}
};
@@ -168,7 +168,7 @@ impl Perform<PostResponse> for Oper<CreatePost> {
impl Perform<GetPostResponse> for Oper<GetPost> {
fn perform(&self) -> Result<GetPostResponse, Error> {
- let data: GetPost = self.data;
+ let data: &GetPost = &self.data;
let conn = establish_connection();
let user_id: Option<i32> = match &data.auth {
@@ -187,7 +187,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, "Couldn't find Post"))?
+ return Err(APIError::err(&self.op, "Couldn't find Post"))?
}
};
@@ -216,7 +216,7 @@ impl Perform<GetPostResponse> for Oper<GetPost> {
impl Perform<GetPostsResponse> for Oper<GetPosts> {
fn perform(&self) -> Result<GetPostsResponse, Error> {
- let data: GetPosts = self.data;
+ let data: &GetPosts = &self.data;
let conn = establish_connection();
let user_id: Option<i32> = match &data.auth {
@@ -248,7 +248,7 @@ impl Perform<GetPostsResponse> for Oper<GetPosts> {
data.limit) {
Ok(posts) => posts,
Err(_e) => {
- return Err(APIError::err(self.op, "Couldn't get posts"))?
+ return Err(APIError::err(&self.op, "Couldn't get posts"))?
}
};
@@ -264,13 +264,13 @@ impl Perform<GetPostsResponse> for Oper<GetPosts> {
impl Perform<CreatePostLikeResponse> for Oper<CreatePostLike> {
fn perform(&self) -> Result<CreatePostLikeResponse, Error> {
- let data: CreatePostLike = self.data;
+ let data: &CreatePostLike = &self.data;
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."))?
+ return Err(APIError::err(&self.op, "Not logged in."))?
}
};
@@ -279,12 +279,12 @@ impl Perform<CreatePostLikeResponse> for Oper<CreatePostLike> {
// 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, "You have been banned from this community"))?
+ return Err(APIError::err(&self.op, "You have been banned from this community"))?
}
// Check for a site ban
if UserView::read(&conn, user_id)?.banned {
- return Err(APIError::err(self.op, "You have been banned from the site"))?
+ return Err(APIError::err(&self.op, "You have been banned from the site"))?
}
let like_form = PostLikeForm {
@@ -301,7 +301,7 @@ impl Perform<CreatePostLikeResponse> for Oper<CreatePostLike> {
let _inserted_like = match PostLike::like(&conn, &like_form) {
Ok(like) => like,
Err(_e) => {
- return Err(APIError::err(self.op, "Couldn't like post."))?
+ return Err(APIError::err(&self.op, "Couldn't like post."))?
}
};
}
@@ -309,7 +309,7 @@ impl Perform<CreatePostLikeResponse> for Oper<CreatePostLike> {
let post_view = match PostView::read(&conn, data.post_id, Some(user_id)) {
Ok(post) => post,
Err(_e) => {
- return Err(APIError::err(self.op, "Couldn't find Post"))?
+ return Err(APIError::err(&self.op, "Couldn't find Post"))?
}
};
@@ -325,10 +325,10 @@ impl Perform<CreatePostLikeResponse> for Oper<CreatePostLike> {
impl Perform<PostResponse> for Oper<EditPost> {
fn perform(&self) -> Result<PostResponse, Error> {
- let data: EditPost = self.data;
+ 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"))?
}
let conn = establish_connection();
@@ -336,7 +336,7 @@ impl Perform<PostResponse> for Oper<EditPost> {
let claims = match Claims::decode(&data.auth) {
Ok(claims) => claims.claims,
Err(_e) => {
- return Err(APIError::err(self.op, "Not logged in."))?
+ return Err(APIError::err(&self.op, "Not logged in."))?
}
};
@@ -359,17 +359,17 @@ impl Perform<PostResponse> for Oper<EditPost> {
.collect()
);
if !editors.contains(&user_id) {
- return Err(APIError::err(self.op, "Not allowed to edit post."))?
+ return Err(APIError::err(&self.op, "Not allowed to edit post."))?
}
// Check for a community ban
if CommunityUserBanView::get(&conn, user_id, data.community_id).is_ok() {
- return Err(APIError::err(self.op, "You have been banned from this community"))?
+ return Err(APIError::err(&self.op, "You have been banned from this community"))?
}
// Check for a site ban
if UserView::read(&conn, user_id)?.banned {
- return Err(APIError::err(self.op, "You have been banned from the site"))?
+ return Err(APIError::err(&self.op, "You have been banned from the site"))?
}
let post_form = PostForm {
@@ -387,7 +387,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, "Couldn't update Post"))?
+ return Err(APIError::err(&self.op, "Couldn't update Post"))?
}
};
@@ -424,13 +424,13 @@ impl Perform<PostResponse> for Oper<EditPost> {
impl Perform<PostResponse> for Oper<SavePost> {
fn perform(&self) -> Result<PostResponse, Error> {
- let data: SavePost = self.data;
+ let data: &SavePost = &self.data;
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."))?
+ return Err(APIError::err(&self.op, "Not logged in."))?
}
};
@@ -445,14 +445,14 @@ impl Perform<PostResponse> for Oper<SavePost> {
match PostSaved::save(&conn, &post_saved_form) {
Ok(post) => post,
Err(_e) => {
- return Err(APIError::err(self.op, "Couldnt do post save"))?
+ return Err(APIError::err(&self.op, "Couldnt do post save"))?
}
};
} else {
match PostSaved::unsave(&conn, &post_saved_form) {
Ok(post) => post,
Err(_e) => {
- return Err(APIError::err(self.op, "Couldnt do post save"))?
+ return Err(APIError::err(&self.op, "Couldnt do post save"))?
}
};
}
diff --git a/server/src/api/site.rs b/server/src/api/site.rs
index 3140788d..03ee90ff 100644
--- a/server/src/api/site.rs
+++ b/server/src/api/site.rs
@@ -83,7 +83,7 @@ pub struct GetSiteResponse {
impl Perform<ListCategoriesResponse> for Oper<ListCategories> {
fn perform(&self) -> Result<ListCategoriesResponse, Error> {
- let data: ListCategories = self.data;
+ let _data: &ListCategories = &self.data;
let conn = establish_connection();
let categories: Vec<Category> = Category::list_all(&conn)?;
@@ -100,7 +100,7 @@ impl Perform<ListCategoriesResponse> for Oper<ListCategories> {
impl Perform<GetModlogResponse> for Oper<GetModlog> {
fn perform(&self) -> Result<GetModlogResponse, Error> {
- let data: GetModlog = self.data;
+ let data: &GetModlog = &self.data;
let conn = establish_connection();
let removed_posts = ModRemovePostView::list(&conn, data.community_id, data.mod_user_id, data.page, data.limit)?;
@@ -139,26 +139,26 @@ impl Perform<GetModlogResponse> for Oper<GetModlog> {
impl Perform<SiteResponse> for Oper<CreateSite> {
fn perform(&self) -> Result<SiteResponse, Error> {
- let data: CreateSite = self.data;
+ let data: &CreateSite = &self.data;
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."))?
+ return Err(APIError::err(&self.op, "Not logged in."))?
}
};
if has_slurs(&data.name) ||
(data.description.is_some() && has_slurs(&data.description.to_owned().unwrap())) {
- return Err(APIError::err(self.op, "No slurs"))?
+ return Err(APIError::err(&self.op, "No slurs"))?
}
let user_id = claims.id;
// Make sure user is an admin
if !UserView::read(&conn, user_id)?.admin {
- return Err(APIError::err(self.op, "Not an admin."))?
+ return Err(APIError::err(&self.op, "Not an admin."))?
}
let site_form = SiteForm {
@@ -171,7 +171,7 @@ impl Perform<SiteResponse> for Oper<CreateSite> {
match Site::create(&conn, &site_form) {
Ok(site) => site,
Err(_e) => {
- return Err(APIError::err(self.op, "Site exists already"))?
+ return Err(APIError::err(&self.op, "Site exists already"))?
}
};
@@ -189,26 +189,26 @@ impl Perform<SiteResponse> for Oper<CreateSite> {
impl Perform<SiteResponse> for Oper<EditSite> {
fn perform(&self) -> Result<SiteResponse, Error> {
- let data: EditSite = self.data;
+ let data: &EditSite = &self.data;
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."))?
+ return Err(APIError::err(&self.op, "Not logged in."))?
}
};
if has_slurs(&data.name) ||
(data.description.is_some() && has_slurs(&data.description.to_owned().unwrap())) {
- return Err(APIError::err(self.op, "No slurs"))?
+ return Err(APIError::err(&self.op, "No slurs"))?
}
let user_id = claims.id;
// Make sure user is an admin
if UserView::read(&conn, user_id)?.admin == false {
- return Err(APIError::err(self.op, "Not an admin."))?
+ return Err(APIError::err(&self.op, "Not an admin."))?
}
let found_site = Site::read(&conn, 1)?;
@@ -223,7 +223,7