def _check_request_permission(request, request_format='xml', url_name="root"):
    '''
    Checks whether this user has permission to perform the specified action
    This method does not check method call validity. That is done later
    
    PARAMETERS
    
    - ``request`` - a django HttpRequest object
    - ``request_format`` - the request type: 'json' or 'xml' 
    
    RETURNS 
    
    True if the request is valid and False if permission is denied
    '''
    
    user = getattr(request, 'user', None)
    dispatcher = get_dispatcher(request.path, url_name)
    methods = dispatcher.list_methods()
    method_name = dispatcher.get_method_name(request.raw_post_data, \
                                             request_format)
    response = True
    
    for method in methods:
        if method.name == method_name:
            # this is the method the user is calling
            # time to check the permissions
            if method.permission is not None:
                logger.debug('Method "%s" is protected by permission "%s"' \
                              %(method.name, method.permission))
                if user is None:
                    # user is only none if not using AuthenticationMiddleware
                    logger.warn('AuthenticationMiddleware is not enabled')
                    response = False
                elif not user.has_perm(method.permission):
                    # check the permission against the permission database
                    logger.info('User "%s" is NOT authorized' %(str(user)))
                    response = False
                else:
                    logger.debug('User "%s" is authorized' %(str(user)))
            else:
                logger.debug('Method "%s" is unprotected' %(method.name))
                
            break
    
    return response
dataset/ETHPy150Open fp7-ofelia/ocf/vt_manager/src/python/vt_manager/common/rpc4django/views.py/_check_request_permission/original