Move RegistrationConfig type to mitra-config::registration module
This commit is contained in:
parent
d93c2ca23d
commit
0995186bc8
4 changed files with 45 additions and 40 deletions
|
@ -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() }
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
38
mitra-config/src/registration.rs
Normal file
38
mitra-config/src/registration.rs
Normal 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
|
||||
}
|
Loading…
Reference in a new issue