ilyass yani commited on
Commit ·
5564be8
1
Parent(s): 44c068e
Fix: add missing log_activity to dependencies (re-enable auth router)
Browse files- app/core/dependencies.py +17 -0
app/core/dependencies.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
from typing import Generator, Optional
|
| 2 |
from fastapi import Header, HTTPException, status, Depends
|
| 3 |
from sqlalchemy.orm import Session
|
|
@@ -7,6 +8,9 @@ from app.schemas.user import TokenData
|
|
| 7 |
from app.models.models import User, UserRole
|
| 8 |
|
| 9 |
|
|
|
|
|
|
|
|
|
|
| 10 |
def get_db() -> Generator[Session, None, None]:
|
| 11 |
"""
|
| 12 |
Dependency function for FastAPI to provide database sessions.
|
|
@@ -27,6 +31,19 @@ def get_db() -> Generator[Session, None, None]:
|
|
| 27 |
db.close()
|
| 28 |
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
def get_current_user(
|
| 31 |
authorization: Optional[str] = Header(None),
|
| 32 |
db: Session = Depends(get_db),
|
|
|
|
| 1 |
+
import logging
|
| 2 |
from typing import Generator, Optional
|
| 3 |
from fastapi import Header, HTTPException, status, Depends
|
| 4 |
from sqlalchemy.orm import Session
|
|
|
|
| 8 |
from app.models.models import User, UserRole
|
| 9 |
|
| 10 |
|
| 11 |
+
logger = logging.getLogger(__name__)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
def get_db() -> Generator[Session, None, None]:
|
| 15 |
"""
|
| 16 |
Dependency function for FastAPI to provide database sessions.
|
|
|
|
| 31 |
db.close()
|
| 32 |
|
| 33 |
|
| 34 |
+
def log_activity(db=None, action: str = "", user_id=None, detail: str = "", **kwargs):
|
| 35 |
+
"""
|
| 36 |
+
Best-effort activity logger used by auth and other routes.
|
| 37 |
+
|
| 38 |
+
It accepts db for backward compatibility but does not require it.
|
| 39 |
+
Any logging failure is swallowed so it never blocks the app startup or request flow.
|
| 40 |
+
"""
|
| 41 |
+
try:
|
| 42 |
+
logger.info("[activity] action=%s user_id=%s detail=%s extra=%s", action, user_id, detail, kwargs)
|
| 43 |
+
except Exception:
|
| 44 |
+
pass
|
| 45 |
+
|
| 46 |
+
|
| 47 |
def get_current_user(
|
| 48 |
authorization: Optional[str] = Header(None),
|
| 49 |
db: Session = Depends(get_db),
|