Check user password, when is correct, then run decorated function.

    :returns: decorated function

def is_allowed(func):
    """Check user password, when is correct, then run decorated function.

    :returns: decorated function

    """
    @wraps(func)
    def _is_allowed(user, *args, **kwargs):
        password = kwargs.pop('password', None)
        if user.check_password(password):
            return func(user, *args, **kwargs)
        else:
            raise NotAllowedError()

    # add password parameter to function signature
    sig = inspect.signature(func)
    parms = list(sig.parameters.values())
    parms.append(inspect.Parameter('password',
                                   inspect.Parameter.KEYWORD_ONLY,
                                   default=None))
    _is_allowed.__signature__ = sig.replace(parameters=parms)

    return _is_allowed