let local_user_view =
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
- check_image_has_local_domain(&data.avatar)?;
- check_image_has_local_domain(&data.banner)?;
-
let avatar = diesel_option_overwrite_to_url(&data.avatar)?;
let banner = diesel_option_overwrite_to_url(&data.banner)?;
let bio = diesel_option_overwrite(&data.bio);
let email_deref = data.email.as_deref().map(|e| e.to_owned());
let email = diesel_option_overwrite(&email_deref);
+ check_image_has_local_domain(avatar.as_ref().unwrap_or(&None))?;
+ check_image_has_local_domain(banner.as_ref().unwrap_or(&None))?;
+
if let Some(Some(email)) = &email {
let previous_email = local_user_view.local_user.email.clone().unwrap_or_default();
// Only send the verification email if there was an email change
use crate::site::FederatedInstances;
use lemmy_db_schema::{
- newtypes::{CommunityId, LocalUserId, PersonId, PostId},
+ newtypes::{CommunityId, DbUrl, LocalUserId, PersonId, PostId},
source::{
comment::Comment,
community::Community,
};
use rosetta_i18n::{Language, LanguageId};
use tracing::warn;
-use url::Url;
pub async fn blocking<F, T>(pool: &DbPool, f: F) -> Result<T, LemmyError>
where
Ok(())
}
-pub fn check_image_has_local_domain(url: &Option<String>) -> Result<(), LemmyError> {
+pub fn check_image_has_local_domain(url: &Option<DbUrl>) -> Result<(), LemmyError> {
if let Some(url) = url {
let settings = Settings::get();
- let url = Url::parse(url)?;
let domain = url.domain().expect("url has domain");
if domain != settings.hostname {
return Err(LemmyError::from_message("image_not_local"));
));
}
+ // Check to make sure the icon and banners are urls
+ let icon = diesel_option_overwrite_to_url(&data.icon)?;
+ let banner = diesel_option_overwrite_to_url(&data.banner)?;
+
check_slurs(&data.name, &context.settings().slur_regex())?;
check_slurs(&data.title, &context.settings().slur_regex())?;
check_slurs_opt(&data.description, &context.settings().slur_regex())?;
- check_image_has_local_domain(&data.icon)?;
- check_image_has_local_domain(&data.banner)?;
+ check_image_has_local_domain(icon.as_ref().unwrap_or(&None))?;
+ check_image_has_local_domain(banner.as_ref().unwrap_or(&None))?;
if !is_valid_actor_name(&data.name, context.settings().actor_name_max_length) {
return Err(LemmyError::from_message("invalid_community_name"));
return Err(LemmyError::from_message("community_already_exists"));
}
- // Check to make sure the icon and banners are urls
- let icon = diesel_option_overwrite_to_url(&data.icon)?;
- let banner = diesel_option_overwrite_to_url(&data.banner)?;
-
// When you create a community, make sure the user becomes a moderator and a follower
let keypair = generate_actor_keypair()?;
let local_user_view =
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
+ let icon = diesel_option_overwrite_to_url(&data.icon)?;
+ let banner = diesel_option_overwrite_to_url(&data.banner)?;
+
check_slurs_opt(&data.title, &context.settings().slur_regex())?;
check_slurs_opt(&data.description, &context.settings().slur_regex())?;
- check_image_has_local_domain(&data.icon)?;
- check_image_has_local_domain(&data.banner)?;
+ check_image_has_local_domain(icon.as_ref().unwrap_or(&None))?;
+ check_image_has_local_domain(banner.as_ref().unwrap_or(&None))?;
// Verify its a mod (only mods can edit it)
let community_id = data.community_id;
})
.await??;
- let icon = diesel_option_overwrite_to_url(&data.icon)?;
- let banner = diesel_option_overwrite_to_url(&data.banner)?;
-
let community_form = CommunityForm {
name: read_community.name,
title: data.title.to_owned().unwrap_or(read_community.title),
let local_user_view =
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
+ let sidebar = diesel_option_overwrite(&data.sidebar);
+ let description = diesel_option_overwrite(&data.description);
+ let icon = diesel_option_overwrite_to_url(&data.icon)?;
+ let banner = diesel_option_overwrite_to_url(&data.banner)?;
+
check_slurs(&data.name, &context.settings().slur_regex())?;
check_slurs_opt(&data.description, &context.settings().slur_regex())?;
- check_image_has_local_domain(&data.icon)?;
- check_image_has_local_domain(&data.banner)?;
+ check_image_has_local_domain(icon.as_ref().unwrap_or(&None))?;
+ check_image_has_local_domain(banner.as_ref().unwrap_or(&None))?;
// Make sure user is an admin
is_admin(&local_user_view)?;
- let sidebar = diesel_option_overwrite(&data.sidebar);
- let description = diesel_option_overwrite(&data.description);
- let icon = diesel_option_overwrite_to_url(&data.icon)?;
- let banner = diesel_option_overwrite_to_url(&data.banner)?;
-
if let Some(Some(desc)) = &description {
site_description_length_check(desc)?;
}
let local_user_view =
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
- check_slurs_opt(&data.name, &context.settings().slur_regex())?;
- check_slurs_opt(&data.description, &context.settings().slur_regex())?;
- check_image_has_local_domain(&data.icon)?;
- check_image_has_local_domain(&data.banner)?;
-
// Make sure user is an admin
is_admin(&local_user_view)?;
let icon = diesel_option_overwrite_to_url(&data.icon)?;
let banner = diesel_option_overwrite_to_url(&data.banner)?;
+ check_slurs_opt(&data.name, &context.settings().slur_regex())?;
+ check_slurs_opt(&data.description, &context.settings().slur_regex())?;
+ check_image_has_local_domain(icon.as_ref().unwrap_or(&None))?;
+ check_image_has_local_domain(banner.as_ref().unwrap_or(&None))?;
+
if let Some(Some(desc)) = &description {
site_description_length_check(desc)?;
}
+ // Make sure if applications are required, that there is an application questionnaire
+ if data.require_application.unwrap_or(false)
+ && application_question.as_ref().unwrap_or(&None).is_none()
+ {
+ return Err(LemmyError::from_message("application_question_required"));
+ }
+
let site_form = SiteForm {
name: data.name.to_owned().unwrap_or(local_site.name),
sidebar,