(klass)
return __outer__
Check users access to an object using their token.
Check users access to an object using their token.
Check users access to an object using their token .
def token_access(klass):
    """
    Check users access to an object using their token.
    """

    def __outer__(func):

        @wraps(func)
        def __wrapper__(request, *args, **kwargs):

            # Get the token from the request data
            token = auth.get_token(request=request)
            # Find the target user.
            user = User.objects.filter(profile__token=token).first()

            # Get the object user is trying to access
            uid = kwargs.get('uid')
            obj = klass.objects.filter(uid=uid).first()

            if not obj:
                # Allow users to create.
                return HttpResponse(content="Object does not exist.", status=404)

            project = obj.project

            # User token required for private projects.
            if not user and project.is_private:
                return HttpResponse(content="Token does not belong to any user.", status=404)

            # GET requests require read access
            if request.method == "GET":
                acc = auth.is_readable(user=user, obj=obj, strict=False)
            # PUT and POST requests require write access
            else:
                acc = auth.is_writable(user=user, project=project)

            # User passes test.
            if acc:
                return func(request, *args, **kwargs)

            return HttpResponse(content="User does not have access to preform that action.", status=404)

        return __wrapper__

    return __outer__
def token_access ( klass ) : def __outer__ ( func ) : @ wraps ( func ) def __wrapper__ ( request , * args , * * kwargs ) : # Get the token from the request data token = auth . get_token ( request = request ) # Find the target user. user = User . objects . filter ( profile__token = token ) . first ( ) # Get the object user is trying to access uid = kwargs . get ( 'uid' ) obj = klass . objects . filter ( uid = uid ) . first ( ) if not obj : # Allow users to create. return HttpResponse ( content = "Object does not exist." , status = 404 ) project = obj . project # User token required for private projects. if not user and project . is_private : return HttpResponse ( content = "Token does not belong to any user." , status = 404 ) # GET requests require read access if request . method == "GET" : acc = auth . is_readable ( user = user , obj = obj , strict = False ) # PUT and POST requests require write access else : acc = auth . is_writable ( user = user , project = project ) # User passes test. if acc : return func ( request , * args , * * kwargs ) return HttpResponse ( content = "User does not have access to preform that action." , status = 404 ) return __wrapper__ return __outer__