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