mirror of https://github.com/jumpserver/jumpserver
feat: 优化账号actions设置逻辑
parent
881c0a6042
commit
237e7b22fb
|
@ -235,17 +235,21 @@ class AssetPermission(OrgModelMixin):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def set_accounts_actions(cls, accounts, perms):
|
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)
|
account_names = accounts.values_list('username', flat=True)
|
||||||
perms = perms.filter_by_accounts(account_names)
|
perms = perms.filter_by_accounts(account_names)
|
||||||
account_names_actions_map = defaultdict(int)
|
|
||||||
account_names_actions = perms.values_list('accounts', 'actions')
|
account_names_actions = perms.values_list('accounts', 'actions')
|
||||||
for account_names, actions in account_names_actions:
|
for account_names, actions in account_names_actions:
|
||||||
for account_name in account_names:
|
for account_name in account_names:
|
||||||
account_names_actions_map[account_name] |= actions
|
account_names_actions_map[account_name] |= actions
|
||||||
for account in accounts:
|
return account_names_actions_map
|
||||||
account.actions = account_names_actions_map.get(account.username)
|
|
||||||
return accounts
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def retrieve_account_names(cls, perms):
|
def retrieve_account_names(cls, perms):
|
||||||
|
|
Loading…
Reference in New Issue