Enhance Content Management with New Taxonomy and Attribute Models

- Introduced `ContentTaxonomy` and `ContentAttribute` models for improved content categorization and attribute management.
- Updated `Content` model to support new fields for content format, cluster role, and external type.
- Refactored serializers and views to accommodate new models, including `ContentTaxonomySerializer` and `ContentAttributeSerializer`.
- Added new API endpoints for managing taxonomies and attributes, enhancing the content management capabilities.
- Updated admin interfaces for `Content`, `ContentTaxonomy`, and `ContentAttribute` to reflect new structures and improve usability.
- Implemented backward compatibility for existing attribute mappings.
- Enhanced filtering and search capabilities in the API for better content retrieval.
This commit is contained in:
IGNY8 VPS (Salman)
2025-11-22 00:21:00 +00:00
parent a82be89d21
commit 55dfd5ad19
17 changed files with 2934 additions and 40 deletions

View File

@@ -57,6 +57,78 @@ class IntegrationViewSet(SiteSectorModelViewSet):
status.HTTP_400_BAD_REQUEST,
request
)
from rest_framework.permissions import AllowAny
@action(detail=False, methods=['post'], url_path='test-connection', permission_classes=[AllowAny])
def test_connection_collection(self, request):
"""
Collection-level test connection endpoint for frontend convenience.
POST /api/v1/integration/integrations/test-connection/
Body:
{
"site_id": 123,
"api_key": "...",
"site_url": "https://example.com"
}
"""
site_id = request.data.get('site_id')
api_key = request.data.get('api_key')
site_url = request.data.get('site_url')
if not site_id:
return error_response('site_id is required', status.HTTP_400_BAD_REQUEST, request)
# Verify site exists
from igny8_core.auth.models import Site
try:
site = Site.objects.get(id=int(site_id))
except (Site.DoesNotExist, ValueError, TypeError):
return error_response('Site not found or invalid', status.HTTP_404_NOT_FOUND, request)
# Authentication: accept either authenticated user OR matching API key in body
api_key = request.data.get('api_key') or api_key
authenticated = False
# If request has a valid user and belongs to same account, allow
if hasattr(request, 'user') and getattr(request.user, 'is_authenticated', False):
try:
# If user has account, ensure site belongs to user's account
if site.account == request.user.account:
authenticated = True
except Exception:
# Ignore and fallback to api_key check
pass
# If not authenticated via session, allow if provided api_key matches site's stored wp_api_key
if not authenticated:
stored_key = getattr(site, 'wp_api_key', None)
if stored_key and api_key and str(api_key) == str(stored_key):
authenticated = True
if not authenticated:
return error_response('Authentication credentials were not provided.', status.HTTP_403_FORBIDDEN, request)
# Try to find an existing integration for this site+platform
integration = SiteIntegration.objects.filter(site=site, platform='wordpress').first()
# If not found, create a temporary in-memory integration object
if not integration:
integration = SiteIntegration(
site=site,
platform='wordpress',
config_json={'site_url': site_url} if site_url else {},
credentials_json={'api_key': api_key} if api_key else {},
is_active=False
)
service = IntegrationService()
result = service.test_connection(integration)
if result.get('success'):
return success_response(result, request=request)
else:
return error_response(result.get('message', 'Connection test failed'), status.HTTP_400_BAD_REQUEST, request)
@action(detail=True, methods=['post'])
def sync(self, request, pk=None):