perf: 优化license判断

pull/5780/head
ibuler 2021-03-17 17:08:49 +08:00 committed by Jiangjie.Bai
parent fd3a4d887e
commit c55e2db75e
2 changed files with 11 additions and 9 deletions

View File

@ -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'))

View File

@ -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,