Merge pull request #11024 from jumpserver/pr@dev@fix_perm_accounts_only_one

fix: 修复授权的账号,用户名相同的,只有一个的情况
pull/11025/head
老广 2023-07-19 21:24:45 +08:00 committed by GitHub
commit 400d37ffca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 7 deletions

View File

@ -41,7 +41,10 @@ class PermAccountUtil(AssetPermissionUtil):
alias_date_expired_mapper[alias].append(perm.date_expired)
asset_accounts = asset.accounts.all().active()
username_account_mapper = {account.username: account for account in asset_accounts}
# username_accounts_mapper = {account.username: account for account in asset_accounts}
username_accounts_mapper = defaultdict(list)
for account in asset_accounts:
username_accounts_mapper[account.username].append(account)
cleaned_accounts_action_bit = defaultdict(int)
cleaned_accounts_expired = defaultdict(list)
@ -56,23 +59,26 @@ class PermAccountUtil(AssetPermissionUtil):
)
for alias, action_bit in alias_action_bit_mapper.items():
account = None
_accounts = []
if alias == AliasAccount.USER:
if user.username in username_account_mapper:
account = username_account_mapper[user.username]
if user.username in username_accounts_mapper:
_accounts = username_accounts_mapper[user.username]
else:
account = Account.get_user_account()
elif alias == AliasAccount.INPUT:
account = Account.get_manual_account()
elif alias == AliasAccount.ANON:
account = Account.get_anonymous_account()
elif alias in username_accounts_mapper:
_accounts = username_accounts_mapper[alias]
elif alias.startswith('@'):
continue
elif alias in username_account_mapper:
account = username_account_mapper[alias]
else:
account = None
if account:
_accounts += [account]
for account in _accounts:
cleaned_accounts_action_bit[account] |= action_bit
cleaned_accounts_expired[account].extend(alias_date_expired_mapper[alias])