]> Untitled Git - lemmy.git/blobdiff - lemmy_api/src/lib.rs
Some API cleanup, adding site_id to site aggregates.
[lemmy.git] / lemmy_api / src / lib.rs
index ad7355e1cb59326ecbcdd59c0529a68137cedbcc..eadb0d1ac9278e8e58318b09662173d61510daba 100644 (file)
@@ -4,6 +4,7 @@ use lemmy_db::{
   source::{
     community::{Community, CommunityModerator},
     post::Post,
+    site::Site,
     user::User_,
   },
   views::community::community_user_ban_view::CommunityUserBanView,
@@ -102,6 +103,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