]> Untitled Git - lemmy.git/blobdiff - crates/apub/src/activities/deletion/delete.rs
Make functions work with both connection and pool (#3420)
[lemmy.git] / crates / apub / src / activities / deletion / delete.rs
index dfa709c36d3bcefc4b783c323ad4c49dc2c4e76e..8ad104173d6e4bc32e33fba735c1ce5c3d40733e 100644 (file)
@@ -25,7 +25,7 @@ use lemmy_db_schema::{
   },
   traits::Crud,
 };
-use lemmy_utils::error::LemmyError;
+use lemmy_utils::error::{LemmyError, LemmyErrorType};
 use url::Url;
 
 #[async_trait::async_trait]
@@ -108,9 +108,7 @@ pub(in crate::activities) async fn receive_remove_action(
   match DeletableObjects::read_from_db(object, context).await? {
     DeletableObjects::Community(community) => {
       if community.local {
-        return Err(LemmyError::from_message(
-          "Only local admin can remove community",
-        ));
+        return Err(LemmyErrorType::OnlyLocalAdminCanRemoveCommunity)?;
       }
       let form = ModRemoveCommunityForm {
         mod_person_id: actor.id,
@@ -119,9 +117,9 @@ pub(in crate::activities) async fn receive_remove_action(
         reason,
         expires: None,
       };
-      ModRemoveCommunity::create(context.pool(), &form).await?;
+      ModRemoveCommunity::create(&mut context.pool(), &form).await?;
       Community::update(
-        context.pool(),
+        &mut context.pool(),
         community.id,
         &CommunityUpdateForm::builder().removed(Some(true)).build(),
       )
@@ -134,9 +132,9 @@ pub(in crate::activities) async fn receive_remove_action(
         removed: Some(true),
         reason,
       };
-      ModRemovePost::create(context.pool(), &form).await?;
+      ModRemovePost::create(&mut context.pool(), &form).await?;
       Post::update(
-        context.pool(),
+        &mut context.pool(),
         post.id,
         &PostUpdateForm::builder().removed(Some(true)).build(),
       )
@@ -149,9 +147,9 @@ pub(in crate::activities) async fn receive_remove_action(
         removed: Some(true),
         reason,
       };
-      ModRemoveComment::create(context.pool(), &form).await?;
+      ModRemoveComment::create(&mut context.pool(), &form).await?;
       Comment::update(
-        context.pool(),
+        &mut context.pool(),
         comment.id,
         &CommentUpdateForm::builder().removed(Some(true)).build(),
       )