From c6071740b1eacef0530b201566cb90b60635c641 Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 22 Mar 2023 16:43:00 +0800 Subject: [PATCH 1/2] =?UTF-8?q?perf:=20=E7=A1=AC=E4=BB=B6=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E6=94=AF=E6=8C=81=E8=B4=A6=E5=8F=B7=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/const/device.py | 5 ++++- apps/assets/const/host.py | 4 ++-- apps/assets/serializers/platform.py | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/assets/const/device.py b/apps/assets/const/device.py index d00996dd6..1a9f206b2 100644 --- a/apps/assets/const/device.py +++ b/apps/assets/const/device.py @@ -15,7 +15,10 @@ class DeviceTypes(BaseType): '*': { 'charset_enabled': False, 'domain_enabled': True, - 'su_enabled': False, + 'su_enabled': True, + 'su_methods': [ + {'name': 'enable', 'id': 'enable'}, + ] } } diff --git a/apps/assets/const/host.py b/apps/assets/const/host.py index eb7930b09..2139567a9 100644 --- a/apps/assets/const/host.py +++ b/apps/assets/const/host.py @@ -20,8 +20,8 @@ class HostTypes(BaseType): 'domain_enabled': True, 'su_enabled': True, 'su_methods': [ - {'name': 'sudo su', 'id': 'sudo su'}, - {'name': 'su -', 'id': 'su -'} + {'name': 'sudo su -', 'id': 'sudo'}, + {'name': 'su -', 'id': 'su'} ], }, cls.WINDOWS: { diff --git a/apps/assets/serializers/platform.py b/apps/assets/serializers/platform.py index 7485224e7..53be193a6 100644 --- a/apps/assets/serializers/platform.py +++ b/apps/assets/serializers/platform.py @@ -95,7 +95,7 @@ class PlatformSerializer(WritableNestedModelSerializer): ) automation = PlatformAutomationSerializer(label=_("Automation"), required=False) su_method = LabeledChoiceField( - choices=[("sudo", "sudo su -"), ("su", "su - ")], + choices=[("sudo", "sudo su -"), ("su", "su - "), ("enable", "enable")], label=_("Su method"), required=False, default="sudo", allow_null=True ) From 1e0a6b5072051ae3d361ccab1d808de925de3c9a Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 22 Mar 2023 17:17:49 +0800 Subject: [PATCH 2/2] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E4=B8=80?= =?UTF-8?q?=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/const/device.py | 4 +--- apps/assets/const/host.py | 5 +---- apps/assets/migrations/0111_auto_20230321_1633.py | 2 ++ 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/apps/assets/const/device.py b/apps/assets/const/device.py index 1a9f206b2..a3bc841a8 100644 --- a/apps/assets/const/device.py +++ b/apps/assets/const/device.py @@ -16,9 +16,7 @@ class DeviceTypes(BaseType): 'charset_enabled': False, 'domain_enabled': True, 'su_enabled': True, - 'su_methods': [ - {'name': 'enable', 'id': 'enable'}, - ] + 'su_methods': ['enable'] } } diff --git a/apps/assets/const/host.py b/apps/assets/const/host.py index 2139567a9..7b6c8818c 100644 --- a/apps/assets/const/host.py +++ b/apps/assets/const/host.py @@ -19,10 +19,7 @@ class HostTypes(BaseType): 'charset': 'utf-8', # default 'domain_enabled': True, 'su_enabled': True, - 'su_methods': [ - {'name': 'sudo su -', 'id': 'sudo'}, - {'name': 'su -', 'id': 'su'} - ], + 'su_methods': ['sudo', 'su'], }, cls.WINDOWS: { 'su_enabled': False, diff --git a/apps/assets/migrations/0111_auto_20230321_1633.py b/apps/assets/migrations/0111_auto_20230321_1633.py index 0f1ba7f14..314d2ed7f 100644 --- a/apps/assets/migrations/0111_auto_20230321_1633.py +++ b/apps/assets/migrations/0111_auto_20230321_1633.py @@ -14,6 +14,8 @@ def migrate_platform_protocol_primary(apps, schema_editor): for platform in platforms: p = platform.protocols.first() + if not p: + continue p.primary = True p.save()