mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-22 13:29:21 +00:00
Log admin requests to get user information
This commit is contained in:
parent
c14a0da518
commit
d0f87467ec
@ -5,8 +5,10 @@
|
|||||||
use crate::api_data::admin::admin_search_user_result_api::AdminSearchUserResult;
|
use crate::api_data::admin::admin_search_user_result_api::AdminSearchUserResult;
|
||||||
use crate::api_data::admin::admin_user_info_api::AdminUserInfoAPI;
|
use crate::api_data::admin::admin_user_info_api::AdminUserInfoAPI;
|
||||||
use crate::constants::admin::AdminRole;
|
use crate::constants::admin::AdminRole;
|
||||||
|
use crate::data::admin_action_log::AdminAction;
|
||||||
use crate::data::base_request_handler::BaseRequestHandler;
|
use crate::data::base_request_handler::BaseRequestHandler;
|
||||||
use crate::data::http_request_handler::HttpRequestHandler;
|
use crate::data::http_request_handler::HttpRequestHandler;
|
||||||
|
use crate::helpers::admin_log_helper::log_admin_action;
|
||||||
use crate::helpers::user_helper;
|
use crate::helpers::user_helper;
|
||||||
use crate::routes::RequestResult;
|
use crate::routes::RequestResult;
|
||||||
|
|
||||||
@ -29,5 +31,8 @@ pub fn get_single(r: &mut HttpRequestHandler) -> RequestResult {
|
|||||||
let user_id = r.post_user_id("user_id")?;
|
let user_id = r.post_user_id("user_id")?;
|
||||||
let user = user_helper::find_user_by_id(&user_id)?;
|
let user = user_helper::find_user_by_id(&user_id)?;
|
||||||
|
|
||||||
|
log_admin_action(r.admin_id()?, &r.remote_ip(),
|
||||||
|
AdminAction::AccessUserPage { user_id, user_name: user.full_name() })?;
|
||||||
|
|
||||||
r.set_response(AdminUserInfoAPI::new(user))
|
r.set_response(AdminUserInfoAPI::new(user))
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
//! # Admin action log
|
//! # Admin action log
|
||||||
|
|
||||||
use crate::data::admin::AdminID;
|
use crate::data::admin::AdminID;
|
||||||
|
use crate::data::user::UserID;
|
||||||
|
|
||||||
#[derive(serde::Serialize, serde::Deserialize, Clone)]
|
#[derive(serde::Serialize, serde::Deserialize, Clone)]
|
||||||
pub enum AdminAction {
|
pub enum AdminAction {
|
||||||
@ -13,6 +14,7 @@ pub enum AdminAction {
|
|||||||
UpdatedAdminGeneralSettings { target: AdminID, new_email: String, new_name: String },
|
UpdatedAdminGeneralSettings { target: AdminID, new_email: String, new_name: String },
|
||||||
AddAdminRole { target: AdminID, role: String },
|
AddAdminRole { target: AdminID, role: String },
|
||||||
RemoveAdminRole { target: AdminID, role: String },
|
RemoveAdminRole { target: AdminID, role: String },
|
||||||
|
AccessUserPage { user_id: UserID, user_name: String },
|
||||||
UnsupportedAction { raw_data: String },
|
UnsupportedAction { raw_data: String },
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,6 +47,8 @@ impl AdminAction {
|
|||||||
AdminAction::RemoveAdminRole { .. } =>
|
AdminAction::RemoveAdminRole { .. } =>
|
||||||
{ "Removed a role from [admin]{target}[/admin] => {role}" }
|
{ "Removed a role from [admin]{target}[/admin] => {role}" }
|
||||||
|
|
||||||
|
AdminAction::AccessUserPage { .. } => { "Administrator accessed information of user #{user_id} '{user_name}'." }
|
||||||
|
|
||||||
AdminAction::UnsupportedAction { .. } => { "Unsupported action. Raw data: {raw_data}" }
|
AdminAction::UnsupportedAction { .. } => { "Unsupported action. Raw data: {raw_data}" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
|
|
||||||
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
|
|
||||||
|
use crate::data::u64_visitor::U64Visitor;
|
||||||
use crate::utils::user_data_utils::user_data_url;
|
use crate::utils::user_data_utils::user_data_url;
|
||||||
|
|
||||||
///! User information
|
///! User information
|
||||||
@ -61,6 +64,20 @@ impl PartialEq<UserID> for &UserID {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Serialize for UserID {
|
||||||
|
fn serialize<S>(&self, serializer: S) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
|
||||||
|
S: Serializer {
|
||||||
|
serializer.serialize_u64(self.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'de> Deserialize<'de> for UserID {
|
||||||
|
fn deserialize<D>(deserializer: D) -> Result<Self, <D as Deserializer<'de>>::Error> where
|
||||||
|
D: Deserializer<'de> {
|
||||||
|
deserializer.deserialize_u64(U64Visitor {}).map(|id| UserID::new(id))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum UserPageVisibility {
|
pub enum UserPageVisibility {
|
||||||
OPEN,
|
OPEN,
|
||||||
|
Loading…
Reference in New Issue
Block a user