]> Untitled Git - lemmy.git/blobdiff - lemmy_api/src/lib.rs
Merge remote-tracking branch 'origin/split-db-workspace' into move_views_to_diesel_split
[lemmy.git] / lemmy_api / src / lib.rs
index fc484c32393bec6e9af42ab3b6624e90d2d74a47..4b61539b4d9853b0af3048e31e70124e66a8f45f 100644 (file)
@@ -1,7 +1,10 @@
 use crate::claims::Claims;
 use actix_web::{web, web::Data};
 use lemmy_db::{
-  source::community::{CommunityModerator_, Community_},
+  source::{
+    community::{CommunityModerator_, Community_},
+    site::Site_,
+  },
   views::community::community_user_ban_view::CommunityUserBanView,
   Crud,
   DbPool,
@@ -9,6 +12,7 @@ use lemmy_db::{
 use lemmy_db_schema::source::{
   community::{Community, CommunityModerator},
   post::Post,
+  site::Site,
   user::User_,
 };
 use lemmy_structs::{blocking, comment::*, community::*, post::*, site::*, user::*};
@@ -103,6 +107,16 @@ pub(crate) async fn check_community_ban(
   }
 }
 
+pub(crate) async fn check_downvotes_enabled(score: i16, pool: &DbPool) -> Result<(), LemmyError> {
+  if score == -1 {
+    let site = blocking(pool, move |conn| Site::read_simple(conn)).await??;
+    if !site.enable_downvotes {
+      return Err(APIError::err("downvotes_disabled").into());
+    }
+  }
+  Ok(())
+}
+
 /// Returns a list of communities that the user moderates
 /// or if a community_id is supplied validates the user is a moderator
 /// of that community and returns the community id in a vec