From e30170c432e108a4c83a1cc6b4a538d2f2811f7e Mon Sep 17 00:00:00 2001 From: Dessalines Date: Tue, 12 Oct 2021 12:33:57 -0400 Subject: [PATCH] Adding check in createorupdate post and comment. --- crates/apub/src/activities/comment/create_or_update.rs | 2 ++ crates/apub/src/activities/mod.rs | 8 ++++++++ crates/apub/src/activities/post/create_or_update.rs | 3 +++ 3 files changed, 13 insertions(+) diff --git a/crates/apub/src/activities/comment/create_or_update.rs b/crates/apub/src/activities/comment/create_or_update.rs index c225300f3..2ed1359f2 100644 --- a/crates/apub/src/activities/comment/create_or_update.rs +++ b/crates/apub/src/activities/comment/create_or_update.rs @@ -1,5 +1,6 @@ use crate::{ activities::{ + check_community_deleted_or_removed, comment::{collect_non_local_mentions, get_notif_recipients}, community::{announce::AnnouncableActivities, send_to_community}, extract_community, @@ -98,6 +99,7 @@ impl ActivityHandler for CreateOrUpdateComment { verify_activity(self, &context.settings())?; verify_person_in_community(&self.actor, &community_id, context, request_counter).await?; verify_domains_match(self.actor.inner(), self.object.id_unchecked())?; + check_community_deleted_or_removed(&community)?; // TODO: should add a check that the correct community is in cc (probably needs changes to // comment deserialization) self.object.verify(context, request_counter).await?; diff --git a/crates/apub/src/activities/mod.rs b/crates/apub/src/activities/mod.rs index 5c775f801..43f86572f 100644 --- a/crates/apub/src/activities/mod.rs +++ b/crates/apub/src/activities/mod.rs @@ -133,6 +133,14 @@ fn verify_add_remove_moderator_target( Ok(()) } +pub(crate) fn check_community_deleted_or_removed(community: &Community) -> Result<(), LemmyError> { + if community.deleted || community.removed { + Err(anyhow!("New post or comment cannot be created in deleted or removed community").into()) + } else { + Ok(()) + } +} + /// Generate a unique ID for an activity, in the format: /// `http(s)://example.com/receive/create/202daf0a-1489-45df-8d2e-c8a3173fed36` fn generate_activity_id(kind: T, protocol_and_hostname: &str) -> Result diff --git a/crates/apub/src/activities/post/create_or_update.rs b/crates/apub/src/activities/post/create_or_update.rs index 8065cc879..f1a336680 100644 --- a/crates/apub/src/activities/post/create_or_update.rs +++ b/crates/apub/src/activities/post/create_or_update.rs @@ -1,5 +1,6 @@ use crate::{ activities::{ + check_community_deleted_or_removed, community::{announce::AnnouncableActivities, send_to_community}, generate_activity_id, verify_activity, @@ -87,6 +88,8 @@ impl ActivityHandler for CreateOrUpdatePost { verify_activity(self, &context.settings())?; let community = self.cc[0].dereference(context, request_counter).await?; verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?; + check_community_deleted_or_removed(&community)?; + match self.kind { CreateOrUpdateType::Create => { verify_domains_match(self.actor.inner(), self.object.id_unchecked())?;