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: