From 237e7b22fb9744c6a16ae899d8333fd8de0f5a85 Mon Sep 17 00:00:00 2001 From: "Jiangjie.Bai" Date: Fri, 30 Sep 2022 16:28:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E8=B4=A6=E5=8F=B7act?= =?UTF-8?q?ions=E8=AE=BE=E7=BD=AE=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/perms/models/asset_permission.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/apps/perms/models/asset_permission.py b/apps/perms/models/asset_permission.py index f6203841d..9d444268f 100644 --- a/apps/perms/models/asset_permission.py +++ b/apps/perms/models/asset_permission.py @@ -235,17 +235,21 @@ class AssetPermission(OrgModelMixin): @classmethod def set_accounts_actions(cls, accounts, perms): - # set account actions + account_names_actions_map = cls.get_account_names_actions_map(accounts, perms) + for account in accounts: + account.actions = account_names_actions_map.get(account.username) + return accounts + + @classmethod + def get_account_names_actions_map(cls, accounts, perms): + account_names_actions_map = defaultdict(int) account_names = accounts.values_list('username', flat=True) perms = perms.filter_by_accounts(account_names) - account_names_actions_map = defaultdict(int) account_names_actions = perms.values_list('accounts', 'actions') for account_names, actions in account_names_actions: for account_name in account_names: account_names_actions_map[account_name] |= actions - for account in accounts: - account.actions = account_names_actions_map.get(account.username) - return accounts + return account_names_actions_map @classmethod def retrieve_account_names(cls, perms):