1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-04-11 15:10:53 +00:00
comunicapiv3/src/controllers/admin/admin_logs_controller.rs

20 lines
799 B
Rust

//! # Admin action history (logs) controller
//!
//! @author Pierre Hubert
use crate::routes::RequestResult;
use crate::data::http_request_handler::HttpRequestHandler;
use crate::data::base_request_handler::BaseRequestHandler;
use crate::helpers::{admin_roles_helper, admin_log_helper};
use crate::constants::admin::AdminRole;
use crate::api_data::admin::admin_log_api::AdminLogAPI;
/// Get the list of logs of the user
pub async fn get_list(r: &mut HttpRequestHandler) -> RequestResult {
let logs = match admin_roles_helper::has_role(r.admin_id()?, AdminRole::ACCESS_ALL_ADMINS_LOGS)? {
true => admin_log_helper::get_all_admin_logs(),
false => admin_log_helper::get_admin_logs(r.admin_id()?)
}?;
r.set_response(logs.iter().map(AdminLogAPI::new).collect::<Vec<_>>())
}