mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-07-03 22:45:01 +00:00
Start to log administrator actions
This commit is contained in:
@ -2,9 +2,12 @@
|
||||
//!
|
||||
//! @author Pierre Hubert
|
||||
|
||||
use mysql::serde::{Deserializer, Serializer};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use webauthn_rs::proto::Credential;
|
||||
|
||||
use crate::constants::admin::{ADMIN_ROLES_LIST, AdminRole};
|
||||
use crate::data::u64_visitor::U64Visitor;
|
||||
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Debug, Hash)]
|
||||
pub struct AdminID(u64);
|
||||
@ -82,4 +85,18 @@ impl AdminRole {
|
||||
.next()
|
||||
.expect("Should have found a role!!!")
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for AdminID {
|
||||
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 AdminID {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, <D as Deserializer<'de>>::Error> where
|
||||
D: Deserializer<'de> {
|
||||
deserializer.deserialize_u64(U64Visitor {}).map(|id| AdminID::new(id))
|
||||
}
|
||||
}
|
26
src/data/admin_action_log.rs
Normal file
26
src/data/admin_action_log.rs
Normal file
@ -0,0 +1,26 @@
|
||||
//! # Admin action log
|
||||
|
||||
use crate::data::admin::AdminID;
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
pub enum AdminAction {
|
||||
AuthWithResetToken,
|
||||
AuthWithAccessKey { key: String, key_id: u64 },
|
||||
RegisteredAdminKey { name: String, target: AdminID },
|
||||
DeletedAdminKey { name: String, target: AdminID },
|
||||
GeneratedAdminResetToken { target: AdminID },
|
||||
CreatedAdmin { id: AdminID, name: String, email: String },
|
||||
UpdatedAdminGeneralSettings { target: AdminID, new_email: String, new_name: String },
|
||||
AddAdminRole { target: AdminID, role: String },
|
||||
RemoveAdminRole { target: AdminID, role: String },
|
||||
UnsupportedAction,
|
||||
}
|
||||
|
||||
|
||||
pub struct AdminActionLog {
|
||||
pub id: u64,
|
||||
pub admin_id: AdminID,
|
||||
pub ip: String,
|
||||
pub time: u64,
|
||||
pub action: AdminAction,
|
||||
}
|
@ -42,4 +42,6 @@ pub mod new_notifications_settings;
|
||||
pub mod push_notification;
|
||||
pub mod presence;
|
||||
pub mod admin;
|
||||
pub mod webauthn_config;
|
||||
pub mod webauthn_config;
|
||||
pub mod admin_action_log;
|
||||
pub mod u64_visitor;
|
20
src/data/u64_visitor.rs
Normal file
20
src/data/u64_visitor.rs
Normal file
@ -0,0 +1,20 @@
|
||||
use std::fmt;
|
||||
use std::fmt::Formatter;
|
||||
|
||||
use mysql::serde::de::Error;
|
||||
use serde::de::Visitor;
|
||||
|
||||
pub struct U64Visitor;
|
||||
|
||||
impl<'de> Visitor<'de> for U64Visitor {
|
||||
type Value = u64;
|
||||
|
||||
fn expecting<'a>(&self, formatter: &mut Formatter<'a>) -> fmt::Result {
|
||||
formatter.write_str("An unsigned integer value")
|
||||
}
|
||||
|
||||
fn visit_u64<E>(self, v: u64) -> Result<Self::Value, E> where
|
||||
E: Error, {
|
||||
Ok(v)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user