feat(integrations): добавлена проверка соединения для Recommerce
- Добавлен endpoint /test/<integration_id>/ для тестирования соединений - RecommerceService упрощён под реальное API (x-auth-token + store_url) - Кнопка "Проверить подключение" в UI с обработкой статусов - Миграция для удаления IntegrationConfig и обновления полей Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -103,6 +103,51 @@ def toggle_integration(request, integration_id: str):
|
||||
})
|
||||
|
||||
|
||||
@require_POST
|
||||
def test_integration_connection(request, integration_id: str):
|
||||
"""
|
||||
Тестировать соединение с интеграцией.
|
||||
POST /integrations/test/<integration_id>/
|
||||
"""
|
||||
if not hasattr(request, 'user') or not request.user.is_authenticated:
|
||||
return JsonResponse({'error': 'Unauthorized'}, status=401)
|
||||
|
||||
model = get_integration_model(integration_id)
|
||||
if not model:
|
||||
return JsonResponse({'error': f'Unknown integration: {integration_id}'}, status=404)
|
||||
|
||||
instance = model.objects.first()
|
||||
if not instance:
|
||||
return JsonResponse({'error': 'Интеграция не настроена'}, status=400)
|
||||
|
||||
if not instance.is_configured:
|
||||
return JsonResponse({'error': 'Заполните настройки интеграции'}, status=400)
|
||||
|
||||
# Получить сервис для интеграции
|
||||
service = get_integration_service(integration_id, instance)
|
||||
if not service:
|
||||
return JsonResponse({'error': 'Сервис не реализован'}, status=501)
|
||||
|
||||
# Выполнить тест
|
||||
success, message = service.test_connection()
|
||||
|
||||
return JsonResponse({
|
||||
'success': success,
|
||||
'message': message,
|
||||
})
|
||||
|
||||
|
||||
def get_integration_service(integration_id: str, instance):
|
||||
"""Получить сервис для интеграции"""
|
||||
if integration_id == 'recommerce':
|
||||
from .services.marketplaces.recommerce import RecommerceService
|
||||
return RecommerceService(instance)
|
||||
elif integration_id == 'woocommerce':
|
||||
# TODO: WooCommerceService
|
||||
return None
|
||||
return None
|
||||
|
||||
|
||||
@require_POST
|
||||
def save_integration_settings(request, integration_id: str):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user