first commit
This commit is contained in:
20
app/services/audit.py
Normal file
20
app/services/audit.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
from flask_login import current_user
|
||||
|
||||
from ..extensions import db
|
||||
from ..models import AuditLog
|
||||
|
||||
|
||||
def log_action(action: str, target_type: str = '', target_id: str = '', **details) -> None:
|
||||
user_id = current_user.id if getattr(current_user, 'is_authenticated', False) else None
|
||||
entry = AuditLog(
|
||||
user_id=user_id,
|
||||
action=action,
|
||||
target_type=target_type,
|
||||
target_id=str(target_id or ''),
|
||||
details=json.dumps(details, ensure_ascii=False) if details else '',
|
||||
)
|
||||
db.session.add(entry)
|
||||
Reference in New Issue
Block a user