mirror of https://github.com/jumpserver/jumpserver
fix: 修复获取不到 org 的问题
parent
19043d0a66
commit
5de5fa2e96
|
@ -11,7 +11,10 @@ import logging
|
||||||
|
|
||||||
from common import const
|
from common import const
|
||||||
|
|
||||||
__all__ = ["DatetimeRangeFilter", "IDSpmFilter", 'IDInFilter', "CustomFilter"]
|
__all__ = [
|
||||||
|
"DatetimeRangeFilter", "IDSpmFilter", 'IDInFilter', "CustomFilter",
|
||||||
|
"BaseFilterSet"
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class BaseFilterSet(drf_filters.FilterSet):
|
class BaseFilterSet(drf_filters.FilterSet):
|
||||||
|
|
|
@ -7,7 +7,7 @@ from django.db import transaction
|
||||||
|
|
||||||
from common.utils import get_logger
|
from common.utils import get_logger
|
||||||
from common.utils.inspect import copy_function_args
|
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
|
from common.local import thread_local
|
||||||
|
|
||||||
logger = get_logger(__file__)
|
logger = get_logger(__file__)
|
||||||
|
|
|
@ -39,7 +39,7 @@ if settings.XPACK_ENABLED:
|
||||||
|
|
||||||
apps = [
|
apps = [
|
||||||
'users', 'assets', 'perms', 'terminal', 'ops', 'audits', 'orgs', 'auth',
|
'users', 'assets', 'perms', 'terminal', 'ops', 'audits', 'orgs', 'auth',
|
||||||
'applications', 'tickets', 'settings', 'xpack'
|
'applications', 'tickets', 'settings', 'xpack',
|
||||||
'flower', 'luna', 'koko', 'ws', 'docs', 'redocs',
|
'flower', 'luna', 'koko', 'ws', 'docs', 'redocs',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -37,13 +37,6 @@ class OrgManager(models.Manager):
|
||||||
queryset = super(OrgManager, self).get_queryset()
|
queryset = super(OrgManager, self).get_queryset()
|
||||||
return filter_org_queryset(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):
|
def set_current_org(self, org):
|
||||||
if isinstance(org, str):
|
if isinstance(org, str):
|
||||||
org = Organization.get_instance(org)
|
org = Organization.get_instance(org)
|
||||||
|
|
|
@ -78,8 +78,11 @@ class Organization(models.Model):
|
||||||
else:
|
else:
|
||||||
org = cls.objects.get(name=id_or_name)
|
org = cls.objects.get(name=id_or_name)
|
||||||
org.set_to_cache()
|
org.set_to_cache()
|
||||||
except cls.DoesNotExist:
|
except cls.DoesNotExist as e:
|
||||||
org = cls.default() if default else None
|
if default:
|
||||||
|
return cls.default()
|
||||||
|
else:
|
||||||
|
raise e
|
||||||
return org
|
return org
|
||||||
|
|
||||||
def get_org_members_by_role(self, role):
|
def get_org_members_by_role(self, role):
|
||||||
|
|
|
@ -55,7 +55,7 @@ def _find(attr):
|
||||||
def get_current_org():
|
def get_current_org():
|
||||||
org_id = get_current_org_id()
|
org_id = get_current_org_id()
|
||||||
if org_id is None:
|
if org_id is None:
|
||||||
return None
|
return Organization.root()
|
||||||
org = Organization.get_instance(org_id)
|
org = Organization.get_instance(org_id)
|
||||||
return org
|
return org
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue