Commit 18c6006a authored by Brad King's avatar Brad King 💬 Committed by Kitware Robot
Browse files

Merge topic 'access-level-improvement'

52e1ce3c AccessLevel: support casting from u64
e78a06c7

 AccessLevel: add an "anonymous" level
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Reviewed-by: Brad King's avatarBrad King <brad.king@kitware.com>
Merge-request: !37
parents 45f6daab 52e1ce3c
......@@ -495,6 +495,8 @@ pub struct Project {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
/// Access levels for groups and projects.
pub enum AccessLevel {
/// Anonymous access.
Anonymous,
/// Guest access (can see the project).
Guest,
/// Reporter access (can open issues).
......@@ -510,6 +512,7 @@ pub enum AccessLevel {
impl From<AccessLevel> for u64 {
fn from(access: AccessLevel) -> Self {
match access {
AccessLevel::Anonymous => 0,
AccessLevel::Guest => 10,
AccessLevel::Reporter => 20,
AccessLevel::Developer => 30,
......@@ -519,6 +522,24 @@ impl From<AccessLevel> for u64 {
}
}
impl From<u64> for AccessLevel {
fn from(access: u64) -> Self {
if access >= 50 {
AccessLevel::Owner
} else if access >= 40 {
AccessLevel::Master
} else if access >= 30 {
AccessLevel::Developer
} else if access >= 20 {
AccessLevel::Reporter
} else if access >= 10 {
AccessLevel::Guest
} else {
AccessLevel::Anonymous
}
}
}
impl Display for AccessLevel {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "{}", Into::<u64>::into(self.clone()))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment