|
@ -44,24 +44,28 @@ pub enum UserOrgType { |
|
|
Manager = 3, |
|
|
Manager = 3, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
impl Ord for UserOrgType { |
|
|
impl UserOrgType { |
|
|
fn cmp(&self, other: &UserOrgType) -> Ordering { |
|
|
pub fn from_str(s: &str) -> Option<Self> { |
|
|
if self == other { |
|
|
match s { |
|
|
Ordering::Equal |
|
|
"0" | "Owner" => Some(UserOrgType::Owner), |
|
|
} else { |
|
|
"1" | "Admin" => Some(UserOrgType::Admin), |
|
|
match self { |
|
|
"2" | "User" => Some(UserOrgType::User), |
|
|
UserOrgType::Owner => Ordering::Greater, |
|
|
"3" | "Manager" => Some(UserOrgType::Manager), |
|
|
UserOrgType::Admin => match other { |
|
|
_ => None, |
|
|
UserOrgType::Owner => Ordering::Less, |
|
|
} |
|
|
_ => Ordering::Greater, |
|
|
|
|
|
}, |
|
|
|
|
|
UserOrgType::Manager => match other { |
|
|
|
|
|
UserOrgType::Owner | UserOrgType::Admin => Ordering::Less, |
|
|
|
|
|
_ => Ordering::Greater, |
|
|
|
|
|
}, |
|
|
|
|
|
UserOrgType::User => Ordering::Less, |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl Ord for UserOrgType { |
|
|
|
|
|
fn cmp(&self, other: &UserOrgType) -> Ordering { |
|
|
|
|
|
// For easy comparison, map each variant to an access level (where 0 is lowest).
|
|
|
|
|
|
static ACCESS_LEVEL: [i32; 4] = [ |
|
|
|
|
|
3, // Owner
|
|
|
|
|
|
2, // Admin
|
|
|
|
|
|
0, // User
|
|
|
|
|
|
1, // Manager
|
|
|
|
|
|
]; |
|
|
|
|
|
ACCESS_LEVEL[*self as usize].cmp(&ACCESS_LEVEL[*other as usize]) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -129,18 +133,6 @@ impl PartialOrd<UserOrgType> for i32 { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
impl UserOrgType { |
|
|
|
|
|
pub fn from_str(s: &str) -> Option<Self> { |
|
|
|
|
|
match s { |
|
|
|
|
|
"0" | "Owner" => Some(UserOrgType::Owner), |
|
|
|
|
|
"1" | "Admin" => Some(UserOrgType::Admin), |
|
|
|
|
|
"2" | "User" => Some(UserOrgType::User), |
|
|
|
|
|
"3" | "Manager" => Some(UserOrgType::Manager), |
|
|
|
|
|
_ => None, |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Local methods
|
|
|
/// Local methods
|
|
|
impl Organization { |
|
|
impl Organization { |
|
|
pub fn new(name: String, billing_email: String) -> Self { |
|
|
pub fn new(name: String, billing_email: String) -> Self { |
|
@ -533,3 +525,16 @@ impl UserOrganization { |
|
|
}} |
|
|
}} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[cfg(test)] |
|
|
|
|
|
mod tests { |
|
|
|
|
|
use super::*; |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
#[allow(non_snake_case)] |
|
|
|
|
|
fn partial_cmp_UserOrgType() { |
|
|
|
|
|
assert!(UserOrgType::Owner > UserOrgType::Admin); |
|
|
|
|
|
assert!(UserOrgType::Admin > UserOrgType::Manager); |
|
|
|
|
|
assert!(UserOrgType::Manager > UserOrgType::User); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|