1
This commit is contained in:
@@ -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__'
|
||||
|
||||
Reference in New Issue
Block a user