Merge branch '#6_LDAP_Add_is_not_working' into 'main'
fix: all committee members should be properly updated now Closes #6 See merge request compsoc1/skynet/ldap/backend!3
This commit is contained in:
commit
b892326545
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<()> {
|
||||
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(());
|
||||
|
|
Loading…
Reference in a new issue