41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
"""Consultation du journal d'audit."""
|
|
from fastapi import APIRouter, Depends
|
|
from sqlalchemy import select
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.core.database import get_db
|
|
from app.core.security import require_executif
|
|
from app.models.journal_action import JournalAction
|
|
|
|
router = APIRouter(prefix="/journal", tags=["Journal"])
|
|
|
|
|
|
@router.get("/actions")
|
|
async def journal_actions(
|
|
limite: int = 100,
|
|
executif=Depends(require_executif),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
limite = max(1, min(limite, 500))
|
|
result = await db.execute(
|
|
select(JournalAction)
|
|
.where(JournalAction.groupe_id == executif.groupe_id)
|
|
.order_by(JournalAction.cree_le.desc())
|
|
.limit(limite)
|
|
)
|
|
return [
|
|
{
|
|
"id": str(item.id),
|
|
"groupe_id": str(item.groupe_id) if item.groupe_id else None,
|
|
"membre_id": str(item.membre_id) if item.membre_id else None,
|
|
"admin_id": str(item.admin_id) if item.admin_id else None,
|
|
"methode": item.methode,
|
|
"chemin": item.chemin,
|
|
"statut_http": item.statut_http,
|
|
"adresse_ip": item.adresse_ip,
|
|
"user_agent": item.user_agent,
|
|
"details": item.details,
|
|
"cree_le": item.cree_le.isoformat(),
|
|
}
|
|
for item in result.scalars().all()
|
|
]
|