]> Untitled Git - lemmy.git/blobdiff - crates/api_common/src/lib.rs
Adding temporary bans. Fixes #1423 (#1999)
[lemmy.git] / crates / api_common / src / lib.rs
index cd854a6d99af74c4ffea3332de51b2b18d98ecd5..6dcdb58bd7311ac5feb907dc7d7d4d3d5f47ff3d 100644 (file)
@@ -55,6 +55,7 @@ where
   res
 }
 
+#[tracing::instrument(skip_all)]
 pub async fn is_mod_or_admin(
   pool: &DbPool,
   person_id: PersonId,
@@ -77,6 +78,7 @@ pub fn is_admin(local_user_view: &LocalUserView) -> Result<(), LemmyError> {
   Ok(())
 }
 
+#[tracing::instrument(skip_all)]
 pub async fn get_post(post_id: PostId, pool: &DbPool) -> Result<Post, LemmyError> {
   blocking(pool, move |conn| Post::read(conn, post_id))
     .await?
@@ -84,6 +86,7 @@ pub async fn get_post(post_id: PostId, pool: &DbPool) -> Result<Post, LemmyError
     .map_err(|e| e.with_message("couldnt_find_post"))
 }
 
+#[tracing::instrument(skip_all)]
 pub async fn mark_post_as_read(
   person_id: PersonId,
   post_id: PostId,
@@ -99,6 +102,7 @@ pub async fn mark_post_as_read(
   .map_err(|e| e.with_message("couldnt_mark_post_as_read"))
 }
 
+#[tracing::instrument(skip_all)]
 pub async fn mark_post_as_unread(
   person_id: PersonId,
   post_id: PostId,
@@ -114,6 +118,7 @@ pub async fn mark_post_as_unread(
   .map_err(|e| e.with_message("couldnt_mark_post_as_read"))
 }
 
+#[tracing::instrument(skip_all)]
 pub async fn get_local_user_view_from_jwt(
   jwt: &str,
   pool: &DbPool,
@@ -127,7 +132,7 @@ pub async fn get_local_user_view_from_jwt(
   let local_user_view =
     blocking(pool, move |conn| LocalUserView::read(conn, local_user_id)).await??;
   // Check for a site ban
-  if local_user_view.person.banned {
+  if local_user_view.person.is_banned() {
     return Err(LemmyError::from_message("site_ban"));
   }
 
@@ -154,6 +159,7 @@ pub fn check_validator_time(
   }
 }
 
+#[tracing::instrument(skip_all)]
 pub async fn get_local_user_view_from_jwt_opt(
   jwt: Option<&Sensitive<String>>,
   pool: &DbPool,
@@ -165,6 +171,7 @@ pub async fn get_local_user_view_from_jwt_opt(
   }
 }
 
+#[tracing::instrument(skip_all)]
 pub async fn get_local_user_settings_view_from_jwt(
   jwt: &Sensitive<String>,
   pool: &DbPool,
@@ -180,7 +187,7 @@ pub async fn get_local_user_settings_view_from_jwt(
   })
   .await??;
   // Check for a site ban
-  if local_user_view.person.banned {
+  if local_user_view.person.is_banned() {
     return Err(LemmyError::from_message("site_ban"));
   }
 
@@ -189,6 +196,7 @@ pub async fn get_local_user_settings_view_from_jwt(
   Ok(local_user_view)
 }
 
+#[tracing::instrument(skip_all)]
 pub async fn get_local_user_settings_view_from_jwt_opt(
   jwt: Option<&Sensitive<String>>,
   pool: &DbPool,
@@ -202,6 +210,7 @@ pub async fn get_local_user_settings_view_from_jwt_opt(
   }
 }
 
+#[tracing::instrument(skip_all)]
 pub async fn check_community_ban(
   person_id: PersonId,
   community_id: CommunityId,
@@ -216,6 +225,7 @@ pub async fn check_community_ban(
   }
 }
 
+#[tracing::instrument(skip_all)]
 pub async fn check_community_deleted_or_removed(
   community_id: CommunityId,
   pool: &DbPool,
@@ -239,6 +249,7 @@ pub fn check_post_deleted_or_removed(post: &Post) -> Result<(), LemmyError> {
   }
 }
 
+#[tracing::instrument(skip_all)]
 pub async fn check_person_block(
   my_id: PersonId,
   potential_blocker_id: PersonId,
@@ -252,6 +263,7 @@ pub async fn check_person_block(
   }
 }
 
+#[tracing::instrument(skip_all)]
 pub async fn check_downvotes_enabled(score: i16, pool: &DbPool) -> Result<(), LemmyError> {
   if score == -1 {
     let site = blocking(pool, Site::read_simple).await??;
@@ -262,6 +274,7 @@ pub async fn check_downvotes_enabled(score: i16, pool: &DbPool) -> Result<(), Le
   Ok(())
 }
 
+#[tracing::instrument(skip_all)]
 pub async fn check_private_instance(
   local_user_view: &Option<LocalUserView>,
   pool: &DbPool,
@@ -275,6 +288,7 @@ pub async fn check_private_instance(
   Ok(())
 }
 
+#[tracing::instrument(skip_all)]
 pub async fn build_federated_instances(
   pool: &DbPool,
   federation_config: &FederationConfig,