-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::{
- get_local_user_view_from_jwt,
+ generate_site_inbox_url,
is_admin,
local_site_rate_limit_to_rate_limit_config,
local_site_to_slur_regex,
+ local_user_view_from_jwt,
site_description_length_check,
},
};
-use lemmy_apub::generate_site_inbox_url;
use lemmy_db_schema::{
newtypes::DbUrl,
source::{
local_site::{LocalSite, LocalSiteUpdateForm},
local_site_rate_limit::{LocalSiteRateLimit, LocalSiteRateLimitUpdateForm},
site::{Site, SiteUpdateForm},
+ tagline::Tagline,
},
traits::Crud,
utils::{diesel_option_overwrite, diesel_option_overwrite_to_url, naive_now},
use lemmy_db_views::structs::SiteView;
use lemmy_utils::{
error::LemmyError,
- utils::{check_application_question, check_slurs, check_slurs_opt},
- ConnectionId,
+ utils::{
+ slurs::{check_slurs, check_slurs_opt},
+ validation::{check_site_visibility_valid, is_valid_body_field},
+ },
};
-use lemmy_websocket::LemmyContext;
use url::Url;
#[async_trait::async_trait(?Send)]
impl PerformCrud for CreateSite {
type Response = SiteResponse;
- #[tracing::instrument(skip(context, _websocket_id))]
- async fn perform(
- &self,
- context: &Data<LemmyContext>,
- _websocket_id: Option<ConnectionId>,
- ) -> Result<SiteResponse, LemmyError> {
+ #[tracing::instrument(skip(context))]
+ async fn perform(&self, context: &Data<LemmyContext>) -> Result<SiteResponse, LemmyError> {
let data: &CreateSite = self;
let local_site = LocalSite::read(context.pool()).await?;
return Err(LemmyError::from_message("site_already_exists"));
};
- let local_user_view =
- get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
+ let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
+
+ // Make sure user is an admin
+ is_admin(&local_user_view)?;
+
+ check_site_visibility_valid(
+ local_site.private_instance,
+ local_site.federation_enabled,
+ &data.private_instance,
+ &data.federation_enabled,
+ )?;
let sidebar = diesel_option_overwrite(&data.sidebar);
let description = diesel_option_overwrite(&data.description);
check_slurs(&data.name, &slur_regex)?;
check_slurs_opt(&data.description, &slur_regex)?;
- // Make sure user is an admin
- is_admin(&local_user_view)?;
-
if let Some(Some(desc)) = &description {
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)?);
// 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)
.slur_filter_regex(diesel_option_overwrite(&data.slur_filter_regex))
.actor_name_max_length(data.actor_name_max_length)
.federation_enabled(data.federation_enabled)
- .federation_debug(data.federation_debug)
- .federation_strict_allowlist(data.federation_strict_allowlist)
- .federation_http_fetch_retry_limit(data.federation_http_fetch_retry_limit)
- .federation_worker_count(data.federation_worker_count)
.captcha_enabled(data.captcha_enabled)
.captcha_difficulty(data.captcha_difficulty.clone())
.build();
let site_view = SiteView::read_local(context.pool()).await?;
+ let new_taglines = data.taglines.clone();
+ let taglines = Tagline::replace(context.pool(), local_site.id, new_taglines).await?;
+
let rate_limit_config =
local_site_rate_limit_to_rate_limit_config(&site_view.local_site_rate_limit);
context
.send(rate_limit_config)
.await?;
- Ok(SiteResponse { site_view })
+ Ok(SiteResponse {
+ site_view,
+ taglines,
+ })
}
}