mas_templates/context/
features.rs1use std::sync::Arc;
8
9use minijinja::{
10    Value,
11    value::{Enumerator, Object},
12};
13
14#[allow(clippy::struct_excessive_bools)]
16#[derive(Debug, Clone, Copy, PartialEq, Eq)]
17pub struct SiteFeatures {
18    pub password_registration: bool,
20
21    pub password_login: bool,
23
24    pub account_recovery: bool,
26
27    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}