1
This commit is contained in:
@@ -161,13 +161,16 @@ class IntegrationService:
|
||||
|
||||
def test_connection(
|
||||
self,
|
||||
integration: SiteIntegration
|
||||
integration: SiteIntegration,
|
||||
is_initial_connection: bool = False
|
||||
) -> Dict[str, Any]:
|
||||
"""
|
||||
Test connection to the integrated platform.
|
||||
|
||||
Args:
|
||||
integration: SiteIntegration instance
|
||||
is_initial_connection: If True, allows connection test to pass even if WordPress
|
||||
plugin hasn't stored API key yet (for initial setup)
|
||||
|
||||
Returns:
|
||||
dict: {
|
||||
@@ -181,7 +184,7 @@ class IntegrationService:
|
||||
"""
|
||||
try:
|
||||
if integration.platform == 'wordpress':
|
||||
return self._test_wordpress_connection(integration)
|
||||
return self._test_wordpress_connection(integration, is_initial_connection=is_initial_connection)
|
||||
elif integration.platform == 'shopify':
|
||||
return self._test_shopify_connection(integration)
|
||||
else:
|
||||
@@ -201,7 +204,8 @@ class IntegrationService:
|
||||
|
||||
def _test_wordpress_connection(
|
||||
self,
|
||||
integration: SiteIntegration
|
||||
integration: SiteIntegration,
|
||||
is_initial_connection: bool = False
|
||||
) -> Dict[str, Any]:
|
||||
"""
|
||||
Test WordPress connection using API key only.
|
||||
@@ -301,13 +305,23 @@ class IntegrationService:
|
||||
except Exception as e:
|
||||
issues.append(f"Cannot detect IGNY8 plugin: {str(e)}")
|
||||
|
||||
# Success determination - only based on API key and plugin
|
||||
is_healthy = (
|
||||
health_checks['api_key_configured'] and
|
||||
health_checks['wp_rest_api_reachable'] and
|
||||
health_checks['plugin_installed'] and
|
||||
health_checks['plugin_has_api_key']
|
||||
)
|
||||
# Success determination
|
||||
# For initial connection, we don't require plugin_has_api_key yet
|
||||
# because WordPress hasn't stored it yet - that's what we're testing!
|
||||
# For subsequent health checks, we require all checks to pass
|
||||
if is_initial_connection:
|
||||
is_healthy = (
|
||||
health_checks['api_key_configured'] and
|
||||
health_checks['wp_rest_api_reachable'] and
|
||||
health_checks['plugin_installed']
|
||||
)
|
||||
else:
|
||||
is_healthy = (
|
||||
health_checks['api_key_configured'] and
|
||||
health_checks['wp_rest_api_reachable'] and
|
||||
health_checks['plugin_installed'] and
|
||||
health_checks['plugin_has_api_key']
|
||||
)
|
||||
|
||||
# Save site_url to config if successful and not already set
|
||||
if is_healthy and not config.get('site_url'):
|
||||
@@ -324,7 +338,11 @@ class IntegrationService:
|
||||
elif not health_checks['plugin_installed']:
|
||||
message = "⚠️ WordPress is reachable but IGNY8 plugin not installed"
|
||||
elif not health_checks['plugin_has_api_key']:
|
||||
message = "⚠️ Plugin is installed but API key not configured in WordPress"
|
||||
if is_initial_connection:
|
||||
# During initial connection, this is expected - WordPress will store the key after successful test
|
||||
message = "✅ WordPress integration ready - API key will be stored after connection"
|
||||
else:
|
||||
message = "⚠️ Plugin is installed but API key not configured in WordPress"
|
||||
else:
|
||||
message = "❌ WordPress connection failed"
|
||||
|
||||
|
||||
@@ -169,7 +169,10 @@ class IntegrationViewSet(SiteSectorModelViewSet):
|
||||
)
|
||||
|
||||
service = IntegrationService()
|
||||
result = service.test_connection(integration)
|
||||
# Mark this as initial connection test since API key was provided in request body
|
||||
# This allows the test to pass even if WordPress plugin hasn't stored the key yet
|
||||
is_initial_connection = bool(api_key and request.data.get('api_key'))
|
||||
result = service._test_wordpress_connection(integration, is_initial_connection=is_initial_connection)
|
||||
|
||||
if result.get('success'):
|
||||
return success_response(result, request=request)
|
||||
|
||||
Reference in New Issue
Block a user