Skip to main content

bitwarden_policies/policies/
send_options.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{Policy, PolicyType, policy_type::PolicyDataType};
4
5/// Send Options policy.
6pub struct SendOptionsPolicy;
7
8impl Policy 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#[cfg_attr(
25    feature = "wasm",
26    derive(tsify::Tsify),
27    tsify(into_wasm_abi, from_wasm_abi)
28)]
29pub struct SendOptionsPolicyData {
30    /// Whether members are prevented from hiding their email address from
31    /// Send recipients.
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub disable_hide_email: Option<bool>,
34}
35
36#[cfg(test)]
37mod tests {
38    use super::*;
39
40    #[test]
41    fn round_trips() {
42        let data = SendOptionsPolicyData {
43            disable_hide_email: Some(true),
44        };
45        let json = serde_json::to_string(&data).unwrap();
46        assert_eq!(json, r#"{"disableHideEmail":true}"#);
47        assert_eq!(
48            serde_json::from_str::<SendOptionsPolicyData>(&json).unwrap(),
49            data
50        );
51    }
52
53    #[test]
54    fn empty_serializes_to_empty_object() {
55        assert_eq!(
56            serde_json::to_string(&SendOptionsPolicyData::default()).unwrap(),
57            "{}"
58        );
59    }
60}