]> Untitled Git - lemmy.git/commitdiff
Add missing mod log entries for federated actions (fixes #1489) (#2198)
authorNutomic <me@nutomic.com>
Thu, 7 Apr 2022 20:44:28 +0000 (20:44 +0000)
committerGitHub <noreply@github.com>
Thu, 7 Apr 2022 20:44:28 +0000 (20:44 +0000)
crates/apub/src/activities/block/block_user.rs
crates/apub/src/activities/block/undo_block_user.rs
crates/apub/src/activities/community/add_mod.rs
crates/apub/src/activities/community/remove_mod.rs
crates/apub/src/activities/deletion/delete.rs
crates/apub/src/activities/deletion/undo_delete.rs
crates/apub/src/objects/post.rs

index 28104dba19131a59b6ac88f939d43f52b27d1a3f..d21c038bee6713b3f01e52c5f27885ae3e43f627 100644 (file)
@@ -31,7 +31,7 @@ use lemmy_db_schema::{
       CommunityPersonBan,
       CommunityPersonBanForm,
     },
-    moderator::{ModBan, ModBanForm},
+    moderator::{ModBan, ModBanForm, ModBanFromCommunity, ModBanFromCommunityForm},
     person::Person,
   },
   traits::{Bannable, Crud, Followable},
@@ -213,14 +213,18 @@ impl ActivityHandler for BlockUser {
         }
 
         // write to mod log
-        let form = ModBanForm {
+        let form = ModBanFromCommunityForm {
           mod_person_id: mod_person.id,
           other_person_id: blocked_person.id,
+          community_id: community.id,
           reason: self.summary,
           banned: Some(true),
           expires,
         };
-        blocking(context.pool(), move |conn| ModBan::create(conn, &form)).await??;
+        blocking(context.pool(), move |conn| {
+          ModBanFromCommunity::create(conn, &form)
+        })
+        .await??;
       }
     }
 
index 014b01fd841e1e11dfe77ad868d8ab25afc68ab7..29c9cd10e0440053d232427688ab54917cfc633a 100644 (file)
@@ -22,7 +22,7 @@ use lemmy_apub_lib::{
 use lemmy_db_schema::{
   source::{
     community::{CommunityPersonBan, CommunityPersonBanForm},
-    moderator::{ModBan, ModBanForm},
+    moderator::{ModBan, ModBanForm, ModBanFromCommunity, ModBanFromCommunityForm},
     person::Person,
   },
   traits::{Bannable, Crud},
@@ -136,14 +136,18 @@ impl ActivityHandler for UndoBlockUser {
         .await??;
 
         // write to mod log
-        let form = ModBanForm {
+        let form = ModBanFromCommunityForm {
           mod_person_id: mod_person.id,
           other_person_id: blocked_person.id,
+          community_id: community.id,
           reason: self.object.summary,
           banned: Some(false),
           expires,
         };
-        blocking(context.pool(), move |conn| ModBan::create(conn, &form)).await??;
+        blocking(context.pool(), move |conn| {
+          ModBanFromCommunity::create(conn, &form)
+        })
+        .await??;
       }
     }
 
index 10baa781c532e741c69d99db655f7d0248cbbbe6..a86c8ac3158c6e5d2b1d73acac5d085598691802 100644 (file)
@@ -25,8 +25,11 @@ use lemmy_apub_lib::{
   traits::{ActivityHandler, ActorType},
 };
 use lemmy_db_schema::{
-  source::community::{CommunityModerator, CommunityModeratorForm},
-  traits::Joinable,
+  source::{
+    community::{CommunityModerator, CommunityModeratorForm},
+    moderator::{ModAddCommunity, ModAddCommunityForm},
+  },
+  traits::{Crud, Joinable},
 };
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
@@ -114,6 +117,22 @@ impl ActivityHandler for AddMod {
         CommunityModerator::join(conn, &form)
       })
       .await??;
+
+      // write mod log
+      let actor = self
+        .actor
+        .dereference(context, context.client(), request_counter)
+        .await?;
+      let form = ModAddCommunityForm {
+        mod_person_id: actor.id,
+        other_person_id: new_mod.id,
+        community_id: community.id,
+        removed: Some(false),
+      };
+      blocking(context.pool(), move |conn| {
+        ModAddCommunity::create(conn, &form)
+      })
+      .await??;
     }
     // TODO: send websocket notification about added mod
     Ok(())
index e404df04d53b0816a48399f2e4d874506d3dd6ce..7e43fcbf7b48198ed4699322d169ba9028264760 100644 (file)
@@ -25,8 +25,11 @@ use lemmy_apub_lib::{
   traits::{ActivityHandler, ActorType},
 };
 use lemmy_db_schema::{
-  source::community::{CommunityModerator, CommunityModeratorForm},
-  traits::Joinable,
+  source::{
+    community::{CommunityModerator, CommunityModeratorForm},
+    moderator::{ModAddCommunity, ModAddCommunityForm},
+  },
+  traits::{Crud, Joinable},
 };
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
@@ -106,6 +109,23 @@ impl ActivityHandler for RemoveMod {
       CommunityModerator::leave(conn, &form)
     })
     .await??;
+
+    // write mod log
+    let actor = self
+      .actor
+      .dereference(context, context.client(), request_counter)
+      .await?;
+    let form = ModAddCommunityForm {
+      mod_person_id: actor.id,
+      other_person_id: remove_mod.id,
+      community_id: community.id,
+      removed: Some(true),
+    };
+    blocking(context.pool(), move |conn| {
+      ModAddCommunity::create(conn, &form)
+    })
+    .await??;
+
     // TODO: send websocket notification about removed mod
     Ok(())
   }
