Move RegistrationConfig type to mitra-config::registration module

This commit is contained in:
silverpill 2023-03-03 17:25:22 +00:00
parent d93c2ca23d
commit 0995186bc8
4 changed files with 45 additions and 40 deletions

View file

@ -2,11 +2,7 @@ use std::path::PathBuf;
use log::{Level as LogLevel};
use rsa::RsaPrivateKey;
use serde::{
Deserialize,
Deserializer,
de::Error as DeserializerError,
};
use serde::Deserialize;
use url::Url;
use mitra_utils::urls::normalize_url;
@ -15,42 +11,10 @@ use super::blockchain::BlockchainConfig;
use super::environment::Environment;
use super::federation::FederationConfig;
use super::limits::Limits;
use super::registration::RegistrationConfig;
use super::retention::RetentionConfig;
use super::MITRA_VERSION;
#[derive(Clone, PartialEq)]
pub enum RegistrationType {
Open,
Invite,
}
impl Default for RegistrationType {
fn default() -> Self { Self::Invite }
}
impl<'de> Deserialize<'de> for RegistrationType {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>
{
let registration_type_str = String::deserialize(deserializer)?;
let registration_type = match registration_type_str.as_str() {
"open" => Self::Open,
"invite" => Self::Invite,
_ => return Err(DeserializerError::custom("unknown registration type")),
};
Ok(registration_type)
}
}
#[derive(Clone, Default, Deserialize)]
pub struct RegistrationConfig {
#[serde(rename = "type")]
pub registration_type: RegistrationType,
#[serde(default)]
pub default_role_read_only_user: bool, // default is false
}
fn default_log_level() -> LogLevel { LogLevel::Info }
fn default_login_message() -> String { "Do not sign this message on other sites!".to_string() }

View file

@ -4,6 +4,7 @@ mod environment;
mod federation;
mod limits;
mod loader;
mod registration;
mod retention;
pub use blockchain::{
@ -11,9 +12,10 @@ pub use blockchain::{
EthereumConfig,
MoneroConfig,
};
pub use config::{Config, Instance, RegistrationType};
pub use config::{Config, Instance};
pub use environment::Environment;
pub use loader::parse_config;
pub use registration::RegistrationType;
pub const MITRA_VERSION: &str = env!("CARGO_PKG_VERSION");

View file

@ -13,8 +13,9 @@ use mitra_utils::{
files::{set_file_permissions, write_file},
};
use super::config::{Config, RegistrationType};
use super::config::Config;
use super::environment::Environment;
use super::registration::RegistrationType;
struct EnvConfig {
config_path: String,

View file

@ -0,0 +1,38 @@
use serde::{
Deserialize,
Deserializer,
de::Error as DeserializerError,
};
#[derive(Clone, PartialEq)]
pub enum RegistrationType {
Open,
Invite,
}
impl Default for RegistrationType {
fn default() -> Self { Self::Invite }
}
impl<'de> Deserialize<'de> for RegistrationType {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>
{
let registration_type_str = String::deserialize(deserializer)?;
let registration_type = match registration_type_str.as_str() {
"open" => Self::Open,
"invite" => Self::Invite,
_ => return Err(DeserializerError::custom("unknown registration type")),
};
Ok(registration_type)
}
}
#[derive(Clone, Default, Deserialize)]
pub struct RegistrationConfig {
#[serde(rename = "type")]
pub registration_type: RegistrationType,
#[serde(default)]
pub default_role_read_only_user: bool, // default is false
}