def enterprise_customer_required(view):
@wraps(view)<EOL>def wrapper(request, *args, **kwargs):<EOL><INDENT>"""<STR_LIT>"""<EOL>user = request.user<EOL>enterprise_customer = get_enterprise_customer_for_user(user)<EOL>if enterprise_customer:<EOL><INDENT>args = args + (enterprise_customer,)<EOL>return view(request, *args, **kwargs)<EOL><DEDENT>else:<EOL><INDENT>raise PermissionDenied(<EOL>'<STR_LIT>'.format(<EOL>username=user.username<EOL>)<EOL>)<EOL><DEDENT><DEDENT>return wrapper<EOL>
Ensure the user making the API request is associated with an EnterpriseCustomer.

This decorator attempts to find an EnterpriseCustomer associated with the requesting
user and passes that EnterpriseCustomer to the view as a parameter. It will return a
PermissionDenied error if an EnterpriseCustomer cannot be found.

Usage::
    @enterprise_customer_required()
    def my_view(request, enterprise_customer):
        # Some functionality ...

    OR

    class MyView(View):
        ...
        @method_decorator(enterprise_customer_required)
        def get(self, request, enterprise_customer):
            # Some functionality ...