diff --git a/apps/authentication/mfa/face.py b/apps/authentication/mfa/face.py index c37eae526..60ff2c247 100644 --- a/apps/authentication/mfa/face.py +++ b/apps/authentication/mfa/face.py @@ -5,6 +5,7 @@ from django.shortcuts import reverse from django.utils.translation import gettext_lazy as _ from authentication.mixins import MFAFaceMixin +from common.const import LicenseEditionChoices from settings.api import settings @@ -32,7 +33,10 @@ class MFAFace(BaseMFA, MFAFaceMixin): @staticmethod def global_enabled(): - return settings.XPACK_LICENSE_IS_VALID and settings.FACE_RECOGNITION_ENABLED + return settings.XPACK_LICENSE_IS_VALID \ + and LicenseEditionChoices.ULTIMATE == \ + LicenseEditionChoices.from_key(settings.XPACK_LICENSE_EDITION) \ + and settings.FACE_RECOGNITION_ENABLED def get_enable_url(self) -> str: return reverse('authentication:user-face-enable') diff --git a/apps/common/const/choices.py b/apps/common/const/choices.py index 3eb0f2a58..804ab7b1a 100644 --- a/apps/common/const/choices.py +++ b/apps/common/const/choices.py @@ -76,3 +76,32 @@ class Language(models.TextChoices): COUNTRY_CALLING_CODES = get_country_phone_choices() + + +class LicenseEditionChoices(models.TextChoices): + COMMUNITY = 'community', _('Community edition') + BASIC = 'basic', _('Basic edition') + STANDARD = 'standard', _('Standard edition') + PROFESSIONAL = 'professional', _('Professional edition') + ULTIMATE = 'ultimate', _('Ultimate edition') + + @staticmethod + def from_key(key: str): + for choice in LicenseEditionChoices: + if choice == key: + return choice + return LicenseEditionChoices.COMMUNITY + @staticmethod + def parse_license_edition(info): + count = info.get('license', {}).get('count', 0) + + if 50 >= count > 0: + return LicenseEditionChoices.BASIC + elif count <= 500: + return LicenseEditionChoices.STANDARD + elif count < 5000: + return LicenseEditionChoices.PROFESSIONAL + elif count >= 5000: + return LicenseEditionChoices.ULTIMATE + else: + return LicenseEditionChoices.COMMUNITY diff --git a/apps/jumpserver/settings/_xpack.py b/apps/jumpserver/settings/_xpack.py index 364a0e377..f0e59cecf 100644 --- a/apps/jumpserver/settings/_xpack.py +++ b/apps/jumpserver/settings/_xpack.py @@ -18,11 +18,12 @@ if not XPACK_DISABLED: XPACK_TEMPLATES_DIR = [] XPACK_CONTEXT_PROCESSOR = [] XPACK_LICENSE_IS_VALID = False +XPACK_LICENSE_EDITION = "" XPACK_LICENSE_INFO = { 'corporation': corporation, } -XPACK_LICENSE_CONTENT = '' +XPACK_LICENSE_CONTENT = 'community' if XPACK_ENABLED: from xpack.utils import get_xpack_templates_dir, get_xpack_context_processor