mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-25 23:09:22 +00:00
Can get the list of keys of an admin
This commit is contained in:
parent
3c4a5a53a1
commit
22b3a73db3
23
src/api_data/admin/admin_keys_api.rs
Normal file
23
src/api_data/admin/admin_keys_api.rs
Normal file
@ -0,0 +1,23 @@
|
||||
//! # Admin keys API
|
||||
//!
|
||||
//! @author Pierre Hubert
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::data::admin::AdminKey;
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct AdminKeyAPI {
|
||||
id: u64,
|
||||
name: String,
|
||||
time_add: u64,
|
||||
}
|
||||
|
||||
impl AdminKeyAPI {
|
||||
pub fn new(key: &AdminKey) -> Self {
|
||||
Self {
|
||||
id: key.id,
|
||||
name: key.name.to_string(),
|
||||
time_add: key.time_add,
|
||||
}
|
||||
}
|
||||
}
|
@ -6,3 +6,4 @@ pub mod admin_auth_options;
|
||||
pub mod admin_auth_success;
|
||||
pub mod admin_id_api;
|
||||
pub mod admin_info_api;
|
||||
pub mod admin_keys_api;
|
@ -8,6 +8,7 @@ use crate::api_data::admin::admin_auth_options::AdminAuthOptions;
|
||||
use crate::api_data::admin::admin_auth_success::AdminAuthSuccess;
|
||||
use crate::api_data::admin::admin_id_api::AdminIDAPI;
|
||||
use crate::api_data::admin::admin_info_api::AdminInfoAPI;
|
||||
use crate::api_data::admin::admin_keys_api::AdminKeyAPI;
|
||||
use crate::data::admin::{AdminKey, NewAdminGeneralSettings};
|
||||
use crate::data::base_request_handler::BaseRequestHandler;
|
||||
use crate::data::error::Res;
|
||||
@ -82,19 +83,27 @@ pub fn get_admin_info(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
false => admin_account_helper::find_admin_by_id(r.admin_id()?)?,
|
||||
true => {
|
||||
let admin_id = r.post_admin_id("id")?;
|
||||
|
||||
if admin_id == r.admin_id()? {
|
||||
admin_account_helper::find_admin_by_id(admin_id)?
|
||||
} else {
|
||||
// TODO
|
||||
unimplemented!();
|
||||
}
|
||||
admin_account_helper::find_admin_by_id(admin_id)?
|
||||
}
|
||||
};
|
||||
|
||||
r.set_response(AdminInfoAPI::new(&admin))
|
||||
}
|
||||
|
||||
/// Get an admin keys
|
||||
pub fn get_keys_list(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
let admin_id = r.post_admin_id("id")?;
|
||||
|
||||
if admin_id != r.admin_id()? {
|
||||
// TODO : implement
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
let keys = admin_account_key_helper::get_admin_keys(admin_id)?;
|
||||
|
||||
r.set_response(keys.iter().map(AdminKeyAPI::new).collect::<Vec<AdminKeyAPI>>())
|
||||
}
|
||||
|
||||
/// Update general settings
|
||||
pub fn update_general_settings(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
let admin_id = r.post_admin_id("id")?;
|
||||
|
@ -43,6 +43,7 @@ pub struct AdminKey {
|
||||
pub id: u64,
|
||||
pub admin_id: AdminID,
|
||||
pub name: String,
|
||||
pub time_add: u64,
|
||||
pub key: Credential,
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,7 @@ fn db_to_admin_key(row: &database::RowResult) -> Res<AdminKey> {
|
||||
id: row.get_u64("id")?,
|
||||
admin_id: row.get_admin_id("admin_id")?,
|
||||
name: row.get_str("name")?,
|
||||
time_add: row.get_u64("time_add")?,
|
||||
key: serde_json::from_str(&row.get_str("credential")?)?,
|
||||
})
|
||||
}
|
@ -352,6 +352,7 @@ pub fn get_routes() -> Vec<Route> {
|
||||
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/info", Box::new(admin_account_controller::get_admin_info)),
|
||||
Route::admin_post("/admin/accounts/keys", Box::new(admin_account_controller::get_keys_list)),
|
||||
Route::admin_post("/admin/accounts/update_general_settings", Box::new(admin_account_controller::update_general_settings)),
|
||||
Route::admin_post("/admin/accounts/challenge_register_key", Box::new(admin_account_controller::challenge_register_key)),
|
||||
Route::admin_post("/admin/accounts/register_key", Box::new(admin_account_controller::register_key)),
|
||||
|
Loading…
Reference in New Issue
Block a user