From 0f338a3b58b2ea79b876c380a90dbfe4a5353626 Mon Sep 17 00:00:00 2001 From: ibuler Date: Fri, 24 Feb 2023 00:04:53 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BF=AE=E5=A4=8D=E7=A4=BE=E5=8C=BA?= =?UTF-8?q?=E7=89=88=E5=8F=AF=E8=83=BD=E5=BC=95=E8=B5=B7=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/models/node.py | 2 +- apps/perms/utils/account.py | 10 ++++++---- apps/rbac/permissions.py | 6 +++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/apps/assets/models/node.py b/apps/assets/models/node.py index 8f6ee45f3..32bfcaa09 100644 --- a/apps/assets/models/node.py +++ b/apps/assets/models/node.py @@ -489,7 +489,7 @@ class SomeNodesMixin: return cls.default_node() if ori_org and ori_org.is_root(): - return None + return cls.default_node() org_roots = cls.org_root_nodes() org_roots_length = len(org_roots) diff --git a/apps/perms/utils/account.py b/apps/perms/utils/account.py index 16e8bb344..b66b247d8 100644 --- a/apps/perms/utils/account.py +++ b/apps/perms/utils/account.py @@ -1,5 +1,6 @@ from collections import defaultdict +from orgs.utils import tmp_to_org from accounts.models import Account from accounts.const import AliasAccount from .permission import AssetPermissionUtil @@ -16,10 +17,11 @@ class PermAccountUtil(AssetPermissionUtil): :param asset: Asset :param account_name: 可能是 @USER @INPUT 字符串 """ - permed_accounts = self.get_permed_accounts_for_user(user, asset) - accounts_mapper = {account.alias: account for account in permed_accounts} - account = accounts_mapper.get(account_name) - return account + with tmp_to_org(asset.org): + permed_accounts = self.get_permed_accounts_for_user(user, asset) + accounts_mapper = {account.alias: account for account in permed_accounts} + account = accounts_mapper.get(account_name) + return account def get_permed_accounts_for_user(self, user, asset): """ 获取授权给用户某个资产的账号 """ diff --git a/apps/rbac/permissions.py b/apps/rbac/permissions.py index 7cc35d370..7c3f21610 100644 --- a/apps/rbac/permissions.py +++ b/apps/rbac/permissions.py @@ -97,13 +97,13 @@ class RBACPermission(permissions.DjangoModelPermissions): else: model_cls = queryset.model except AssertionError as e: - logger.error(f'Error get model cls: {e}') + # logger.error(f'Error get model cls: {e}') model_cls = None except AttributeError as e: - logger.error(f'Error get model cls: {e}') + # logger.error(f'Error get model cls: {e}') model_cls = None except Exception as e: - logger.error('Error get model class: {} of {}'.format(e, view)) + # logger.error('Error get model class: {} of {}'.format(e, view)) raise e return model_cls