fix: all committee members should be properly updated now #30

Merged
silver merged 1 commit from #6_LDAP_Add_is_not_working into main 2023-08-02 12:59:20 +00:00

View file

@ -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::<Vec<&str>>();
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::<Vec<&str>>();
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::<Vec<&str>>() {
@ -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::<Vec<&str>>();
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::<Vec<&str>>();
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(());