feat: log de actividad por usuario
- Tabla activity_log en SQLite (migración automática) - Registra: login, login_fallido, rda_enviado, rda_masivo, rda_directo, automation_run, contrato_creado, contrato_editado, contrato_toggle - Endpoint GET /logs/actividad con filtros por usuario, acción y fecha - UI /logs/actividad con badges de color por tipo de acción - Enlace "Actividad" en navegación lateral Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
8e29e2d04f
commit
c20e1a7476
@@ -9,6 +9,7 @@ from app.services.firebird_service import get_firebird_from_config
|
||||
from app.services.json_generator import generar_rda_paciente, agrupar_por_recepcion
|
||||
from app.services.api_client import get_tns_token, TNS_BASE
|
||||
from app.routes.contratos import load_contrato_map, load_excluded_set
|
||||
from app.utils.activity import log_activity, get_ip
|
||||
|
||||
router = APIRouter(prefix="/transaccion", tags=["transaccion"])
|
||||
|
||||
@@ -219,6 +220,10 @@ async def send_one(
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
factura_log = str(grupo_rows[0].get("NUM_FACTURA", idrecepcion))
|
||||
log_activity(user["user_id"], user["username"], "rda_enviado",
|
||||
f"Factura {factura_log} | Contrato {grupo_rows[0].get('CODCONTRATO','')} | {'OK' if ok_rda else 'ERROR: '+msg_tns[:80]}",
|
||||
get_ip(request))
|
||||
return JSONResponse({"success": ok_rda, "message": msg_tns, "raw_tns": raw_resp, "idrecepcion": idrecepcion})
|
||||
|
||||
|
||||
@@ -318,6 +323,9 @@ async def send_transaccion(
|
||||
|
||||
ok_count = sum(1 for r in resultados if r["success"])
|
||||
err_count = len(resultados) - ok_count
|
||||
log_activity(user["user_id"], user["username"], "rda_masivo",
|
||||
f"Enviados: {ok_count} OK, {err_count} errores, {excluidos_count} excluidos | {fecha_inicio} → {fecha_fin}",
|
||||
get_ip(request))
|
||||
return JSONResponse({
|
||||
"success": err_count == 0,
|
||||
"total_enviados": ok_count,
|
||||
@@ -429,6 +437,9 @@ async def send_direct(
|
||||
})
|
||||
|
||||
ok_count = sum(1 for r in resultados if r["success"])
|
||||
log_activity(user["user_id"], user["username"], "rda_directo",
|
||||
f"Factura {factura_str} | {'OK' if ok_count > 0 else 'ERROR'}",
|
||||
get_ip(request))
|
||||
return JSONResponse({
|
||||
"success": ok_count > 0,
|
||||
"total": len(resultados),
|
||||
|
||||
Reference in New Issue
Block a user