feat: 支持账号更新界面清空存在的秘钥信息

pull/9118/head
jiangweidong 2022-11-24 15:25:09 +08:00
parent abfd472a0a
commit 9e41ad0764
3 changed files with 6 additions and 4 deletions

View File

@ -83,7 +83,7 @@ class BaseAccount(JMSOrgBaseModel):
@lazyproperty
def public_key(self):
if self.secret_type == SecretType.SSH_KEY:
if self.secret_type == SecretType.SSH_KEY and self.private_key:
return ssh_pubkey_gen(private_key=self.private_key)
return None

View File

@ -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')

View File

@ -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)