summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPietro Albini <pietro@pietroalbini.org>2019-07-04 15:56:20 +0200
committerPietro Albini <pietro@pietroalbini.org>2019-07-04 15:56:20 +0200
commit7d5494dddd98868fb28ab07107e346981c532834 (patch)
treebf39ebaa295b75c71d01a5850ad6d00d8c59a102 /src
parent49ea464dba0ef814c79a6e2001d9e63ef3898549 (diff)
prevent subteams of subteams at the validation level
Diffstat (limited to 'src')
-rw-r--r--src/validate.rs27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/validate.rs b/src/validate.rs
index 478515a..87f2354 100644
--- a/src/validate.rs
+++ b/src/validate.rs
@@ -1,8 +1,8 @@
use crate::data::Data;
use crate::schema::{Email, Permissions};
-use failure::{bail, ensure, Error};
+use failure::{bail, Error};
use regex::Regex;
-use std::collections::HashSet;
+use std::collections::{HashMap, HashSet};
static CHECKS: &[fn(&Data, &mut Vec<String>)] = &[
validate_wg_names,
@@ -64,14 +64,25 @@ fn validate_wg_names(data: &Data, errors: &mut Vec<String>) {
/// Ensure `subteam-of` points to an existing team
fn validate_subteam_of(data: &Data, errors: &mut Vec<String>) {
- let team_names: HashSet<_> = data.teams().map(|t| t.name()).collect();
+ let teams: HashMap<_, _> = data
+ .teams()
+ .map(|t| (t.name(), t.subteam_of().is_some()))
+ .collect();
wrapper(data.teams(), errors, |team, _| {
if let Some(subteam_of) = team.subteam_of() {
- ensure!(
- team_names.contains(subteam_of),
- "team `{}` doesn't exist",
- subteam_of
- );
+ match teams.get(subteam_of) {
+ Some(false) => {}
+ Some(true) => bail!(
+ "team `{}` can't be a subteam of a subteam (`{}`)",
+ team.name(),
+ subteam_of
+ ),
+ None => bail!(
+ "the parent of team `{}` doesn't exist: `{}`",
+ team.name(),
+ subteam_of
+ ),
+ }
}
Ok(())
});