Skip to main content

bitwarden_policies/policies/
send_options.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{PolicyDefinition, PolicyType, policy_type::PolicyDataType};
4
5/// Send Options policy.
6pub struct SendOptionsPolicy;
7
8impl PolicyDefinition for SendOptionsPolicy {
9    type Data = SendOptionsPolicyData;
10
11    fn policy_type(&self) -> PolicyType {
12        PolicyType::SendOptions
13    }
14
15    fn to_erased(&self, data: Self::Data) -> PolicyDataType {
16        PolicyDataType::SendOptions(data)
17    }
18}
19
20/// Configuration data for the Send Options policy.
21#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
22#[serde(rename_all = "camelCase")]
23#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
24#[bitwarden_ffi::wasm_record]
25pub struct SendOptionsPolicyData {
26    /// Whether members are prevented from hiding their email address from
27    /// Send recipients.
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub disable_hide_email: Option<bool>,
30}
31
32#[cfg(test)]
33mod tests {
34    use super::*;
35
36    #[test]
37    fn round_trips() {
38        let data = SendOptionsPolicyData {
39            disable_hide_email: Some(true),
40        };
41        let json = serde_json::to_string(&data).unwrap();
42        assert_eq!(json, r#"{"disableHideEmail":true}"#);
43        assert_eq!(
44            serde_json::from_str::<SendOptionsPolicyData>(&json).unwrap(),
45            data
46        );
47    }
48
49    #[test]
50    fn empty_serializes_to_empty_object() {
51        assert_eq!(
52            serde_json::to_string(&SendOptionsPolicyData::default()).unwrap(),
53            "{}"
54        );
55    }
56}