(role, get_user=import_user)
return wrapper
Takes an role (a string name of either a role or an ability) and returns the function if the user has that role
Takes an role (a string name of either a role or an ability) and returns the function if the user has that role
Takes an role ( a string name of either a role or an ability ) and returns the function if the user has that role
def user_is(role, get_user=import_user):
    """
    Takes an role (a string name of either a role or an ability) and returns the function if the user has that role
    """
    def wrapper(func):
        @wraps(func)
        def inner(*args, **kwargs):
            from .models import Role
            current_user = get_user()
            if role in current_user.roles:
                return func(*args, **kwargs)
            raise Forbidden("You do not have access")
        return inner
    return wrapper
def user_is ( role , get_user = import_user ) : def wrapper ( func ) : @ wraps ( func ) def inner ( * args , * * kwargs ) : from . models import Role current_user = get_user ( ) if role in current_user . roles : return func ( * args , * * kwargs ) raise Forbidden ( "You do not have access" ) return inner return wrapper