|
| 1 | +// Copyright 2025 New Vector Ltd. |
| 2 | +// |
| 3 | +// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial |
| 4 | +// Please see LICENSE files in the repository root for full details. |
| 5 | + |
| 6 | +use aide::transform::TransformOperation; |
| 7 | +use axum::{Json, extract::State}; |
| 8 | +use schemars::JsonSchema; |
| 9 | +use serde::Serialize; |
| 10 | + |
| 11 | +use crate::admin::call_context::CallContext; |
| 12 | + |
| 13 | +#[allow(clippy::struct_excessive_bools)] |
| 14 | +#[derive(Serialize, JsonSchema)] |
| 15 | +pub struct SiteConfig { |
| 16 | + /// The Matrix server name for which this instance is configured |
| 17 | + server_name: String, |
| 18 | + |
| 19 | + /// Whether password login is enabled. |
| 20 | + pub password_login_enabled: bool, |
| 21 | + |
| 22 | + /// Whether password registration is enabled. |
| 23 | + pub password_registration_enabled: bool, |
| 24 | + |
| 25 | + /// Whether registration tokens are required for password registrations. |
| 26 | + pub registration_token_required: bool, |
| 27 | + |
| 28 | + /// Whether users can change their email. |
| 29 | + pub email_change_allowed: bool, |
| 30 | + |
| 31 | + /// Whether users can change their display name. |
| 32 | + pub displayname_change_allowed: bool, |
| 33 | + |
| 34 | + /// Whether users can change their password. |
| 35 | + pub password_change_allowed: bool, |
| 36 | + |
| 37 | + /// Whether users can recover their account via email. |
| 38 | + pub account_recovery_allowed: bool, |
| 39 | + |
| 40 | + /// Whether users can delete their own account. |
| 41 | + pub account_deactivation_allowed: bool, |
| 42 | + |
| 43 | + /// Whether CAPTCHA during registration is enabled. |
| 44 | + pub captcha_enabled: bool, |
| 45 | + |
| 46 | + /// Minimum password complexity, between 0 and 4. |
| 47 | + /// This is a score from zxcvbn. |
| 48 | + #[schemars(range(min = 0, max = 4))] |
| 49 | + pub minimum_password_complexity: u8, |
| 50 | +} |
| 51 | + |
| 52 | +pub fn doc(operation: TransformOperation) -> TransformOperation { |
| 53 | + operation |
| 54 | + .id("siteConfig") |
| 55 | + .tag("server") |
| 56 | + .summary("Get informations about the configuration of this MAS instance") |
| 57 | + .response_with::<200, Json<SiteConfig>, _>(|t| { |
| 58 | + t.example(SiteConfig { |
| 59 | + server_name: "example.com".to_owned(), |
| 60 | + password_login_enabled: true, |
| 61 | + password_registration_enabled: true, |
| 62 | + registration_token_required: true, |
| 63 | + email_change_allowed: true, |
| 64 | + displayname_change_allowed: true, |
| 65 | + password_change_allowed: true, |
| 66 | + account_recovery_allowed: true, |
| 67 | + account_deactivation_allowed: true, |
| 68 | + captcha_enabled: true, |
| 69 | + minimum_password_complexity: 3, |
| 70 | + }) |
| 71 | + }) |
| 72 | +} |
| 73 | + |
| 74 | +#[tracing::instrument(name = "handler.admin.v1.site_config", skip_all)] |
| 75 | +pub async fn handler( |
| 76 | + _: CallContext, |
| 77 | + State(site_config): State<mas_data_model::SiteConfig>, |
| 78 | +) -> Json<SiteConfig> { |
| 79 | + Json(SiteConfig { |
| 80 | + server_name: site_config.server_name, |
| 81 | + password_login_enabled: site_config.password_login_enabled, |
| 82 | + password_registration_enabled: site_config.password_registration_enabled, |
| 83 | + registration_token_required: site_config.registration_token_required, |
| 84 | + email_change_allowed: site_config.email_change_allowed, |
| 85 | + displayname_change_allowed: site_config.displayname_change_allowed, |
| 86 | + password_change_allowed: site_config.password_change_allowed, |
| 87 | + account_recovery_allowed: site_config.account_recovery_allowed, |
| 88 | + account_deactivation_allowed: site_config.account_deactivation_allowed, |
| 89 | + captcha_enabled: site_config.captcha.is_some(), |
| 90 | + minimum_password_complexity: site_config.minimum_password_complexity, |
| 91 | + }) |
| 92 | +} |
0 commit comments