This commit is contained in:
alorig
2025-11-22 20:51:07 +05:00
parent e2c0d3d0fc
commit d4990fb088
4 changed files with 98 additions and 6 deletions

View File

@@ -52,6 +52,34 @@ class IntegrationViewSet(SiteSectorModelViewSet):
from rest_framework import serializers
class SiteIntegrationSerializer(serializers.ModelSerializer):
def validate(self, data):
"""
Custom validation for WordPress integrations.
Allow API key-only authentication (no username/password required).
"""
validated_data = super().validate(data)
# For WordPress platform, allow API key-only authentication
if validated_data.get('platform') == 'wordpress':
credentials = validated_data.get('credentials_json', {})
# If API key is provided, username/app_password are optional
if credentials.get('api_key'):
# API key authentication - no username/password required
pass
elif not credentials.get('username') or not credentials.get('app_password'):
# Traditional auth requires both username and app_password
if not credentials.get('username'):
raise serializers.ValidationError({
'credentials_json': 'Username is required when not using API key authentication.'
})
if not credentials.get('app_password'):
raise serializers.ValidationError({
'credentials_json': 'Application password is required when not using API key authentication.'
})
return validated_data
class Meta:
model = SiteIntegration
fields = '__all__'