fix: all committee members should be properly updated now #30
1 changed files with 25 additions and 32 deletions
|
@ -8,14 +8,14 @@ use std::{collections::HashSet, env, error::Error};
|
||||||
async fn main() -> tide::Result<()> {
|
async fn main() -> tide::Result<()> {
|
||||||
let config = get_config();
|
let config = get_config();
|
||||||
|
|
||||||
update_users(&config).await?;
|
update(&config).await?;
|
||||||
update_admin(&config).await?;
|
|
||||||
update_committee(&config).await?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update_users(config: &Config) -> tide::Result<()> {
|
async fn update(config: &Config) -> tide::Result<()> {
|
||||||
|
dotenv().ok();
|
||||||
|
|
||||||
let mut users_tmp = HashSet::new();
|
let mut users_tmp = HashSet::new();
|
||||||
// default user to ensure group is never empty
|
// default user to ensure group is never empty
|
||||||
users_tmp.insert(String::from("compsoc"));
|
users_tmp.insert(String::from("compsoc"));
|
||||||
|
@ -31,6 +31,27 @@ async fn update_users(config: &Config) -> tide::Result<()> {
|
||||||
users_tmp.insert(user);
|
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
|
// sorting makes it easier/faster
|
||||||
if let Ok(x) = env::var("USERS_BANNED") {
|
if let Ok(x) = env::var("USERS_BANNED") {
|
||||||
for user in x.split(',').collect::<Vec<&str>>() {
|
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)
|
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<()> {
|
async fn update_group(config: &Config, group: &str, users: &[&str], replace: bool) -> tide::Result<()> {
|
||||||
if users.is_empty() {
|
if users.is_empty() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
|
Loading…
Reference in a new issue