Browse Source

Simplify the root/zone lookup

develop
Drew Short 6 years ago
parent
commit
71a12ccf22
  1. 31
      src/config/model.rs

31
src/config/model.rs

@ -52,23 +52,36 @@ pub struct Config {
} }
impl Config { impl Config {
pub fn get_users_for_root_and_zone(&self, search_root: &str, search_zone: &str) -> Option<Vec<&UserConfig>> {
pub fn get_user(&self, username: &str) -> Option<&UserConfig> {
for user in &self.users {
if user.username == username {
return Some(user);
}
}
None
}
pub fn get_users_for_root_and_zone(&self, root: &str, zone: &str) -> Option<Vec<&UserConfig>> {
let mut users: Vec<&UserConfig> = Vec::new(); let mut users: Vec<&UserConfig> = Vec::new();
for user in &self.users { for user in &self.users {
for root in &user.roots {
let zone_match = &search_zone.to_string();
if root.root == search_root && root.zones.contains(zone_match) {
if user.has_root_and_zone(root, zone) {
users.push(user); users.push(user);
break;
} }
} }
if users.len() > 0 { Some(users) } else { None }
}
} }
if users.len() > 0 {
Some(users)
} else {
None
impl UserConfig {
pub fn has_root_and_zone(&self, search_root: &str, search_zone: &str) -> bool {
for root in &self.roots {
let zone_match = &search_zone.to_string();
if root.root == search_root && root.zones.contains(zone_match) {
return true;
}
} }
false
} }
} }
Loading…
Cancel
Save