mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-07-10 01:22:48 +00:00
Can access admin logs from the API
This commit is contained in:
@ -5,7 +5,7 @@
|
||||
use crate::constants::conservation_policy::ADMIN_ACTIONS_LOG_LIFETIME;
|
||||
use crate::constants::database_tables_names::ADMIN_LOGS_TABLE;
|
||||
use crate::data::admin::AdminID;
|
||||
use crate::data::admin_action_log::AdminAction;
|
||||
use crate::data::admin_action_log::{AdminAction, AdminActionLog};
|
||||
use crate::data::error::Res;
|
||||
use crate::helpers::database;
|
||||
use crate::utils::date_utils::time;
|
||||
@ -26,4 +26,28 @@ pub fn clean_old_logs() -> Res {
|
||||
.set_custom_where("time < ?")
|
||||
.add_custom_where_arg_u64(time() - ADMIN_ACTIONS_LOG_LIFETIME.as_secs())
|
||||
.exec()
|
||||
}
|
||||
|
||||
|
||||
/// Get all administrators action log history
|
||||
pub fn get_all_admin_logs() -> Res<Vec<AdminActionLog>> {
|
||||
database::QueryInfo::new(ADMIN_LOGS_TABLE).exec(db_to_log)
|
||||
}
|
||||
|
||||
/// Get a specific administrator action log history
|
||||
pub fn get_admin_logs(id: AdminID) -> Res<Vec<AdminActionLog>> {
|
||||
database::QueryInfo::new(ADMIN_LOGS_TABLE)
|
||||
.cond_admin_id("admin_id", id)
|
||||
.exec(db_to_log)
|
||||
}
|
||||
|
||||
fn db_to_log(row: &database::RowResult) -> Res<AdminActionLog> {
|
||||
Ok(AdminActionLog {
|
||||
id: row.get_u64("id")?,
|
||||
admin_id: row.get_admin_id("admin_id")?,
|
||||
ip: row.get_str("ip")?,
|
||||
time: row.get_u64("time")?,
|
||||
action: serde_json::from_str(&row.get_str("action")?)
|
||||
.unwrap_or(AdminAction::UnsupportedAction),
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user