From 044fd238b8afb64fbfda225c2cfc6ff636c4f943 Mon Sep 17 00:00:00 2001 From: feng <1304903146@qq.com> Date: Mon, 21 Oct 2024 15:23:26 +0800 Subject: [PATCH] perf: Remove ssh_key_change_strategy add value --- .../serializers/automations/change_secret.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/apps/accounts/serializers/automations/change_secret.py b/apps/accounts/serializers/automations/change_secret.py index 7e12ea848..2334880b9 100644 --- a/apps/accounts/serializers/automations/change_secret.py +++ b/apps/accounts/serializers/automations/change_secret.py @@ -63,6 +63,26 @@ class ChangeSecretAutomationSerializer(AuthValidateMixin, BaseAutomationSerializ )}, }} + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.set_ssh_key_change_strategy_choices() + + def set_ssh_key_change_strategy_choices(self): + ssh_key_change_strategy = self.fields.get("ssh_key_change_strategy") + if not ssh_key_change_strategy: + return + ssh_key_change_strategy._choices.pop(SSHKeyStrategy.add, None) + + def to_representation(self, instance): + data = super().to_representation(instance) + ssh_strategy_value = data.get('ssh_key_change_strategy', {}).get('value') + if ssh_strategy_value == SSHKeyStrategy.add: + data['ssh_key_change_strategy'] = { + 'label': SSHKeyStrategy.set_jms.label, + 'value': SSHKeyStrategy.set_jms.value + } + return data + @property def model_type(self): return AutomationTypes.change_secret