index 3bb4b5bc8691e6cadcaf1f7618d7c105835e3950..275683a379c71ba88a04dfb3184ccfb79e8e2a88 100644 (file)
@@ -67,11 +67,13 @@ impl ActivityHandler for Delete {
         Some(reason)
       };
       receive_remove_action(
-        &self.actor,
+        &self
+          .actor
+          .dereference(context, context.client(), request_counter)
+          .await?,
         self.object.id(),
         reason,
         context,
-        request_counter,
       )
       .await
     } else {
@@ -119,15 +121,11 @@ impl Delete {
 
 #[tracing::instrument(skip_all)]
 pub(in crate::activities) async fn receive_remove_action(
-  actor: &ObjectId<ApubPerson>,
+  actor: &ApubPerson,
   object: &Url,
   reason: Option<String>,
   context: &LemmyContext,
-  request_counter: &mut i32,
 ) -> Result<(), LemmyError> {
-  let actor = actor
-    .dereference(context, context.client(), request_counter)
-    .await?;
   use UserOperationCrud::*;
   match DeletableObjects::read_from_db(object, context).await? {
     DeletableObjects::Community(community) => {
index 7ee90b6e89b59938391793661769b88e2b61788e..6dced43959f38b65afa64670515a194f6c83f134 100644 (file)
@@ -5,13 +5,29 @@ use crate::{
     generate_activity_id,
     verify_activity,
   },
-  objects::community::ApubCommunity,
+  objects::{community::ApubCommunity, person::ApubPerson},
   protocol::activities::deletion::{delete::Delete, undo_delete::UndoDelete},
 };
 use activitystreams_kinds::activity::UndoType;
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{data::Data, object_id::ObjectId, traits::ActivityHandler};
-use lemmy_db_schema::source::{comment::Comment, community::Community, person::Person, post::Post};
+use lemmy_db_schema::{
+  source::{
+    comment::Comment,
+    community::Community,
+    moderator::{
+      ModRemoveComment,
+      ModRemoveCommentForm,
+      ModRemoveCommunity,
+      ModRemoveCommunityForm,
+      ModRemovePost,
+      ModRemovePostForm,
+    },
+    person::Person,
+    post::Post,
+  },
+  traits::Crud,
+};
 use lemmy_utils::LemmyError;
 use lemmy_websocket::{
   send::{send_comment_ws_message_simple, send_community_ws_message, send_post_ws_message},
@@ -49,7 +65,15 @@ impl ActivityHandler for UndoDelete {
     request_counter: &mut i32,
   ) -> Result<(), LemmyError> {
     if self.object.summary.is_some() {
-      UndoDelete::receive_undo_remove_action(self.object.object.id(), context).await
+      UndoDelete::receive_undo_remove_action(
+        &self
+          .actor
+          .dereference(context, context.client(), request_counter)
+          .await?,
+        self.object.object.id(),
+        context,
+      )
+      .await
     } else {
       receive_delete_action(
         self.object.object.id(),
@@ -93,6 +117,7 @@ impl UndoDelete {
 
   #[tracing::instrument(skip_all)]
   pub(in crate::activities) async fn receive_undo_remove_action(
+    actor: &ApubPerson,
     object: &Url,
     context: &LemmyContext,
   ) -> Result<(), LemmyError> {
@@ -104,6 +129,17 @@ impl UndoDelete {
             "Only local admin can restore community",
           ));
         }
+        let form = ModRemoveCommunityForm {
+          mod_person_id: actor.id,
+          community_id: community.id,
+          removed: Some(false),
+          reason: None,
+          expires: None,
+        };
+        blocking(context.pool(), move |conn| {
+          ModRemoveCommunity::create(conn, &form)
+        })
+        .await??;
         let deleted_community = blocking(context.pool(), move |conn| {
           Community::update_removed(conn, community.id, false)
         })
@@ -111,6 +147,16 @@ impl UndoDelete {
         send_community_ws_message(deleted_community.id, EditCommunity, None, None, context).await?;
       }
       DeletableObjects::Post(post) => {
+        let form = ModRemovePostForm {
+          mod_person_id: actor.id,
+          post_id: post.id,
+          removed: Some(false),
+          reason: None,
+        };
+        blocking(context.pool(), move |conn| {
+          ModRemovePost::create(conn, &form)
+        })
+        .await??;
         let removed_post = blocking(context.pool(), move |conn| {
           Post::update_removed(conn, post.id, false)
         })
@@ -118,6 +164,16 @@ impl UndoDelete {
         send_post_ws_message(removed_post.id, EditPost, None, None, context).await?;
       }
       DeletableObjects::Comment(comment) => {
+        let form = ModRemoveCommentForm {
+          mod_person_id: actor.id,
+          comment_id: comment.id,
+          removed: Some(false),
+          reason: None,
+        };
+        blocking(context.pool(), move |conn| {
+          ModRemoveComment::create(conn, &form)
+        })
+        .await??;
         let removed_comment = blocking(context.pool(), move |conn| {
           Comment::update_removed(conn, comment.id, false)
         })
index b5fbe9424114f23b13699a586a3fc162410b77a2..3d0725b7258884e16fa2b2410c852eff6a801926 100644 (file)
@@ -161,6 +161,8 @@ impl ApubObject for ApubPost {
       .await?;
     let community = page.extract_community(context, request_counter).await?;
 
+    // TODO: write mod log if stickied or locked changed
+
     let url = if let Some(attachment) = page.attachment.first() {
       Some(attachment.href.clone())
     } else {