From e317947b75eed386692509adfcd9de0724f279fd Mon Sep 17 00:00:00 2001 From: Nutomic Date: Mon, 11 Dec 2023 20:35:53 +0100 Subject: [PATCH] Dont allow blocking local instance (fixes #4241) (#4242) * Dont allow blocking local instance (fixes #4241) * use localuserview --- crates/api/src/site/block.rs | 4 ++++ crates/utils/src/error.rs | 1 + 2 files changed, 5 insertions(+) diff --git a/crates/api/src/site/block.rs b/crates/api/src/site/block.rs index be48e8ce8..7d28e43d5 100644 --- a/crates/api/src/site/block.rs +++ b/crates/api/src/site/block.rs @@ -19,6 +19,10 @@ pub async fn block_instance( ) -> Result, LemmyError> { let instance_id = data.instance_id; let person_id = local_user_view.person.id; + if local_user_view.person.instance_id == instance_id { + return Err(LemmyErrorType::CantBlockLocalInstance)?; + } + let instance_block_form = InstanceBlockForm { person_id, instance_id, diff --git a/crates/utils/src/error.rs b/crates/utils/src/error.rs index 34f636705..7d84dcbf6 100644 --- a/crates/utils/src/error.rs +++ b/crates/utils/src/error.rs @@ -227,6 +227,7 @@ pub enum LemmyErrorType { BanExpirationInPast, InvalidUnixTime, InvalidBotAction, + CantBlockLocalInstance, Unknown(String), }