diff --git a/config/defaults.toml b/config/defaults.toml index 341c32f..653dbfb 100644 --- a/config/defaults.toml +++ b/config/defaults.toml @@ -1,9 +1,3 @@ -# Whether users can create new accounts -registration_open = true - -# Whether admins need to approve new articles -article_approval = false - # Details about the PostgreSQL database connection [database] # Database connection url @@ -28,3 +22,10 @@ allowlist = "good.com,friends.org" # Comma separated list of instances which are blocked for federation; optional blocklist = "evil.com,bad.org" + +[options] +# Whether users can create new accounts +registration_open = true + +# Whether admins need to approve new articles +article_approval = false diff --git a/src/backend/api/article.rs b/src/backend/api/article.rs index 06193eb..3c377e1 100644 --- a/src/backend/api/article.rs +++ b/src/backend/api/article.rs @@ -68,7 +68,7 @@ pub(in crate::backend::api) async fn create_article( instance_id: local_instance.id, local: true, protected: false, - approved: !data.config.config.article_approval, + approved: !data.config.options.article_approval, }; let article = DbArticle::create(form, &data)?; @@ -214,7 +214,7 @@ pub(in crate::backend::api) async fn fork_article( instance_id: local_instance.id, local: true, protected: false, - approved: !data.config.config.article_approval, + approved: !data.config.options.article_approval, }; let article = DbArticle::create(form, &data)?; diff --git a/src/backend/api/mod.rs b/src/backend/api/mod.rs index 9a78f1b..d1e5432 100644 --- a/src/backend/api/mod.rs +++ b/src/backend/api/mod.rs @@ -102,6 +102,6 @@ pub(in crate::backend::api) async fn site_view( ) -> MyResult> { Ok(Json(SiteView { my_profile: user.map(|u| u.0), - config: data.config.config.clone(), + config: data.config.options.clone(), })) } diff --git a/src/backend/api/user.rs b/src/backend/api/user.rs index 46daa6a..bc9914a 100644 --- a/src/backend/api/user.rs +++ b/src/backend/api/user.rs @@ -76,7 +76,7 @@ pub(in crate::backend::api) async fn register_user( jar: CookieJar, Form(form): Form, ) -> MyResult<(CookieJar, Json)> { - if !data.config.config.registration_open { + if !data.config.options.registration_open { return Err(anyhow!("Registration is closed").into()); } let user = DbPerson::create_local(form.username, form.password, false, &data)?; diff --git a/src/backend/config.rs b/src/backend/config.rs index a2c2514..2dd62f4 100644 --- a/src/backend/config.rs +++ b/src/backend/config.rs @@ -1,4 +1,4 @@ -use crate::{backend::error::MyResult, common::SharedConfig}; +use crate::{backend::error::MyResult, common::Options}; use config::Config; use doku::Document; use serde::Deserialize; @@ -13,7 +13,7 @@ pub struct IbisConfig { /// Details of the initial admin account pub setup: IbisConfigSetup, pub federation: IbisConfigFederation, - pub config: SharedConfig, + pub options: Options, } impl IbisConfig { diff --git a/src/backend/nodeinfo.rs b/src/backend/nodeinfo.rs index 6e35127..2f60135 100644 --- a/src/backend/nodeinfo.rs +++ b/src/backend/nodeinfo.rs @@ -34,7 +34,7 @@ async fn node_info(data: Data) -> MyResult> { version: env!("CARGO_PKG_VERSION").to_string(), }, protocols: vec!["activitypub".to_string()], - open_registrations: data.config.config.registration_open, + open_registrations: data.config.options.registration_open, })) } diff --git a/src/common/mod.rs b/src/common/mod.rs index 15df071..b71217f 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -326,7 +326,7 @@ pub struct GetUserForm { #[serde(deny_unknown_fields)] #[cfg_attr(feature = "ssr", derive(Queryable, Document))] #[cfg_attr(feature = "ssr", diesel(check_for_backend(diesel::pg::Pg)))] -pub struct SharedConfig { +pub struct Options { /// Whether users can create new accounts #[default = true] #[cfg_attr(feature = "ssr", doku(example = "true"))] @@ -342,7 +342,7 @@ pub struct SharedConfig { #[cfg_attr(feature = "ssr", diesel(check_for_backend(diesel::pg::Pg)))] pub struct SiteView { pub my_profile: Option, - pub config: SharedConfig, + pub config: Options, } #[test] diff --git a/tests/common.rs b/tests/common.rs index fa6f92d..2c09644 100644 --- a/tests/common.rs +++ b/tests/common.rs @@ -5,7 +5,7 @@ use ibis::{ config::{IbisConfig, IbisConfigDatabase, IbisConfigFederation}, start, }, - common::{RegisterUserForm, SharedConfig}, + common::{Options, RegisterUserForm}, frontend::{api::ApiClient, error::MyResult}, }; use reqwest::ClientBuilder; @@ -128,7 +128,7 @@ impl IbisInstance { domain: domain.clone(), ..Default::default() }, - config: SharedConfig { + options: Options { registration_open: true, article_approval, },