def request_user_has_resource_api_permission(permission_type):
    """
    A decorator meant to wrap post Pecan REST controller methods

    This decorator assumes the first argument passed to the decorated function is a resource API
    object.
    """
    def decorate(func):
        function_name = func.__name__
        if function_name not in ['post']:
            raise Exception('This decorator should only be used to wrap post methods')

        @wraps(func)
        def func_wrapper(*args, **kwargs):
            resource_api = args[1]

            utils.assert_request_user_has_resource_api_permission(request=pecan.request,
                                                                  resource_api=resource_api,
                                                                  permission_type=permission_type)
            return func(*args, **kwargs)
        return func_wrapper
    return decorate
dataset/ETHPy150Open StackStorm/st2/st2common/st2common/rbac/decorators.py/request_user_has_resource_api_permission/original