]> Untitled Git - lemmy.git/commitdiff
Prevent making an instance private if federation is enabled. (#3074)
authorWyatt Smith <wyatt@wyattsmith.org>
Thu, 15 Jun 2023 09:35:09 +0000 (02:35 -0700)
committerGitHub <noreply@github.com>
Thu, 15 Jun 2023 09:35:09 +0000 (11:35 +0200)
* Prevent making an instance private if federation is enabled.

* Added case where federation is enabled, check if the alternative setting is changed

* Merged the error messages for private instance/federation.

---------

Co-authored-by: Wyatt Smith <wys@dropbox.com>
crates/api_crud/src/site/update.rs

index b3e8657592969666dfebdbca016a87730113e998..ac1544ffcae8cbd7bb3d59e074976fbd4605511c 100644 (file)
@@ -76,6 +76,19 @@ impl PerformCrud for EditSite {
       }
     }
 
+    let enabled_private_instance_with_federation = data.private_instance == Some(true)
+      && data
+        .federation_enabled
+        .unwrap_or(local_site.federation_enabled);
+    let enabled_federation_with_private_instance = data.federation_enabled == Some(true)
+      && data.private_instance.unwrap_or(local_site.private_instance);
+
+    if enabled_private_instance_with_federation || enabled_federation_with_private_instance {
+      return Err(LemmyError::from_message(
+        "cant_enable_private_instance_and_federation_together",
+      ));
+    }
+
     if let Some(discussion_languages) = data.discussion_languages.clone() {
       SiteLanguage::update(context.pool(), discussion_languages.clone(), &site).await?;
     }