STABLE: Final schema sync, optimized gitignore

This commit is contained in:
Kincses
2026-02-26 08:19:25 +01:00
parent 893f39fa15
commit 505543330a
203 changed files with 11590 additions and 9542 deletions

View File

@@ -1,31 +1,27 @@
# /opt/docker/dev/service_finder/backend/app/db/middleware.py
from fastapi import Request
from app.db.session import SessionLocal
from app.services.config_service import config
from app.db.session import AsyncSessionLocal
from app.models.audit import OperationalLog # JAVÍTVA: Az új modell
from sqlalchemy import text
import json
async def audit_log_middleware(request: Request, call_next):
logging_enabled = await config.get_setting('audit_log_enabled', default=True)
# Itt a config_service-t is aszinkron módon kell hívni, ha szükséges
response = await call_next(request)
if logging_enabled and request.method != 'GET': # GET-et általában nem naplózunk a zaj miatt, de állítható
if request.method != 'GET':
try:
user_id = getattr(request.state, 'user_id', None) # Ha már be van lépve
async with SessionLocal() as db:
await db.execute(text("""
INSERT INTO data.audit_logs (user_id, action, endpoint, method, ip_address)
VALUES (:u, :a, :e, :m, :ip)
"""), {
'u': user_id,
'a': f'API_CALL_{request.method}',
'e': str(request.url.path),
'm': request.method,
'ip': request.client.host
})
user_id = getattr(request.state, 'user_id', None)
async with AsyncSessionLocal() as db:
log = OperationalLog(
user_id=user_id,
action=f"API_CALL_{request.method}",
resource_type="ENDPOINT",
resource_id=str(request.url.path),
details={"ip": request.client.host, "method": request.method}
)
db.add(log)
await db.commit()
except Exception:
pass # A naplózás hibája nem akaszthatja meg a kiszolgálást
pass # A naplózás nem akaszthatja meg a folyamatot
return response
return response