mas_templates/context/
features.rs

1// Copyright 2024 New Vector Ltd.
2// Copyright 2024 The Matrix.org Foundation C.I.C.
3//
4// SPDX-License-Identifier: AGPL-3.0-only
5// Please see LICENSE 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 login is enabled.
22    pub password_login: bool,
23
24    /// Whether email-based account recovery is enabled.
25    pub account_recovery: bool,
26
27    /// Whether users can log in with their email address.
28    pub login_with_email_allowed: bool,
29}
30
31impl Object for SiteFeatures {
32    fn get_value(self: &Arc<Self>, field: &Value) -> Option<Value> {
33        match field.as_str()? {
34            "password_registration" => Some(Value::from(self.password_registration)),
35            "password_login" => Some(Value::from(self.password_login)),
36            "account_recovery" => Some(Value::from(self.account_recovery)),
37            "login_with_email_allowed" => Some(Value::from(self.login_with_email_allowed)),
38            _ => None,
39        }
40    }
41
42    fn enumerate(self: &Arc<Self>) -> Enumerator {
43        Enumerator::Str(&[
44            "password_registration",
45            "password_login",
46            "account_recovery",
47            "login_with_email_allowed",
48        ])
49    }
50}