From bfee0c519b3cddbb41a9a58083919d3cf3217f18 Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Wed, 2 Aug 2023 13:51:14 +0100 Subject: [PATCH] fix: all committee members should be properly updated now --- src/bin/update_groups.rs | 57 ++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/src/bin/update_groups.rs b/src/bin/update_groups.rs index e1c4e9d..8ea1d30 100644 --- a/src/bin/update_groups.rs +++ b/src/bin/update_groups.rs @@ -8,14 +8,14 @@ use std::{collections::HashSet, env, error::Error}; async fn main() -> tide::Result<()> { let config = get_config(); - update_users(&config).await?; - update_admin(&config).await?; - update_committee(&config).await?; + update(&config).await?; Ok(()) } -async fn update_users(config: &Config) -> tide::Result<()> { +async fn update(config: &Config) -> tide::Result<()> { + dotenv().ok(); + let mut users_tmp = HashSet::new(); // default user to ensure group is never empty users_tmp.insert(String::from("compsoc")); @@ -31,6 +31,27 @@ async fn update_users(config: &Config) -> tide::Result<()> { users_tmp.insert(user); } + if let Ok(x) = env::var("USERS_ADMIN") { + let users = x.split(',').collect::>(); + + update_group(config, "skynet-admins", &users, true).await?; + // admins automatically get added as users + for user in users { + users_tmp.insert(user.to_string()); + } + } + + // read from teh env + if let Ok(x) = env::var("USERS_COMMITTEE") { + let users = x.split(',').collect::>(); + + update_group(config, "skynet-committee", &users, true).await?; + // committee automatically get added as users + for user in users { + users_tmp.insert(user.to_string()); + } + } + // sorting makes it easier/faster if let Ok(x) = env::var("USERS_BANNED") { for user in x.split(',').collect::>() { @@ -50,34 +71,6 @@ fn uid_to_dn(uid: &str) -> String { format!("uid={},ou=users,dc=skynet,dc=ie", uid) } -async fn update_admin(config: &Config) -> tide::Result<()> { - dotenv().ok(); - - // read from teh env - if let Ok(x) = env::var("USERS_ADMIN") { - let users = x.split(',').collect::>(); - - update_group(config, "skynet-admins", &users, true).await?; - // admins automatically get added as users - update_group(config, "skynet-users", &users, false).await?; - } - Ok(()) -} - -async fn update_committee(config: &Config) -> tide::Result<()> { - dotenv().ok(); - - // read from teh env - if let Ok(x) = env::var("USERS_COMMITTEE") { - let users = x.split(',').collect::>(); - - update_group(config, "skynet-committee", &users, true).await?; - // admins automatically get added as users - update_group(config, "skynet-users", &users, false).await?; - } - Ok(()) -} - async fn update_group(config: &Config, group: &str, users: &[&str], replace: bool) -> tide::Result<()> { if users.is_empty() { return Ok(());