From 1ec20a8f98e3226c1655f11fbf7c22a4ab44d564 Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Wed, 15 Feb 2023 17:46:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E4=B8=AD=E5=85=B3=E9=97=ADmagnus=20=E5=92=8C?= =?UTF-8?q?razor=20=E4=B8=8D=E7=94=9F=E6=95=88=20(#9563)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 修复系统设置中关闭magnus 和razor 不生效 * perf: 优化代码 --------- Co-authored-by: Aaron3S --- apps/terminal/api/component/connect_methods.py | 2 +- apps/terminal/connect_methods.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/apps/terminal/api/component/connect_methods.py b/apps/terminal/api/component/connect_methods.py index a284159d3..0c397558b 100644 --- a/apps/terminal/api/component/connect_methods.py +++ b/apps/terminal/api/component/connect_methods.py @@ -18,7 +18,7 @@ class ConnectMethodListApi(generics.ListAPIView): def get_queryset(self): os = get_request_os(self.request) - return ConnectMethodUtil.get_protocols_connect_methods(os) + return ConnectMethodUtil.get_filtered_protocols_connect_methods(os) def list(self, request, *args, **kwargs): queryset = self.get_queryset() diff --git a/apps/terminal/connect_methods.py b/apps/terminal/connect_methods.py index 0f6bfe476..1ad9fde6c 100644 --- a/apps/terminal/connect_methods.py +++ b/apps/terminal/connect_methods.py @@ -211,6 +211,22 @@ class ConnectMethodUtil: def refresh_methods(cls): cls._all_methods = None + @classmethod + def get_filtered_protocols_connect_methods(cls, os): + methods = dict(cls.get_protocols_connect_methods(os)) + component_setting = { + 'razor': 'TERMINAL_RAZOR_ENABLED', + 'magnus': 'TERMINAL_MAGNUS_ENABLED', + } + disabled_component = [comp for comp, attr in component_setting.items() if not getattr(settings, attr)] + if not disabled_component: + return methods + + for protocol, ms in methods.items(): + filtered_methods = [m for m in ms if m['component'] not in disabled_component] + methods[protocol] = filtered_methods + return methods + @classmethod def get_protocols_connect_methods(cls, os): if cls._all_methods is not None: