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#[derive(Debug, Clone, Copy, PartialEq, Eq)]
16pub struct SiteFeatures {
17    /// Whether local password-based registration is enabled.
18    pub password_registration: bool,
19
20    /// Whether local password-based login is enabled.
21    pub password_login: bool,
22
23    /// Whether email-based account recovery is enabled.
24    pub account_recovery: bool,
25}
26
27impl Object for SiteFeatures {
28    fn get_value(self: &Arc<Self>, field: &Value) -> Option<Value> {
29        match field.as_str()? {
30            "password_registration" => Some(Value::from(self.password_registration)),
31            "password_login" => Some(Value::from(self.password_login)),
32            "account_recovery" => Some(Value::from(self.account_recovery)),
33            _ => None,
34        }
35    }
36
37    fn enumerate(self: &Arc<Self>) -> Enumerator {
38        Enumerator::Str(&[
39            "password_registration",
40            "password_login",
41            "account_recovery",
42        ])
43    }
44}