diff options
author | Dessalines <tyhou13@gmx.com> | 2019-12-11 12:21:47 -0800 |
---|---|---|
committer | Dessalines <tyhou13@gmx.com> | 2019-12-11 12:21:47 -0800 |
commit | fca8e6a0a9308340e88ad291c89c40e7d17f27be (patch) | |
tree | 7b5cdfa2323499d4f477645962baee2948f482ec /server/src/api | |
parent | e9f476566378b6745ecb82808c0943550285c3fd (diff) |
Adding some site oriented settings.
- Adding option to close registration. Fixes #350
- Adding option to disable showing NSFW buttons. Fixes #364
- Adding option to disable downvotes. Fixes #239
Diffstat (limited to 'server/src/api')
-rw-r--r-- | server/src/api/comment.rs | 8 | ||||
-rw-r--r-- | server/src/api/mod.rs | 2 | ||||
-rw-r--r-- | server/src/api/post.rs | 8 | ||||
-rw-r--r-- | server/src/api/site.rs | 15 | ||||
-rw-r--r-- | server/src/api/user.rs | 7 |
5 files changed, 40 insertions, 0 deletions
diff --git a/server/src/api/comment.rs b/server/src/api/comment.rs index eb5da62b..9f9d46d3 100644 --- a/server/src/api/comment.rs +++ b/server/src/api/comment.rs @@ -298,6 +298,14 @@ impl Perform<CommentResponse> for Oper<CreateCommentLike> { let user_id = claims.id; + // 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"))?; + } + } + // Check for a community ban let post = Post::read(&conn, data.post_id)?; if CommunityUserBanView::get(&conn, user_id, post.community_id).is_ok() { diff --git a/server/src/api/mod.rs b/server/src/api/mod.rs index 2d5dec87..97a11900 100644 --- a/server/src/api/mod.rs +++ b/server/src/api/mod.rs @@ -8,6 +8,8 @@ use crate::db::moderator_views::*; use crate::db::password_reset_request::*; use crate::db::post::*; use crate::db::post_view::*; +use crate::db::site::*; +use crate::db::site_view::*; use crate::db::user::*; use crate::db::user_mention::*; use crate::db::user_mention_view::*; diff --git a/server/src/api/post.rs b/server/src/api/post.rs index 0b54840f..4b2395a8 100644 --- a/server/src/api/post.rs +++ b/server/src/api/post.rs @@ -265,6 +265,14 @@ impl Perform<CreatePostLikeResponse> for Oper<CreatePostLike> { let user_id = claims.id; + // 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"))?; + } + } + // Check for a community ban let post = Post::read(&conn, data.post_id)?; if CommunityUserBanView::get(&conn, user_id, post.community_id).is_ok() { diff --git a/server/src/api/site.rs b/server/src/api/site.rs index cb6edfd5..ec89e46c 100644 --- a/server/src/api/site.rs +++ b/server/src/api/site.rs @@ -56,6 +56,9 @@ pub struct GetModlogResponse { pub struct CreateSite { name: String, description: Option<String>, + enable_downvotes: bool, + open_registration: bool, + enable_nsfw: bool, auth: String, } @@ -63,6 +66,9 @@ pub struct CreateSite { pub struct EditSite { name: String, description: Option<String>, + enable_downvotes: bool, + open_registration: bool, + enable_nsfw: bool, auth: String, } @@ -208,6 +214,9 @@ impl Perform<SiteResponse> for Oper<CreateSite> { name: data.name.to_owned(), description: data.description.to_owned(), creator_id: user_id, + enable_downvotes: data.enable_downvotes, + open_registration: data.open_registration, + enable_nsfw: data.enable_nsfw, updated: None, }; @@ -255,6 +264,9 @@ impl Perform<SiteResponse> for Oper<EditSite> { description: data.description.to_owned(), creator_id: found_site.creator_id, updated: Some(naive_now()), + enable_downvotes: data.enable_downvotes, + open_registration: data.open_registration, + enable_nsfw: data.enable_nsfw, }; match Site::update(&conn, 1, &site_form) { @@ -431,6 +443,9 @@ impl Perform<GetSiteResponse> for Oper<TransferSite> { description: read_site.description, creator_id: data.user_id, updated: Some(naive_now()), + enable_downvotes: read_site.enable_downvotes, + open_registration: read_site.open_registration, + enable_nsfw: read_site.enable_nsfw, }; match Site::update(&conn, 1, &site_form) { diff --git a/server/src/api/user.rs b/server/src/api/user.rs index 3047a0d3..df38dc99 100644 --- a/server/src/api/user.rs +++ b/server/src/api/user.rs @@ -193,6 +193,13 @@ impl Perform<LoginResponse> for Oper<Register> { let data: &Register = &self.data; let conn = establish_connection(); + // Make sure site has open registration + if let Ok(site) = SiteView::read(&conn) { + if !site.open_registration { + return Err(APIError::err(&self.op, "registration_closed"))?; + } + } + // Make sure passwords match if &data.password != &data.password_verify { return Err(APIError::err(&self.op, "passwords_dont_match"))?; |