mas_templates/context/
features.rs

1// Copyright 2024, 2025 New Vector Ltd.
2// Copyright 2024 The Matrix.org Foundation C.I.C.
3//
4// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
5// Please see LICENSE files in the repository root for full details.
6
7use std::sync::Arc;
8
9use minijinja::{
10    Value,
11    value::{Enumerator, Object},
12};
13
14/// Site features information.
15#[allow(clippy::struct_excessive_bools)]
16#[derive(Debug, Clone, Copy, PartialEq, Eq)]
17pub struct SiteFeatures {
18    /// Whether local password-based registration is enabled.
19    pub password_registration: bool,
20
21    /// Whether local password-based registration requires an email address.
22    pub password_registration_email_required: bool,
23
24    /// Whether local password-based login is enabled.
25    pub password_login: bool,
26
27    /// Whether email-based account recovery is enabled.
28    pub account_recovery: bool,
29
30    /// Whether users can log in with their email address.
31    pub login_with_email_allowed: bool,
32}
33
34impl Object for SiteFeatures {
35    fn get_value(self: &Arc<Self>, field: &Value) -> Option<Value> {
36        match field.as_str()? {
37            "password_registration" => Some(Value::from(self.password_registration)),
38            "password_registration_email_required" => {
39                Some(Value::from(self.password_registration_email_required))
40            }
41            "password_login" => Some(Value::from(self.password_login)),
42            "account_recovery" => Some(Value::from(self.account_recovery)),
43            "login_with_email_allowed" => Some(Value::from(self.login_with_email_allowed)),
44            _ => None,
45        }
46    }
47
48    fn enumerate(self: &Arc<Self>) -> Enumerator {
49        Enumerator::Str(&[
50            "password_registration",
51            "password_registration_email_required",
52            "password_login",
53            "account_recovery",
54            "login_with_email_allowed",
55        ])
56    }
57}