use laterite_auth::{AuditEntry, AuthenticatedUser};
use crate::AdminState;
pub(crate) async fn record(
state: &AdminState,
user: &AuthenticatedUser,
action: &str,
target_type: Option<&str>,
target_id: Option<&str>,
detail: Option<&str>,
) {
let entry = AuditEntry {
actor_user_id: Some(user.user.id),
actor_username: &user.user.username,
action,
target_type,
target_id,
detail,
};
if let Err(e) = state.auth.record_audit(entry).await {
tracing::error!(action, error = %e, "failed to write audit log entry");
}
}
#[cfg(test)]
pub(crate) fn test_actor() -> AuthenticatedUser {
use laterite_auth::{BackendUser, PermissionSet};
AuthenticatedUser {
user: BackendUser {
id: 1,
username: "tester".to_string(),
email: "tester@example.test".to_string(),
first_name: "Test".to_string(),
last_name: None,
password_hash: String::new(),
is_superuser: true,
is_active: true,
timezone: None,
locale: None,
created_at: chrono::Utc::now(),
updated_at: chrono::Utc::now(),
},
permissions: PermissionSet::default(),
}
}