]> Untitled Git - lemmy.git/blobdiff - crates/api_crud/src/site/create.rs
Adding diesel enums for SortType and ListingType (#2808)
[lemmy.git] / crates / api_crud / src / site / create.rs
index 8b2b9c18bf7a0d2024faff469d2a11a039470d2b..d45caaa8a4e8751ef0569ffacea6c06813ab02db 100644 (file)
@@ -1,9 +1,11 @@
-use crate::PerformCrud;
-use activitypub_federation::core::signatures::generate_actor_keypair;
+use crate::{site::check_application_question, PerformCrud};
+use activitypub_federation::http_signatures::generate_actor_keypair;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   site::{CreateSite, SiteResponse},
   utils::{
+    generate_site_inbox_url,
     get_local_user_view_from_jwt,
     is_admin,
     local_site_rate_limit_to_rate_limit_config,
@@ -11,7 +13,6 @@ use lemmy_api_common::{
     site_description_length_check,
   },
 };
-use lemmy_apub::generate_site_inbox_url;
 use lemmy_db_schema::{
   newtypes::DbUrl,
   source::{
@@ -25,10 +26,12 @@ use lemmy_db_schema::{
 use lemmy_db_views::structs::SiteView;
 use lemmy_utils::{
   error::LemmyError,
-  utils::{check_application_question, check_slurs, check_slurs_opt},
+  utils::{
+    slurs::{check_slurs, check_slurs_opt},
+    validation::is_valid_body_field,
+  },
   ConnectionId,
 };
-use lemmy_websocket::LemmyContext;
 use url::Url;
 
 #[async_trait::async_trait(?Send)]
@@ -68,8 +71,15 @@ impl PerformCrud for CreateSite {
       site_description_length_check(desc)?;
     }
 
+    is_valid_body_field(&data.sidebar)?;
+
     let application_question = diesel_option_overwrite(&data.application_question);
-    check_application_question(&application_question, &data.require_application)?;
+    check_application_question(
+      &application_question,
+      data
+        .registration_mode
+        .unwrap_or(local_site.registration_mode),
+    )?;
 
     let actor_id: DbUrl = Url::parse(&context.settings().get_protocol_and_hostname())?.into();
     let inbox_url = Some(generate_site_inbox_url(&actor_id)?);
@@ -95,15 +105,14 @@ impl PerformCrud for CreateSite {
       // Set the site setup to true
       .site_setup(Some(true))
       .enable_downvotes(data.enable_downvotes)
-      .open_registration(data.open_registration)
+      .registration_mode(data.registration_mode)
       .enable_nsfw(data.enable_nsfw)
       .community_creation_admin_only(data.community_creation_admin_only)
       .require_email_verification(data.require_email_verification)
-      .require_application(data.require_application)
       .application_question(application_question)
       .private_instance(data.private_instance)
       .default_theme(data.default_theme.clone())
-      .default_post_listing_type(data.default_post_listing_type.clone())
+      .default_post_listing_type(data.default_post_listing_type)
       .legal_information(diesel_option_overwrite(&data.legal_information))
       .application_email_admins(data.application_email_admins)
       .hide_modlog_mod_names(data.hide_modlog_mod_names)