fix(settings): corregir desincronizacion de metodos de autenticacion, normalizar claves de proveedores y añadir badges reactivos de estado

This commit is contained in:
2026-09-23 17:52:45 -03:00
parent b20e206a76
commit 5771476ee9
5 changed files with 330 additions and 38 deletions
+1
View File
@@ -218,6 +218,7 @@ app.use('/api/v1', async (req, res) => {
const targetUrl = `${process.env.FLASK_API_URL || 'http://localhost:5000/api/v1'}${req.url}`;
const headers = { ...req.headers };
delete headers.host;
delete headers['content-length'];
if (token && !headers.authorization) {
headers.authorization = `Bearer ${token}`;
}
+68 -1
View File
@@ -1321,6 +1321,43 @@ const handleGlobalSettings = async (req, res) => {
console.warn('Global settings fetch notice:', e.message);
}
// Normalización robusta de auth_providers para asegurar compatibilidad total con Nunjucks
if (settings && settings.auth_providers) {
const ap = settings.auth_providers;
const isLocal = ap.local !== undefined ? Boolean(ap.local) : (ap.local_enabled !== undefined ? Boolean(ap.local_enabled) : true);
const isGoogle = ap.google !== undefined ? Boolean(ap.google) : (ap.google_enabled !== undefined ? Boolean(ap.google_enabled) : false);
const isMoodle = ap.moodle !== undefined ? Boolean(ap.moodle) : (ap.moodle_enabled !== undefined ? Boolean(ap.moodle_enabled) : false);
settings.auth_providers = {
local: isLocal,
local_enabled: isLocal,
google: isGoogle,
google_enabled: isGoogle,
moodle: isMoodle,
moodle_enabled: isMoodle
};
} else {
settings.auth_providers = {
local: true,
local_enabled: true,
google: false,
google_enabled: false,
moodle: false,
moodle_enabled: false
};
}
if (settings && settings.smtp) {
settings.smtp.password_masked = settings.smtp.password_masked || settings.smtp.password || '';
settings.smtp.from_email = settings.smtp.from_email || settings.smtp.sender_email || '';
settings.smtp.from_name = settings.smtp.from_name || settings.smtp.sender_name || 'Admin Edu-Space';
}
if (settings && settings.google_oauth) {
settings.google_oauth.client_secret_masked = settings.google_oauth.client_secret_masked || settings.google_oauth.client_secret || '';
}
if (settings && settings.moodle) {
settings.moodle.ws_token_masked = settings.moodle.ws_token_masked || settings.moodle.ws_token || '';
}
try {
const demoResp = await req.apiClient.get('/settings/demo-mode');
if (demoResp.data) {
@@ -1359,6 +1396,37 @@ router.post('/settings/demo-mode', async (req, res) => {
}
});
// Endpoint explícito para consultar y actualizar métodos de autenticación
router.get('/settings/auth-providers', async (req, res) => {
try {
const resp = await req.apiClient.get('/settings/all');
const ap = resp.data?.settings?.auth_providers || resp.data?.data?.auth_providers || {};
return res.json({
status: 'success',
auth_providers: {
local: ap.local !== undefined ? Boolean(ap.local) : (ap.local_enabled !== undefined ? Boolean(ap.local_enabled) : true),
google: ap.google !== undefined ? Boolean(ap.google) : (ap.google_enabled !== undefined ? Boolean(ap.google_enabled) : false),
moodle: ap.moodle !== undefined ? Boolean(ap.moodle) : (ap.moodle_enabled !== undefined ? Boolean(ap.moodle_enabled) : false)
}
});
} catch (err) {
return res.status(500).json({ status: 'error', message: err.message });
}
});
router.post('/settings/auth-providers', async (req, res) => {
try {
const resp = await req.apiClient.post('/settings/auth-providers', req.body);
return res.status(resp.status || 200).json(resp.data);
} catch (err) {
console.error('Error in POST /admin/settings/auth-providers:', err.response?.data || err.message);
return res.status(err.response?.status || 500).json(err.response?.data || {
status: 'error',
message: 'Error al actualizar métodos de autenticación: ' + (err.response?.data?.message || err.message)
});
}
});
// Función forwarder para acciones de configuración hacia Flask
const forwardSettingsAction = async (req, res) => {
try {
@@ -1381,7 +1449,6 @@ const forwardSettingsAction = async (req, res) => {
router.post('/settings/smtp', forwardSettingsAction);
router.post('/settings/smtp/test', forwardSettingsAction);
router.post('/settings/auth-providers', forwardSettingsAction);
router.post('/settings/google-oauth', forwardSettingsAction);
router.post('/settings/moodle', forwardSettingsAction);
router.post('/settings/moodle/test', forwardSettingsAction);