diff --git a/apps/jumpserver/utils.py b/apps/jumpserver/utils.py index 72a836892..d19d950e2 100644 --- a/apps/jumpserver/utils.py +++ b/apps/jumpserver/utils.py @@ -2,6 +2,8 @@ # from functools import partial from werkzeug.local import LocalProxy + +from django.conf import settings from common.local import thread_local @@ -17,4 +19,11 @@ def get_current_request(): return _find('current_request') +def has_valid_xpack_license(): + if not settings.XPACK_ENABLED: + return False + from xpack.plugins.license.models import License + return License.has_valid_license() + + current_request = LocalProxy(partial(_find, 'current_request')) diff --git a/apps/settings/api/common.py b/apps/settings/api/common.py index 04674d25b..8aafee063 100644 --- a/apps/settings/api/common.py +++ b/apps/settings/api/common.py @@ -10,6 +10,7 @@ from django.core.mail import send_mail, get_connection from django.utils.translation import ugettext_lazy as _ from django.templatetags.static import static +from jumpserver.utils import has_valid_xpack_license from common.permissions import IsSuperUser from common.utils import get_logger from .. import serializers @@ -94,14 +95,6 @@ class PublicSettingApi(generics.RetrieveAPIView): logo_urls.update({attr: getattr(obj, attr).url}) return logo_urls - @staticmethod - def get_xpack_license_is_valid(): - if not settings.XPACK_ENABLED: - return False - - from xpack.plugins.license.models import License - return License.has_valid_license() - @staticmethod def get_login_title(): default_title = _('Welcome to the JumpServer open source Bastion Host') @@ -121,7 +114,7 @@ class PublicSettingApi(generics.RetrieveAPIView): "SECURITY_MFA_VERIFY_TTL": settings.SECURITY_MFA_VERIFY_TTL, "SECURITY_COMMAND_EXECUTION": settings.SECURITY_COMMAND_EXECUTION, "SECURITY_PASSWORD_EXPIRATION_TIME": settings.SECURITY_PASSWORD_EXPIRATION_TIME, - "XPACK_LICENSE_IS_VALID": self.get_xpack_license_is_valid(), + "XPACK_LICENSE_IS_VALID": has_valid_xpack_license(), "LOGIN_TITLE": self.get_login_title(), "LOGO_URLS": self.get_logo_urls(), "TICKETS_ENABLED": settings.TICKETS_ENABLED,