18 lines
607 B
Python
18 lines
607 B
Python
import json
|
|
from ..db import get_db_connection, release_db_connection
|
|
|
|
def log_action(user_id, action, details=None):
|
|
"""Записывает действие пользователя в лог аудита."""
|
|
conn = get_db_connection()
|
|
try:
|
|
cur = conn.cursor()
|
|
cur.execute(
|
|
"INSERT INTO audit_log (user_id, action, details) VALUES (%s, %s, %s)",
|
|
(user_id, action, json.dumps(details) if details else None)
|
|
)
|
|
conn.commit()
|
|
except Exception as e:
|
|
print(f"Audit Log Error: {e}")
|
|
finally:
|
|
release_db_connection(conn)
|