fix(ai-chat): harden prompt security against injections, fix login methods detection & align desktop input dock (v3.8.43)

This commit is contained in:
2026-10-28 06:48:10 -03:00
parent 63a90f06ad
commit 1fc653dce8
12 changed files with 305 additions and 181 deletions
+35 -8
View File
@@ -19,6 +19,7 @@ from app.models.enrollment import StudentEnrollment
from app.models.milestone import AcademicMilestone, MilestoneType
from app.models.grade import MilestoneGrade
from app.models.institutional_benefit import InstitutionalBenefit
from app.models.setting import SystemSetting
from app import db
from app.models.user import User
from app.services.gradebook_service import GradebookService
@@ -566,14 +567,40 @@ class LiveContextService:
}
]
# B. Búsqueda de Docentes / Profesores por Nombre
teacher_keywords = ['profesor', 'profesores', 'docente', 'docentes', 'llama', 'nombre', 'sergio']
if any(w in q_lower for w in teacher_keywords) or any(len(tok) >= 4 for tok in tokens):
# B. Consulta de Métodos de Login y Autenticación del Sistema
auth_keywords = ['login', 'logins', 'autenticacion', 'acceso', 'sso', 'google', 'moodle', 'credenciales', 'cuentas']
if any(ak in q_lower for ak in auth_keywords):
local_en = SystemSetting.get_value('auth_local_enabled', 'true') in ['true', 'True', '1', True]
google_en = SystemSetting.get_value('auth_google_enabled', 'false') in ['true', 'True', '1', True]
moodle_en = SystemSetting.get_value('auth_moodle_enabled', 'false') in ['true', 'True', '1', True]
active_methods = []
if local_en:
active_methods.append("Cuentas locales (Usuario y Contraseña)")
if google_en:
active_methods.append("Google Workspace (@unicaba.edu.ar)")
if moodle_en:
active_methods.append("Login delegado de Moodle SSO")
lines.append("\nESTADO DE MÉTODOS DE LOGIN Y AUTENTICACIÓN (CONFIGURACIÓN GLOBAL DEL SISTEMA):")
lines.append(f"• Login Local: {'Habilitado (Activo)' if local_en else 'Deshabilitado'}")
lines.append(f"• Google Workspace (@unicaba.edu.ar): {'Habilitado (Activo)' if google_en else 'Deshabilitado (Inactivo)'}")
lines.append(f"• Login Delegado de Moodle: {'Habilitado (Activo)' if moodle_en else 'Deshabilitado (Inactivo)'}")
if active_methods:
lines.append(f"• Métodos actualmente ACTIVOS: {', '.join(active_methods)}.")
else:
lines.append("• Métodos actualmente ACTIVOS: Ninguno habilitado.")
lines.append("• Gestión: El Administrador puede habilitar o deshabilitar estos métodos en Gobierno & Sistema ➔ Config. Global.")
# C. Búsqueda de Docentes / Profesores por Nombre (SOLO si la consulta trata sobre docentes)
teacher_keywords = ['profesor', 'profesores', 'docente', 'docentes', 'profe', 'profes', 'quien dicta', 'quien ensena']
if any(w in q_lower for w in teacher_keywords):
all_docentes = User.query.filter(User.is_active == True, func.lower(User.role).like('%docent%')).all()
meaningful_tokens = [
tok for tok in tokens
if tok not in {'profesor', 'profesores', 'docente', 'docentes', 'llamado', 'alguno', 'estan', 'registrados', 'cuantos', 'cual', 'quien', 'nombre'}
]
ignored_tokens = {
'profesor', 'profesores', 'docente', 'docentes', 'llamado', 'alguno', 'estan',
'registrados', 'cuantos', 'cual', 'quien', 'nombre', 'tipo', 'login', 'logins',
'google', 'moodle', 'sistema', 'acceso', 'cuentas', 'habilitados', 'activos'
}
meaningful_tokens = [tok for tok in tokens if tok not in ignored_tokens]
if meaningful_tokens:
found_teachers = []
for d in all_docentes:
@@ -590,7 +617,7 @@ class LiveContextService:
searched_name = meaningful_tokens[0].capitalize()
lines.append(f"\nBÚSQUEDA DE DOCENTES: No se encontraron profesores registrados con el nombre '{searched_name}' entre los {len(all_docentes)} docentes activos.")
# C. Búsqueda de Asignaturas
# D. Búsqueda de Asignaturas
if tokens:
search_filter = or_(
*[Subject.name.ilike(f"%{tok}%") for tok in tokens],