fix: 修复获取不到 org 的问题

pull/5657/head
ibuler 2021-03-01 14:11:27 +08:00 committed by 老广
parent 19043d0a66
commit 5de5fa2e96
6 changed files with 12 additions and 13 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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