1
0
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:
Pierre HUBERT 2021-07-12 19:00:41 +02:00
parent c14a0da518
commit d0f87467ec
3 changed files with 26 additions and 0 deletions

View File

@ -5,8 +5,10 @@
use crate::api_data::admin::admin_search_user_result_api::AdminSearchUserResult;
use crate::api_data::admin::admin_user_info_api::AdminUserInfoAPI;
use crate::constants::admin::AdminRole;
use crate::data::admin_action_log::AdminAction;
use crate::data::base_request_handler::BaseRequestHandler;
use crate::data::http_request_handler::HttpRequestHandler;
use crate::helpers::admin_log_helper::log_admin_action;
use crate::helpers::user_helper;
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 = 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))
}

View File

@ -1,6 +1,7 @@
//! # Admin action log
use crate::data::admin::AdminID;
use crate::data::user::UserID;
#[derive(serde::Serialize, serde::Deserialize, Clone)]
pub enum AdminAction {
@ -13,6 +14,7 @@ pub enum AdminAction {
UpdatedAdminGeneralSettings { target: AdminID, new_email: String, new_name: String },
AddAdminRole { target: AdminID, role: String },
RemoveAdminRole { target: AdminID, role: String },
AccessUserPage { user_id: UserID, user_name: String },
UnsupportedAction { raw_data: String },
}
@ -45,6 +47,8 @@ impl AdminAction {
AdminAction::RemoveAdminRole { .. } =>
{ "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}" }
}
}

View File

@ -1,5 +1,8 @@
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;
///! 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)]
pub enum UserPageVisibility {
OPEN,