1
0
Fork 0
mirror of https://github.com/Nutomic/ibis.git synced 2024-11-23 13:11:09 +00:00

Update default config

This commit is contained in:
Felix Ableitner 2024-11-14 14:52:33 +01:00
parent 61806e12a6
commit 22bd0d9538
8 changed files with 18 additions and 17 deletions

View file

@ -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 # Details about the PostgreSQL database connection
[database] [database]
# Database connection url # Database connection url
@ -28,3 +22,10 @@ allowlist = "good.com,friends.org"
# Comma separated list of instances which are blocked for federation; optional # Comma separated list of instances which are blocked for federation; optional
blocklist = "evil.com,bad.org" 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

View file

@ -68,7 +68,7 @@ pub(in crate::backend::api) async fn create_article(
instance_id: local_instance.id, instance_id: local_instance.id,
local: true, local: true,
protected: false, protected: false,
approved: !data.config.config.article_approval, approved: !data.config.options.article_approval,
}; };
let article = DbArticle::create(form, &data)?; let article = DbArticle::create(form, &data)?;
@ -214,7 +214,7 @@ pub(in crate::backend::api) async fn fork_article(
instance_id: local_instance.id, instance_id: local_instance.id,
local: true, local: true,
protected: false, protected: false,
approved: !data.config.config.article_approval, approved: !data.config.options.article_approval,
}; };
let article = DbArticle::create(form, &data)?; let article = DbArticle::create(form, &data)?;

View file

@ -102,6 +102,6 @@ pub(in crate::backend::api) async fn site_view(
) -> MyResult<Json<SiteView>> { ) -> MyResult<Json<SiteView>> {
Ok(Json(SiteView { Ok(Json(SiteView {
my_profile: user.map(|u| u.0), my_profile: user.map(|u| u.0),
config: data.config.config.clone(), config: data.config.options.clone(),
})) }))
} }

View file

@ -76,7 +76,7 @@ pub(in crate::backend::api) async fn register_user(
jar: CookieJar, jar: CookieJar,
Form(form): Form<RegisterUserForm>, Form(form): Form<RegisterUserForm>,
) -> MyResult<(CookieJar, Json<LocalUserView>)> { ) -> MyResult<(CookieJar, Json<LocalUserView>)> {
if !data.config.config.registration_open { if !data.config.options.registration_open {
return Err(anyhow!("Registration is closed").into()); return Err(anyhow!("Registration is closed").into());
} }
let user = DbPerson::create_local(form.username, form.password, false, &data)?; let user = DbPerson::create_local(form.username, form.password, false, &data)?;

View file

@ -1,4 +1,4 @@
use crate::{backend::error::MyResult, common::SharedConfig}; use crate::{backend::error::MyResult, common::Options};
use config::Config; use config::Config;
use doku::Document; use doku::Document;
use serde::Deserialize; use serde::Deserialize;
@ -13,7 +13,7 @@ pub struct IbisConfig {
/// Details of the initial admin account /// Details of the initial admin account
pub setup: IbisConfigSetup, pub setup: IbisConfigSetup,
pub federation: IbisConfigFederation, pub federation: IbisConfigFederation,
pub config: SharedConfig, pub options: Options,
} }
impl IbisConfig { impl IbisConfig {

View file

@ -34,7 +34,7 @@ async fn node_info(data: Data<IbisData>) -> MyResult<Json<NodeInfo>> {
version: env!("CARGO_PKG_VERSION").to_string(), version: env!("CARGO_PKG_VERSION").to_string(),
}, },
protocols: vec!["activitypub".to_string()], protocols: vec!["activitypub".to_string()],
open_registrations: data.config.config.registration_open, open_registrations: data.config.options.registration_open,
})) }))
} }

View file

@ -326,7 +326,7 @@ pub struct GetUserForm {
#[serde(deny_unknown_fields)] #[serde(deny_unknown_fields)]
#[cfg_attr(feature = "ssr", derive(Queryable, Document))] #[cfg_attr(feature = "ssr", derive(Queryable, Document))]
#[cfg_attr(feature = "ssr", diesel(check_for_backend(diesel::pg::Pg)))] #[cfg_attr(feature = "ssr", diesel(check_for_backend(diesel::pg::Pg)))]
pub struct SharedConfig { pub struct Options {
/// Whether users can create new accounts /// Whether users can create new accounts
#[default = true] #[default = true]
#[cfg_attr(feature = "ssr", doku(example = "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)))] #[cfg_attr(feature = "ssr", diesel(check_for_backend(diesel::pg::Pg)))]
pub struct SiteView { pub struct SiteView {
pub my_profile: Option<LocalUserView>, pub my_profile: Option<LocalUserView>,
pub config: SharedConfig, pub config: Options,
} }
#[test] #[test]

View file

@ -5,7 +5,7 @@ use ibis::{
config::{IbisConfig, IbisConfigDatabase, IbisConfigFederation}, config::{IbisConfig, IbisConfigDatabase, IbisConfigFederation},
start, start,
}, },
common::{RegisterUserForm, SharedConfig}, common::{Options, RegisterUserForm},
frontend::{api::ApiClient, error::MyResult}, frontend::{api::ApiClient, error::MyResult},
}; };
use reqwest::ClientBuilder; use reqwest::ClientBuilder;
@ -128,7 +128,7 @@ impl IbisInstance {
domain: domain.clone(), domain: domain.clone(),
..Default::default() ..Default::default()
}, },
config: SharedConfig { options: Options {
registration_open: true, registration_open: true,
article_approval, article_approval,
}, },