feat: added support for skynet trainees
This commit is contained in:
parent
b0bc6f35c2
commit
303885ef0d
2 changed files with 28 additions and 18 deletions
|
@ -56,6 +56,7 @@
|
||||||
# special categories of users
|
# special categories of users
|
||||||
USERS_ADMIN = lib.strings.concatStringsSep "," cfg.users.admin;
|
USERS_ADMIN = lib.strings.concatStringsSep "," cfg.users.admin;
|
||||||
USERS_COMMITTEE = lib.strings.concatStringsSep "," cfg.users.committee;
|
USERS_COMMITTEE = lib.strings.concatStringsSep "," cfg.users.committee;
|
||||||
|
USERS_TRAINEE = lib.strings.concatStringsSep "," cfg.users.trainee;
|
||||||
USERS_LIFETIME = lib.strings.concatStringsSep "," cfg.users.lifetime;
|
USERS_LIFETIME = lib.strings.concatStringsSep "," cfg.users.lifetime;
|
||||||
USERS_BANNED = lib.strings.concatStringsSep "," cfg.users.banned;
|
USERS_BANNED = lib.strings.concatStringsSep "," cfg.users.banned;
|
||||||
USERS_RESTRICTED = lib.strings.concatStringsSep "," cfg.users.restricted;
|
USERS_RESTRICTED = lib.strings.concatStringsSep "," cfg.users.restricted;
|
||||||
|
@ -141,6 +142,11 @@
|
||||||
default = [];
|
default = [];
|
||||||
description = "array of committee members";
|
description = "array of committee members";
|
||||||
};
|
};
|
||||||
|
trainee = mkOption rec {
|
||||||
|
type = types.listOf types.str;
|
||||||
|
default = [];
|
||||||
|
description = "array of trainee admins";
|
||||||
|
};
|
||||||
lifetime = mkOption rec {
|
lifetime = mkOption rec {
|
||||||
type = types.listOf types.str;
|
type = types.listOf types.str;
|
||||||
default = [];
|
default = [];
|
||||||
|
|
|
@ -18,6 +18,7 @@ async fn update(config: &Config) -> tide::Result<()> {
|
||||||
let mut users_tmp = HashSet::from([String::from("compsoc")]);
|
let mut users_tmp = HashSet::from([String::from("compsoc")]);
|
||||||
let mut admins_tmp = HashSet::from([String::from("compsoc")]);
|
let mut admins_tmp = HashSet::from([String::from("compsoc")]);
|
||||||
let mut committee_tmp = HashSet::from([String::from("compsoc")]);
|
let mut committee_tmp = HashSet::from([String::from("compsoc")]);
|
||||||
|
let mut trainees_tmp = HashSet::from([String::from("compsoc")]);
|
||||||
|
|
||||||
if let Ok(x) = env::var("USERS_LIFETIME") {
|
if let Ok(x) = env::var("USERS_LIFETIME") {
|
||||||
for user in x.split(',').collect::<Vec<&str>>() {
|
for user in x.split(',').collect::<Vec<&str>>() {
|
||||||
|
@ -30,22 +31,9 @@ async fn update(config: &Config) -> tide::Result<()> {
|
||||||
users_tmp.insert(user);
|
users_tmp.insert(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(x) = env::var("USERS_ADMIN") {
|
get_from_env(&mut users_tmp, &mut admins_tmp, "USERS_ADMIN");
|
||||||
// admins automatically get added as users
|
get_from_env(&mut users_tmp, &mut committee_tmp, "USERS_COMMITTEE");
|
||||||
for user in x.split(',').collect::<Vec<&str>>() {
|
get_from_env(&mut users_tmp, &mut trainees_tmp, "USERS_TRAINEE");
|
||||||
admins_tmp.insert(user.to_string());
|
|
||||||
users_tmp.insert(user.to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// read from teh env
|
|
||||||
if let Ok(x) = env::var("USERS_COMMITTEE") {
|
|
||||||
// committee automatically get added as users
|
|
||||||
for user in x.split(',').collect::<Vec<&str>>() {
|
|
||||||
committee_tmp.insert(user.to_string());
|
|
||||||
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") {
|
||||||
|
@ -58,15 +46,27 @@ async fn update(config: &Config) -> tide::Result<()> {
|
||||||
users,
|
users,
|
||||||
admins,
|
admins,
|
||||||
committee,
|
committee,
|
||||||
} = get_secure(&db, &users_tmp, &admins_tmp, &committee_tmp).await;
|
trainees,
|
||||||
|
} = get_secure(&db, &users_tmp, &admins_tmp, &committee_tmp, &trainees_tmp).await;
|
||||||
|
|
||||||
update_group(config, "skynet-users", &users, true).await?;
|
update_group(config, "skynet-users", &users, true).await?;
|
||||||
update_group(config, "skynet-admins", &admins, true).await?;
|
update_group(config, "skynet-admins", &admins, true).await?;
|
||||||
update_group(config, "skynet-committee", &committee, true).await?;
|
update_group(config, "skynet-committee", &committee, true).await?;
|
||||||
|
update_group(config, "skynet-trainees", &trainees, true).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_from_env(users: &mut HashSet<String>, other: &mut HashSet<String>, key: &str) {
|
||||||
|
if let Ok(x) = env::var(key) {
|
||||||
|
// committee automatically get added as users
|
||||||
|
for user in x.split(',').collect::<Vec<&str>>() {
|
||||||
|
other.insert(user.to_string());
|
||||||
|
users.insert(user.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async fn from_csv(db: &Pool<Sqlite>) -> Result<HashSet<String>, Box<dyn Error>> {
|
async fn from_csv(db: &Pool<Sqlite>) -> Result<HashSet<String>, Box<dyn Error>> {
|
||||||
let mut uids = HashSet::new();
|
let mut uids = HashSet::new();
|
||||||
|
|
||||||
|
@ -125,15 +125,19 @@ struct AccountsSecure {
|
||||||
users: Vec<String>,
|
users: Vec<String>,
|
||||||
admins: Vec<String>,
|
admins: Vec<String>,
|
||||||
committee: Vec<String>,
|
committee: Vec<String>,
|
||||||
|
trainees: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_secure(db: &Pool<Sqlite>, users: &HashSet<String>, admins: &HashSet<String>, committee: &HashSet<String>) -> AccountsSecure {
|
async fn get_secure(
|
||||||
|
db: &Pool<Sqlite>, users: &HashSet<String>, admins: &HashSet<String>, committee: &HashSet<String>, trainees: &HashSet<String>,
|
||||||
|
) -> AccountsSecure {
|
||||||
// to avoid searching for teh same thing again.
|
// to avoid searching for teh same thing again.
|
||||||
let mut cache = HashSet::new();
|
let mut cache = HashSet::new();
|
||||||
AccountsSecure {
|
AccountsSecure {
|
||||||
users: get_secure_sub(db, users, &mut cache).await,
|
users: get_secure_sub(db, users, &mut cache).await,
|
||||||
admins: get_secure_sub(db, admins, &mut cache).await,
|
admins: get_secure_sub(db, admins, &mut cache).await,
|
||||||
committee: get_secure_sub(db, committee, &mut cache).await,
|
committee: get_secure_sub(db, committee, &mut cache).await,
|
||||||
|
trainees: get_secure_sub(db, trainees, &mut cache).await,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue