fix(typing): resolucion integral de advertencias de tipado, extraccion de payload con get_request_payload y limpieza de modelos
This commit is contained in:
@@ -8,13 +8,13 @@ class AuditService:
|
||||
"""Servicio para la captura y consulta de la bitácora inmutable de auditoría."""
|
||||
|
||||
@staticmethod
|
||||
def log(action: str, module: str, entity_id: Optional[int] = None,
|
||||
details: Optional[Any] = None, user: Optional[User] = None,
|
||||
def log(action: str, module: str, entity_id: Optional[Any] = None,
|
||||
details: Optional[Any] = None, user: Optional[Any] = None,
|
||||
ip_address: Optional[str] = None,
|
||||
user_id: Optional[int] = None,
|
||||
user_email: Optional[str] = None,
|
||||
user_id: Optional[Any] = None,
|
||||
user_email: Optional[Any] = None,
|
||||
status: Optional[str] = None,
|
||||
**kwargs) -> AuditLog:
|
||||
**kwargs) -> Optional[AuditLog]:
|
||||
"""
|
||||
Registra un evento de auditoría de forma segura e inmutable.
|
||||
"""
|
||||
@@ -28,8 +28,23 @@ class AuditService:
|
||||
|
||||
# 1. Determinar usuario actuante
|
||||
if user:
|
||||
user_id = user.id
|
||||
user_email = user.email
|
||||
user_id = getattr(user, 'id', None)
|
||||
user_email = getattr(user, 'email', None)
|
||||
|
||||
if user_id is not None:
|
||||
try:
|
||||
user_id = int(user_id)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if user_email is not None:
|
||||
user_email = str(user_email)
|
||||
|
||||
if entity_id is not None:
|
||||
try:
|
||||
entity_id = int(entity_id)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 2. IP de origen
|
||||
if not ip_address:
|
||||
|
||||
@@ -28,17 +28,18 @@ class CryptoService:
|
||||
return encrypted_bytes.decode('utf-8')
|
||||
|
||||
@classmethod
|
||||
def decrypt(cls, cipher_text: str) -> str:
|
||||
def decrypt(cls, cipher_text: Any) -> str:
|
||||
"""Descifra un texto cifrado y retorna el texto original. Si falla, retorna vacío."""
|
||||
if not cipher_text:
|
||||
return ''
|
||||
cipher_str = str(cipher_text)
|
||||
try:
|
||||
fernet = cls._get_fernet()
|
||||
decrypted_bytes = fernet.decrypt(cipher_text.encode('utf-8'))
|
||||
decrypted_bytes = fernet.decrypt(cipher_str.encode('utf-8'))
|
||||
return decrypted_bytes.decode('utf-8')
|
||||
except Exception:
|
||||
# Si no era un texto cifrado con Fernet o fue alterado, retornar el texto tal cual o vacío
|
||||
return cipher_text
|
||||
return cipher_str
|
||||
|
||||
crypto_service = CryptoService()
|
||||
|
||||
|
||||
@@ -105,12 +105,8 @@ class OptimizerService:
|
||||
with cls._lock:
|
||||
cls._jobs[job_id] = job
|
||||
|
||||
# Si no se pasó app explícitamente, intentar obtener current_app
|
||||
if app is None:
|
||||
try:
|
||||
app = getattr(current_app, '_get_current_object', lambda: current_app)()
|
||||
except Exception:
|
||||
app = None
|
||||
# No background app context required in FastAPI
|
||||
app = None
|
||||
|
||||
thread = threading.Thread(
|
||||
target=cls._run_job_worker,
|
||||
@@ -217,7 +213,7 @@ class OptimizerService:
|
||||
is_virtual=c_dto.isVirtual,
|
||||
is_active=True
|
||||
)
|
||||
room.id = c_dto.classroomId
|
||||
setattr(room, 'id', c_dto.classroomId)
|
||||
classrooms.append(room)
|
||||
else:
|
||||
classrooms = Classroom.query.filter_by(is_active=True).all()
|
||||
|
||||
Reference in New Issue
Block a user