From 5de5fa2e964e05926179be14107b565742fdc67e Mon Sep 17 00:00:00 2001 From: ibuler Date: Mon, 1 Mar 2021 14:11:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E4=B8=8D=E5=88=B0=20org=20=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/common/drf/filters.py | 5 ++++- apps/common/utils/lock.py | 2 +- apps/jumpserver/urls.py | 2 +- apps/orgs/mixins/models.py | 7 ------- apps/orgs/models.py | 7 +++++-- apps/orgs/utils.py | 2 +- 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/apps/common/drf/filters.py b/apps/common/drf/filters.py index 9d8ec087e..f130af3b7 100644 --- a/apps/common/drf/filters.py +++ b/apps/common/drf/filters.py @@ -11,7 +11,10 @@ import logging from common import const -__all__ = ["DatetimeRangeFilter", "IDSpmFilter", 'IDInFilter', "CustomFilter"] +__all__ = [ + "DatetimeRangeFilter", "IDSpmFilter", 'IDInFilter', "CustomFilter", + "BaseFilterSet" +] class BaseFilterSet(drf_filters.FilterSet): diff --git a/apps/common/utils/lock.py b/apps/common/utils/lock.py index ffb6217e3..ecb37c31a 100644 --- a/apps/common/utils/lock.py +++ b/apps/common/utils/lock.py @@ -7,7 +7,7 @@ from django.db import transaction from common.utils import get_logger from common.utils.inspect import copy_function_args -from apps.jumpserver.const import CONFIG +from jumpserver.const import CONFIG from common.local import thread_local logger = get_logger(__file__) diff --git a/apps/jumpserver/urls.py b/apps/jumpserver/urls.py index 306b1d9ea..5b8202854 100644 --- a/apps/jumpserver/urls.py +++ b/apps/jumpserver/urls.py @@ -39,7 +39,7 @@ if settings.XPACK_ENABLED: apps = [ 'users', 'assets', 'perms', 'terminal', 'ops', 'audits', 'orgs', 'auth', - 'applications', 'tickets', 'settings', 'xpack' + 'applications', 'tickets', 'settings', 'xpack', 'flower', 'luna', 'koko', 'ws', 'docs', 'redocs', ] diff --git a/apps/orgs/mixins/models.py b/apps/orgs/mixins/models.py index f2f6ae49e..c0823bb74 100644 --- a/apps/orgs/mixins/models.py +++ b/apps/orgs/mixins/models.py @@ -37,13 +37,6 @@ class OrgManager(models.Manager): queryset = super(OrgManager, self).get_queryset() return filter_org_queryset(queryset) - def all(self): - if not current_org: - msg = 'You can `objects.set_current_org(org).all()` then run it' - return self - else: - return super(OrgManager, self).all() - def set_current_org(self, org): if isinstance(org, str): org = Organization.get_instance(org) diff --git a/apps/orgs/models.py b/apps/orgs/models.py index 1fbae50ce..679dd5fbc 100644 --- a/apps/orgs/models.py +++ b/apps/orgs/models.py @@ -78,8 +78,11 @@ class Organization(models.Model): else: org = cls.objects.get(name=id_or_name) org.set_to_cache() - except cls.DoesNotExist: - org = cls.default() if default else None + except cls.DoesNotExist as e: + if default: + return cls.default() + else: + raise e return org def get_org_members_by_role(self, role): diff --git a/apps/orgs/utils.py b/apps/orgs/utils.py index eef12b1c6..de9e2982c 100644 --- a/apps/orgs/utils.py +++ b/apps/orgs/utils.py @@ -55,7 +55,7 @@ def _find(attr): def get_current_org(): org_id = get_current_org_id() if org_id is None: - return None + return Organization.root() org = Organization.get_instance(org_id) return org