Skip to content

Commit

Permalink
refactor: 重构校验
Browse files Browse the repository at this point in the history
  • Loading branch information
shaohuzhang1 committed Oct 18, 2024
1 parent d5bbf48 commit ad6d617
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
12 changes: 6 additions & 6 deletions apps/application/serializers/application_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ def get_embed(self, with_valid=True, params={}):
is_draggable = 'false'
show_guide = 'true'
float_icon = f"{self.data.get('protocol')}://{self.data.get('host')}/ui/MaxKB.gif"
X_PACK_LICENSE_IS_VALID = (settings.XPACK_LICENSE_IS_VALID if hasattr(settings,
'XPACK_LICENSE_IS_VALID') else False)
xpack_cache = DBModelManage.get_model('xpack_cache')
X_PACK_LICENSE_IS_VALID = False if xpack_cache is None else xpack_cache.get('XPACK_LICENSE_IS_VALID', False)
# 获取接入的query参数
query = self.get_query_api_input(application_access_token.application, params)

Expand Down Expand Up @@ -313,8 +313,8 @@ def edit(self, instance: Dict, with_valid=True):
application_access_token.show_source = instance.get('show_source')
application_access_token.save()
application_setting_model = DBModelManage.get_model('application_setting')
X_PACK_LICENSE_IS_VALID = (settings.XPACK_LICENSE_IS_VALID if hasattr(settings,
'XPACK_LICENSE_IS_VALID') else False)
xpack_cache = DBModelManage.get_model('xpack_cache')
X_PACK_LICENSE_IS_VALID = False if xpack_cache is None else xpack_cache.get("XPACK_LICENSE_IS_VALID", False)
if application_setting_model is not None and X_PACK_LICENSE_IS_VALID:
application_setting, _ = application_setting_model.objects.get_or_create(
application_id=self.data.get('application_id'))
Expand Down Expand Up @@ -736,8 +736,8 @@ def profile(self, with_valid=True):
if application_access_token is None:
raise AppUnauthorizedFailed(500, "非法用户")
application_setting_model = DBModelManage.get_model('application_setting')
X_PACK_LICENSE_IS_VALID = (settings.XPACK_LICENSE_IS_VALID if hasattr(settings,
'XPACK_LICENSE_IS_VALID') else False)
xpack_cache = DBModelManage.get_model('xpack_cache')
X_PACK_LICENSE_IS_VALID = False if xpack_cache is None else xpack_cache.get('XPACK_LICENSE_IS_VALID', False)
application_setting_dict = {}
if application_setting_model is not None and X_PACK_LICENSE_IS_VALID:
application_setting = QuerySet(application_setting_model).filter(
Expand Down
6 changes: 3 additions & 3 deletions apps/common/util/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
from functools import reduce
from typing import Dict, List

from django.conf import settings
from django.db.models import QuerySet

from ..exception.app_exception import AppApiException
from ..models.db_model_manage import DBModelManage


def sub_array(array: List, item_num=10):
Expand Down Expand Up @@ -76,8 +76,8 @@ def run(*args, **kwargs):
def valid_license(model=None, count=None, message=None):
def inner(func):
def run(*args, **kwargs):
if (not (settings.XPACK_LICENSE_IS_VALID if hasattr(settings,
'XPACK_LICENSE_IS_VALID') else None)
xpack_cache = DBModelManage.get_model('xpack_cache')
if ((not False if xpack_cache is None else xpack_cache.get('XPACK_LICENSE_IS_VALID', False))
and QuerySet(
model).count() >= count):
error = message or f'超出限制{count},请联系我们(https://fit2cloud.com/)。'
Expand Down
6 changes: 3 additions & 3 deletions apps/setting/serializers/valid_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

from application.models import Application
from common.exception.app_exception import AppApiException
from common.models.db_model_manage import DBModelManage
from common.util.field_message import ErrMessage
from dataset.models import DataSet
from smartdoc import settings
from users.models import User

model_message_dict = {
Expand All @@ -40,8 +40,8 @@ def valid(self, is_valid=True):
if is_valid:
self.is_valid(raise_exception=True)
model_value = model_message_dict.get(self.data.get('valid_type'))
if not (settings.XPACK_LICENSE_IS_VALID if hasattr(settings,
'XPACK_LICENSE_IS_VALID') else None):
xpack_cache = DBModelManage.get_model('xpack_cache')
if not False if xpack_cache is None else xpack_cache.get('XPACK_LICENSE_IS_VALID', False):
if self.data.get('valid_count') != model_value.get('count'):
raise AppApiException(400, model_value.get('message'))
if QuerySet(
Expand Down
6 changes: 4 additions & 2 deletions apps/users/serializers/user_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from common.db.search import page_search
from common.exception.app_exception import AppApiException
from common.mixins.api_mixin import ApiMixin
from common.models.db_model_manage import DBModelManage
from common.response.result import get_api_response
from common.util.common import valid_license
from common.util.field_message import ErrMessage
Expand All @@ -45,9 +46,10 @@ class SystemSerializer(ApiMixin, serializers.Serializer):
@staticmethod
def get_profile():
version = os.environ.get('MAXKB_VERSION')
xpack_cache = DBModelManage.get_model('xpack_cache')
return {'version': version, 'IS_XPACK': hasattr(settings, 'IS_XPACK'),
'XPACK_LICENSE_IS_VALID': (settings.XPACK_LICENSE_IS_VALID if hasattr(settings,
'XPACK_LICENSE_IS_VALID') else False)}
'XPACK_LICENSE_IS_VALID': False if xpack_cache is None else xpack_cache.get('XPACK_LICENSE_IS_VALID',
False)}

@staticmethod
def get_response_body_api():
Expand Down

0 comments on commit ad6d617

Please sign in to comment.