django-oscar / django-oscar-accounts

Managed accounts for Django (with or without django-oscar)
BSD 3-Clause "New" or "Revised" License
212 stars 119 forks source link

Unable to withdraw funds from account with primary user #124

Open 1john opened 3 years ago

1john commented 3 years ago

If you login to the oscar dashboard as a superuser or a staff user and try to make a withdrawal from a user account that has a primary_user listed, you will not be able to make the withdrawal.

Error message: "Unable to withdraw funds from account: This user is not authorised to make transfers from this account"

Code in question is in can_be_authorized_by() in abstract_models.py line 220:

 def can_be_authorised_by(self, user=None):
        """
        Test whether the passed user can authorise a transfer from this account
        """
        if user is None:
            return True
        if self.primary_user:
            return user == self.primary_user
        secondary_users = self.secondary_users.all()
        if secondary_users.count() > 0:
            return user in secondary_users
        return True

How is a staff or superuser supposed to withdraw from an account? Am I using primary_user wrong?

Seems like there should be:

if user.is_staff or user.is_superuser:
    return True

in that function.

Thanks