Merge pull request #9119 from jumpserver/pr@v3@feat_support_clear_private_key

feat: 支持账号更新界面清空存在的秘钥信息
pull/9150/head
老广 2 years ago committed by GitHub
commit ab4c8402c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -86,8 +86,8 @@ class BaseAccount(JMSOrgBaseModel):
@lazyproperty
def public_key(self):
if self.secret_type == SecretType.SSH_KEY:
return parse_ssh_public_key_str(self.private_key)
if self.secret_type == SecretType.SSH_KEY and self.private_key:
return parse_ssh_public_key_str(private_key=self.private_key)
return None
@property

@ -72,7 +72,9 @@ class AccountSerializer(AccountSerializerCreateMixin, BaseAccountSerializer):
def __init__(self, *args, data=None, **kwargs):
super().__init__(*args, data=data, **kwargs)
if data and 'name' not in data:
data['name'] = data.get('username')
username = data.get('username')
if username is not None:
data['name'] = username
if hasattr(self, 'initial_data') and \
not getattr(self, 'initial_data', None):
delattr(self, 'initial_data')

@ -28,7 +28,7 @@ class AuthValidateMixin(serializers.Serializer):
def validate_secret(self, secret):
if not secret:
return
return ''
secret_type = self.initial_secret_type
if secret_type == SecretType.PASSWORD:
validate_password_for_ansible(secret)
@ -44,7 +44,7 @@ class AuthValidateMixin(serializers.Serializer):
def clean_auth_fields(validated_data):
for field in ('secret',):
value = validated_data.get(field)
if not value:
if value is None:
validated_data.pop(field, None)
validated_data.pop('passphrase', None)

Loading…
Cancel
Save