From 11f6fe0bf97ab0c8d00346e1c278f780bc74095c Mon Sep 17 00:00:00 2001 From: Bai Date: Wed, 25 Dec 2024 15:31:48 +0800 Subject: [PATCH] fix: system org --- apps/orgs/serializers.py | 2 +- apps/orgs/utils.py | 10 +++++----- apps/users/serializers/profile.py | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/orgs/serializers.py b/apps/orgs/serializers.py index efa1fa311..fae09dc68 100644 --- a/apps/orgs/serializers.py +++ b/apps/orgs/serializers.py @@ -38,7 +38,7 @@ class OrgSerializer(ModelSerializer): class CurrentOrgSerializer(ModelSerializer): class Meta: model = Organization - fields = ['id', 'name', 'is_default', 'is_root', 'comment'] + fields = ['id', 'name', 'is_default', 'is_root', 'is_system', 'comment'] class CurrentOrgDefault: diff --git a/apps/orgs/utils.py b/apps/orgs/utils.py index 0efdcc2a7..26c5a408a 100644 --- a/apps/orgs/utils.py +++ b/apps/orgs/utils.py @@ -24,13 +24,13 @@ def get_org_from_request(request): # 其次session if not oid: oid = request.session.get("oid") - + if oid and oid.lower() == 'default': return Organization.default() if oid and oid.lower() == 'root': return Organization.root() - + if oid and oid.lower() == 'system': return Organization.system() @@ -39,14 +39,14 @@ def get_org_from_request(request): if org and org.internal: # 内置组织直接返回 return org - + if not settings.XPACK_ENABLED: # 社区版用户只能使用默认组织 return Organization.default() - + if not org and request.user.is_authenticated: # 企业版用户优先从自己有权限的组织中获取 - org = request.user.orgs.first() + org = request.user.orgs.exclude(id=Organization.SYSTEM_ID).first() if not org: org = Organization.default() diff --git a/apps/users/serializers/profile.py b/apps/users/serializers/profile.py index eacc0bff3..20c941c85 100644 --- a/apps/users/serializers/profile.py +++ b/apps/users/serializers/profile.py @@ -12,6 +12,7 @@ class UserOrgSerializer(serializers.Serializer): id = serializers.CharField() name = serializers.CharField() is_default = serializers.BooleanField(read_only=True) + is_system = serializers.BooleanField(read_only=True) is_root = serializers.BooleanField(read_only=True)