Skip to content
25 changes: 25 additions & 0 deletions manager/src/manager/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,31 @@ class UserSerializer(NonNullSerializer):
uid = serializers.CharField(source="pk", read_only=True)
acls = PubSubACLSerializer(many=True, required=False)

def validate(self, attrs):
is_update = self.instance is not None

if not is_update:
username = attrs.get('username', None)
password = attrs.get('password', None)

if not username or not username.strip():
raise serializers.ValidationError({'username': ['This field is required.']})
if not password:
raise serializers.ValidationError({'password': ['This field is required.']})

Comment thread
daddo-intel marked this conversation as resolved.
else:
if 'username' in self.initial_data:
username = attrs.get('username', '')
if not username or not username.strip():
raise serializers.ValidationError({'username': ['This field may not be blank.']})

if 'password' in self.initial_data:
password = attrs.get('password', '')
if not password:
Comment thread
daddo-intel marked this conversation as resolved.
Outdated
raise serializers.ValidationError({'password': ['This field may not be blank.']})

return super().validate(attrs)
Comment thread
daddo-intel marked this conversation as resolved.

def create_update(self, validated_data, instance=None):
is_update = instance is not None

Expand Down
Loading