mas_handlers/graphql/model/
site_config.rs1#![allow(clippy::str_to_string)] use async_graphql::{ComplexObject, Enum, ID, SimpleObject};
10use url::Url;
11
12pub const SITE_CONFIG_ID: &str = "site_config";
13pub const CAPTCHA_CONFIG_ID: &str = "captcha_config";
14
15#[derive(SimpleObject)]
16#[graphql(complex)]
17#[allow(clippy::struct_excessive_bools)]
18pub struct SiteConfig {
19 captcha_config: Option<CaptchaConfig>,
21
22 server_name: String,
24
25 policy_uri: Option<Url>,
27
28 tos_uri: Option<Url>,
30
31 imprint: Option<String>,
33
34 email_change_allowed: bool,
36
37 display_name_change_allowed: bool,
39
40 password_login_enabled: bool,
42
43 password_change_allowed: bool,
45
46 password_registration_enabled: bool,
48
49 account_deactivation_allowed: bool,
51
52 minimum_password_complexity: u8,
56
57 login_with_email_allowed: bool,
59}
60
61#[derive(SimpleObject)]
62#[graphql(complex)]
63pub struct CaptchaConfig {
64 pub service: CaptchaService,
66
67 pub site_key: String,
69}
70
71#[derive(Enum, Debug, Clone, Copy, PartialEq, Eq)]
73pub enum CaptchaService {
74 RecaptchaV2,
75 CloudflareTurnstile,
76 HCaptcha,
77}
78
79#[ComplexObject]
80impl SiteConfig {
81 pub async fn id(&self) -> ID {
83 SITE_CONFIG_ID.into()
84 }
85}
86
87impl SiteConfig {
88 pub fn new(data_model: &mas_data_model::SiteConfig) -> Self {
91 Self {
92 captcha_config: data_model.captcha.as_ref().map(CaptchaConfig::new),
93 server_name: data_model.server_name.clone(),
94 policy_uri: data_model.policy_uri.clone(),
95 tos_uri: data_model.tos_uri.clone(),
96 imprint: data_model.imprint.clone(),
97 email_change_allowed: data_model.email_change_allowed,
98 display_name_change_allowed: data_model.displayname_change_allowed,
99 password_login_enabled: data_model.password_login_enabled,
100 password_change_allowed: data_model.password_change_allowed,
101 password_registration_enabled: data_model.password_registration_enabled,
102 account_deactivation_allowed: data_model.account_deactivation_allowed,
103 minimum_password_complexity: data_model.minimum_password_complexity,
104 login_with_email_allowed: data_model.login_with_email_allowed,
105 }
106 }
107}
108
109#[ComplexObject]
110impl CaptchaConfig {
111 pub async fn id(&self) -> ID {
112 CAPTCHA_CONFIG_ID.into()
113 }
114}
115
116impl CaptchaConfig {
117 pub fn new(data_model: &mas_data_model::CaptchaConfig) -> Self {
120 Self {
121 service: match data_model.service {
122 mas_data_model::CaptchaService::RecaptchaV2 => CaptchaService::RecaptchaV2,
123 mas_data_model::CaptchaService::CloudflareTurnstile => {
124 CaptchaService::CloudflareTurnstile
125 }
126 mas_data_model::CaptchaService::HCaptcha => CaptchaService::HCaptcha,
127 },
128 site_key: data_model.site_key.clone(),
129 }
130 }
131}