aboutsummaryrefslogtreecommitdiffstats
path: root/src/db.rs
diff options
context:
space:
mode:
authornecrashter2022-04-23 15:59:29 +0300
committerYigit Sever2022-04-23 18:10:12 +0300
commit435cda893bd74bd8e597876f4b5f515c8347f9de (patch)
treec3939c359d934e78548ad49bbb3290ab8a53530e /src/db.rs
parentbcf7a379620ca433215ad9617ad9417b4f39e87d (diff)
downloadgradecoin-435cda893bd74bd8e597876f4b5f515c8347f9de.tar.gz
gradecoin-435cda893bd74bd8e597876f4b5f515c8347f9de.tar.bz2
gradecoin-435cda893bd74bd8e597876f4b5f515c8347f9de.zip
Read preapproved users CSV file from config
Diffstat (limited to 'src/db.rs')
-rw-r--r--src/db.rs10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/db.rs b/src/db.rs
index e7fb137..2187010 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -15,8 +15,6 @@ use log::debug;
15use parking_lot::RwLock; 15use parking_lot::RwLock;
16use std::{collections::HashMap, fs, io, path::PathBuf, sync::Arc}; 16use std::{collections::HashMap, fs, io, path::PathBuf, sync::Arc};
17 17
18const PREAPPROVED_STU_FILENAME: &str = "students.csv";
19
20#[derive(Debug, Clone, Default)] 18#[derive(Debug, Clone, Default)]
21pub struct Db { 19pub struct Db {
22 pub blockchain: Arc<RwLock<Block>>, 20 pub blockchain: Arc<RwLock<Block>>,
@@ -35,7 +33,7 @@ impl Db {
35 let users: HashMap<Fingerprint, User> = get_friendly_users(); 33 let users: HashMap<Fingerprint, User> = get_friendly_users();
36 34
37 // Read the list of users who can register 35 // Read the list of users who can register
38 let preapproved_users = read_approved_users(); 36 let preapproved_users = read_approved_users(&config.preapproved_users);
39 37
40 let mut db = Db { 38 let mut db = Db {
41 blockchain: Arc::new(RwLock::new(Block::default())), 39 blockchain: Arc::new(RwLock::new(Block::default())),
@@ -184,14 +182,14 @@ fn get_friendly_users() -> HashMap<Fingerprint, User> {
184 users 182 users
185} 183}
186 184
187fn read_approved_users() -> Vec<MetuId> { 185fn read_approved_users(filename: &str) -> Vec<MetuId> {
188 let mut approved_students: Vec<MetuId> = Vec::new(); 186 let mut approved_students: Vec<MetuId> = Vec::new();
189 let contents = fs::read_to_string(PREAPPROVED_STU_FILENAME).unwrap_or_else(|_| { 187 let contents = fs::read_to_string(filename).unwrap_or_else(|_| {
190 panic!( 188 panic!(
191 "{}", 189 "{}",
192 format!( 190 format!(
193 "Expected {} in place to load preapproved students", 191 "Expected {} in place to load preapproved students",
194 PREAPPROVED_STU_FILENAME 192 filename
195 ) 193 )
196 ) 194 )
197 }); 195 });