bitwarden_api_api/models/
policy_type.rs1use serde::{Deserialize, Deserializer, Serialize, Serializer, de::Visitor};
12
13use crate::models;
14#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
16pub enum PolicyType {
17 TwoFactorAuthentication,
18 MasterPassword,
19 PasswordGenerator,
20 SingleOrg,
21 RequireSso,
22 OrganizationDataOwnership,
23 DisableSend,
24 SendOptions,
25 ResetPassword,
26 MaximumVaultTimeout,
27 DisablePersonalVaultExport,
28 ActivateAutofill,
29 AutomaticAppLogIn,
30 FreeFamiliesSponsorshipPolicy,
31 RemoveUnlockWithPin,
32 RestrictedItemTypesPolicy,
33 UriMatchDefaults,
34 AutotypeDefaultSetting,
35 AutomaticUserConfirmation,
36 BlockClaimedDomainAccountCreation,
37 OrganizationUserNotification,
38 SendControls,
39
40 __Unknown(i64),
42}
43
44impl PolicyType {
45 pub fn as_i64(&self) -> i64 {
46 match self {
47 Self::TwoFactorAuthentication => 0,
48 Self::MasterPassword => 1,
49 Self::PasswordGenerator => 2,
50 Self::SingleOrg => 3,
51 Self::RequireSso => 4,
52 Self::OrganizationDataOwnership => 5,
53 Self::DisableSend => 6,
54 Self::SendOptions => 7,
55 Self::ResetPassword => 8,
56 Self::MaximumVaultTimeout => 9,
57 Self::DisablePersonalVaultExport => 10,
58 Self::ActivateAutofill => 11,
59 Self::AutomaticAppLogIn => 12,
60 Self::FreeFamiliesSponsorshipPolicy => 13,
61 Self::RemoveUnlockWithPin => 14,
62 Self::RestrictedItemTypesPolicy => 15,
63 Self::UriMatchDefaults => 16,
64 Self::AutotypeDefaultSetting => 17,
65 Self::AutomaticUserConfirmation => 18,
66 Self::BlockClaimedDomainAccountCreation => 19,
67 Self::OrganizationUserNotification => 20,
68 Self::SendControls => 21,
69 Self::__Unknown(v) => *v,
70 }
71 }
72
73 pub fn from_i64(value: i64) -> Self {
74 match value {
75 0 => Self::TwoFactorAuthentication,
76 1 => Self::MasterPassword,
77 2 => Self::PasswordGenerator,
78 3 => Self::SingleOrg,
79 4 => Self::RequireSso,
80 5 => Self::OrganizationDataOwnership,
81 6 => Self::DisableSend,
82 7 => Self::SendOptions,
83 8 => Self::ResetPassword,
84 9 => Self::MaximumVaultTimeout,
85 10 => Self::DisablePersonalVaultExport,
86 11 => Self::ActivateAutofill,
87 12 => Self::AutomaticAppLogIn,
88 13 => Self::FreeFamiliesSponsorshipPolicy,
89 14 => Self::RemoveUnlockWithPin,
90 15 => Self::RestrictedItemTypesPolicy,
91 16 => Self::UriMatchDefaults,
92 17 => Self::AutotypeDefaultSetting,
93 18 => Self::AutomaticUserConfirmation,
94 19 => Self::BlockClaimedDomainAccountCreation,
95 20 => Self::OrganizationUserNotification,
96 21 => Self::SendControls,
97 v => Self::__Unknown(v),
98 }
99 }
100}
101
102impl serde::Serialize for PolicyType {
103 fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
104 serializer.serialize_i64(self.as_i64())
105 }
106}
107
108impl<'de> serde::Deserialize<'de> for PolicyType {
109 fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
110 struct PolicyTypeVisitor;
111
112 impl Visitor<'_> for PolicyTypeVisitor {
113 type Value = PolicyType;
114
115 fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
116 f.write_str("an integer")
117 }
118
119 fn visit_i64<E: serde::de::Error>(self, v: i64) -> Result<Self::Value, E> {
120 Ok(PolicyType::from_i64(v))
121 }
122
123 fn visit_u64<E: serde::de::Error>(self, v: u64) -> Result<Self::Value, E> {
124 Ok(PolicyType::from_i64(v as i64))
125 }
126 }
127
128 deserializer.deserialize_i64(PolicyTypeVisitor)
129 }
130}
131
132impl std::fmt::Display for PolicyType {
133 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
134 write!(f, "{}", self.as_i64())
135 }
136}
137impl Default for PolicyType {
138 fn default() -> PolicyType {
139 Self::TwoFactorAuthentication
140 }
141}