pub enable_downvotes: bool,
pub open_registration: bool,
pub enable_nsfw: bool,
+ pub community_creation_admin_only: bool,
pub auth: String,
}
pub enable_downvotes: bool,
pub open_registration: bool,
pub enable_nsfw: bool,
+ pub community_creation_admin_only: Option<bool>,
pub auth: String,
}
blocking,
community::{CommunityResponse, CreateCommunity},
get_local_user_view_from_jwt,
+ is_admin,
};
use lemmy_apub::{
generate_apub_endpoint,
EndpointType,
};
use lemmy_db_queries::{diesel_option_overwrite_to_url, ApubObject, Crud, Followable, Joinable};
-use lemmy_db_schema::source::community::{
- Community,
- CommunityFollower,
- CommunityFollowerForm,
- CommunityForm,
- CommunityModerator,
- CommunityModeratorForm,
+use lemmy_db_schema::source::{
+ community::{
+ Community,
+ CommunityFollower,
+ CommunityFollowerForm,
+ CommunityForm,
+ CommunityModerator,
+ CommunityModeratorForm,
+ },
+ site::Site,
};
use lemmy_db_views_actor::community_view::CommunityView;
use lemmy_utils::{
let data: &CreateCommunity = &self;
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
+ let site = blocking(context.pool(), move |conn| Site::read(conn, 0)).await??;
+ if site.community_creation_admin_only && is_admin(&local_user_view).is_err() {
+ return Err(ApiError::err("only_admins_can_create_communities").into());
+ }
+
check_slurs(&data.name)?;
check_slurs(&data.title)?;
check_slurs_opt(&data.description)?;
open_registration: data.open_registration,
enable_nsfw: data.enable_nsfw,
updated: None,
+ community_creation_admin_only: Some(data.community_creation_admin_only),
};
let create_site = move |conn: &'_ _| Site::create(conn, &site_form);
open_registration: true,
enable_nsfw: true,
auth: login_response.jwt,
+ community_creation_admin_only: false,
};
create_site.perform(context, websocket_id).await?;
info!("Site {} created", setup.site_name);
enable_downvotes: data.enable_downvotes,
open_registration: data.open_registration,
enable_nsfw: data.enable_nsfw,
+ community_creation_admin_only: data.community_creation_admin_only,
};
let update_site = move |conn: &'_ _| Site::update(conn, 1, &site_form);
open_registration: true,
enable_nsfw: true,
updated: None,
+ community_creation_admin_only: Some(false),
};
Site::create(&conn, &site_form).unwrap();
icon -> Nullable<Varchar>,
banner -> Nullable<Varchar>,
description -> Nullable<Text>,
+ community_creation_admin_only -> Bool,
}
}
pub icon: Option<DbUrl>,
pub banner: Option<DbUrl>,
pub description: Option<String>,
+ pub community_creation_admin_only: bool,
}
#[derive(Insertable, AsChangeset)]
pub icon: Option<Option<DbUrl>>,
pub banner: Option<Option<DbUrl>>,
pub description: Option<Option<String>>,
+ pub community_creation_admin_only: Option<bool>,
}
--- /dev/null
+ALTER TABLE site DROP COLUMN community_creation_admin_only;
--- /dev/null
+ALTER TABLE site ADD COLUMN community_creation_admin_only bool NOT NULL DEFAULT false;