feat(moodle): conectar moodle_api bidireccional, habilitar login delegado y sincronizacion hacia la app
This commit is contained in:
@@ -2344,6 +2344,12 @@ def update_moodle_settings():
|
||||
SystemSetting.set_value('moodle_auto_sync_enabled', auto_sync, 'Habilitación de sincronización periódica automática', category='sso_moodle')
|
||||
SystemSetting.set_value('moodle_sync_interval_minutes', sync_interval, 'Intervalo en minutos para sincronización periódica', category='sso_moodle')
|
||||
|
||||
if 'auth_moodle_enabled' in data:
|
||||
auth_enabled = 'true' if data.get('auth_moodle_enabled') in [True, 'true', '1', 'on'] else 'false'
|
||||
SystemSetting.set_value('auth_moodle_enabled', auth_enabled, 'Habilitar autenticación delegada con Moodle', category='sso_moodle')
|
||||
if 'service_name' in data:
|
||||
SystemSetting.set_value('moodle_service_name', str(data['service_name']).strip(), 'Nombre del servicio WebService Moodle', category='sso_moodle')
|
||||
|
||||
try:
|
||||
audit = AuditLog(
|
||||
user_id=acting_user.id,
|
||||
@@ -2379,6 +2385,22 @@ def test_moodle_connection():
|
||||
return jsonify(result), 400
|
||||
|
||||
|
||||
@api_admin_bp.route('/moodle/sync-from-moodle', methods=['POST'])
|
||||
@jwt_required
|
||||
def sync_data_from_moodle():
|
||||
"""Sincroniza usuarios, roles y catálogo desde Moodle hacia Admin Edu Space."""
|
||||
acting_user = getattr(g, 'jwt_user', None)
|
||||
if not (acting_user and (acting_user.is_admin() or getattr(acting_user, 'role', '').upper() == 'ADMIN')):
|
||||
return jsonify({'error': 'Forbidden', 'message': 'Acceso no autorizado.'}), 403
|
||||
|
||||
from app.services.moodle_client import moodle_client
|
||||
try:
|
||||
res = moodle_client.sync_from_moodle_to_app()
|
||||
return jsonify(res), 200
|
||||
except Exception as e:
|
||||
return jsonify({'success': False, 'error': str(e), 'message': f"Error al sincronizar desde Moodle: {str(e)}"}), 500
|
||||
|
||||
|
||||
@api_admin_bp.route('/moodle/queue/stats', methods=['GET'])
|
||||
@jwt_required
|
||||
def get_moodle_queue_stats():
|
||||
|
||||
Reference in New Issue
Block a user