diff --git a/src/controllers/admin/admin_account_controller.rs b/src/controllers/admin/admin_account_controller.rs index 45bbfc1..153840f 100644 --- a/src/controllers/admin/admin_account_controller.rs +++ b/src/controllers/admin/admin_account_controller.rs @@ -55,6 +55,16 @@ pub fn get_admin_id(r: &mut HttpRequestHandler) -> RequestResult { r.set_response(AdminIDAPI::new(r.admin_id()?)) } +/// Get and return the list of administrators +pub fn get_list(r: &mut HttpRequestHandler) -> RequestResult { + let list = admin_account_helper::get_list()? + .iter() + .map(AdminInfoAPI::new) + .collect::>(); + + r.set_response(list) +} + /// Get current admin information pub fn get_admin_info(r: &mut HttpRequestHandler) -> RequestResult { let admin = match r.has_post_parameter("id") { diff --git a/src/helpers/admin_account_helper.rs b/src/helpers/admin_account_helper.rs index 390cf16..037d6ca 100644 --- a/src/helpers/admin_account_helper.rs +++ b/src/helpers/admin_account_helper.rs @@ -32,6 +32,12 @@ pub fn exists(id: AdminID) -> Res { .map(|r| r > 0) } +/// Get the entire list of administrators +pub fn get_list() -> Res> { + database::QueryInfo::new(ADMIN_LIST_TABLE) + .exec(db_to_admin) +} + /// Get admin information by ID pub fn find_admin_by_id(id: AdminID) -> Res { database::QueryInfo::new(ADMIN_LIST_TABLE) diff --git a/src/routes.rs b/src/routes.rs index 24da3b6..6b254f7 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -351,6 +351,7 @@ pub fn get_routes() -> Vec { Route::limited_admin_post_without_login("/admin/accounts/auth_with_reset_token", Box::new(admin_account_controller::auth_with_reset_token), LimitPolicy::FAILURE(5)), Route::admin_post("/admin/accounts/sign_out", Box::new(admin_account_controller::sign_out)), Route::admin_post("/admin/accounts/id", Box::new(admin_account_controller::get_admin_id)), + Route::admin_post("/admin/accounts/list", Box::new(admin_account_controller::get_list)), Route::admin_post("/admin/accounts/info", Box::new(admin_account_controller::get_admin_info)), Route::admin_post("/admin/accounts/update_general_settings", Box::new(admin_account_controller::update_general_settings)), Route::admin_post("/admin/accounts/generate_reset_token", Box::new(admin_account_controller::generate_reset_token)),