fix(sheets-import): increase express payload limit to 50MB and add comprehensive incident diagnosis and system error audit

This commit is contained in:
2026-10-09 10:31:52 -03:00
parent 1edd81516a
commit be5da21649
11 changed files with 317 additions and 32 deletions
+51 -2
View File
@@ -2872,7 +2872,7 @@ def get_audit_logs():
modules = sorted(list(set([r[0].lower() for r in modules_tuples if r[0]])))
actions = sorted(list(set([r[0].upper() for r in actions_tuples if r[0]])))
default_modules = ['auth', 'reservations', 'classrooms', 'buildings', 'academic', 'optimizer', 'users', 'admin']
default_modules = ['auth', 'reservations', 'classrooms', 'buildings', 'academic', 'optimizer', 'users', 'admin', 'system', 'import']
for m in default_modules:
if m not in modules:
modules.append(m)
@@ -2881,7 +2881,8 @@ def get_audit_logs():
'LOGIN', 'LOGIN_FAILED', 'LOGIN_BLOCKED', 'LOGIN_GOOGLE', 'LOGIN_MOODLE', 'LOGOUT',
'PASSWORD_CHANGE', 'IMPERSONATE_START', 'IMPERSONATE_END',
'CREATE', 'UPDATE', 'DELETE', 'CONFIRM', 'CANCEL', 'TOGGLE',
'OPTIMIZE_RUN', 'OPTIMIZE_APPLY', 'SYSTEM_RESET'
'OPTIMIZE_RUN', 'OPTIMIZE_APPLY', 'SYSTEM_RESET', 'SYSTEM_ERROR',
'SHEETS_IMPORT', 'SHEETS_IMPORT_ERROR'
]
for a in default_actions:
if a not in actions:
@@ -2906,3 +2907,51 @@ def get_audit_logs():
}), 200
@api_admin_bp.route('/log-error', methods=['POST'])
def log_system_error():
"""
Endpoint para registrar incidentes técnicos o errores no controlados
provenientes del frontend BFF o subsistemas en AuditLog.
"""
try:
data = request.get_json(silent=True) or {}
incident_id = data.get('incident_id')
error_title = data.get('error_title', 'Error de Sistema')
error_message = data.get('error_message', 'Error desconocido')
status_code = data.get('status_code', 500)
path = data.get('path', '')
user_email = data.get('user_email') or 'anonymous'
ip_address = data.get('ip_address') or request.remote_addr
stack = data.get('stack', '')
details = {
'incident_id': incident_id,
'title': error_title,
'message': error_message,
'status_code': status_code,
'path': path,
'stack_preview': stack[:500] if stack else ''
}
AuditService.log(
action='SYSTEM_ERROR',
module='system',
user_email=user_email,
ip_address=ip_address,
details=details,
status='failed'
)
return jsonify({
'status': 'success',
'logged': True,
'incident_id': incident_id
}), 200
except Exception as e:
return jsonify({
'status': 'error',
'message': str(e)
}), 500