From 480860ca2670e0847dd9518d750d65a44383b0db Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Mon, 17 Jul 2023 00:38:02 +0100 Subject: [PATCH] fix: make sure that an old csv does not cause issues. --- src/bin/update_groups.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/bin/update_groups.rs b/src/bin/update_groups.rs index e0c2004..22006c9 100644 --- a/src/bin/update_groups.rs +++ b/src/bin/update_groups.rs @@ -1,3 +1,4 @@ +use chrono::{Datelike, Utc}; use dotenv::dotenv; use ldap3::{LdapConn, Mod, Scope, SearchEntry}; use skynet_ldap_backend::{get_config, Config}; @@ -34,6 +35,7 @@ async fn update_users(config: &Config) -> tide::Result<()> { for every valid user in wolves match to ldap add to users */ + println!("{:#?}", users_tmp); // pull from wolves csv for user in from_csv(config).await.unwrap_or_default() { users_tmp.insert(user); @@ -46,6 +48,8 @@ async fn update_users(config: &Config) -> tide::Result<()> { } } + println!("{:#?}", users_tmp); + // easier to work with Strings above but easier to work with &str below let users: Vec<&str> = users_tmp.iter().map(|s| &**s).collect(); @@ -182,7 +186,15 @@ async fn from_csv(config: &Config) -> Result, Box> { let (uid_idstudent, uid_email) = ldap_get_accounts(config).await?; let records = read_csv()?; + let now = Utc::now(); + let today = format!("{}-{:02}-{:02}", now.year(), now.month(), now.day()); + for record in records { + // only import users if it is actually active. + if record.expiry < today { + continue; + } + if let Some(uid) = uid_email.get(&record.email) { uids.insert(uid.clone()); } @@ -202,6 +214,8 @@ struct Record { id_student: String, #[serde(rename = "Contact Email")] email: String, + #[serde(rename = "Expiry")] + expiry: String, } fn read_csv() -> Result, Box> {