diff --git a/apps/perms/utils/account.py b/apps/perms/utils/account.py index 62c7b68d0..d97343372 100644 --- a/apps/perms/utils/account.py +++ b/apps/perms/utils/account.py @@ -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])