[Update] 修复用户更新页面会清空用户public_key的问题

pull/3660/head
Bai 2020-01-20 11:27:34 +08:00
parent 13a042bc0f
commit da6a0c286d
1 changed files with 9 additions and 0 deletions

View File

@ -74,8 +74,17 @@ class UserSerializer(BulkSerializerMixin, serializers.ModelSerializer):
attrs['password_raw'] = password
return attrs
@staticmethod
def clean_auth_fields(attrs):
for field in ('password', 'public_key'):
value = attrs.get(field)
if not value:
attrs.pop(field, None)
return attrs
def validate(self, attrs):
attrs = self.change_password_to_raw(attrs)
attrs = self.clean_auth_fields(attrs)
return attrs