# Path: yapper/blueprints/user/models.py
# class Permission:
#     WRITE_POSTS = 0x01
#     READ_ONLY = 0x02
#     ADMIN = 0xff
#     ANONYMOUS = 0x00
# 
#     @staticmethod
#     def user():
#         return (Permission.WRITE_POSTS, True)
# 
#     @staticmethod
#     def admin():
#         return (Permission.ADMIN, False)


from functools import wraps
from flask import abort
from flask_login import current_user
from .models import Permission



def permission_required(permission):
    """
    Checks for a specific permission the current_user has or not.
    """
    def decorator(f):
        @wraps(f)
        def decorated_function(*args, **kwargs):
            if not current_user.can(permission):
                abort(403)
            return f(*args, **kwargs)
        return decorated_function
    return decorator


def admin_required(f):
    """Like `permission required`, but specific to admin."""

# Path: yapper/blueprints/user/models.py
# class Permission:
#     WRITE_POSTS = 0x01
#     READ_ONLY = 0x02
#     ADMIN = 0xff
#     ANONYMOUS = 0x00
# 
#     @staticmethod
#     def user():
#         return (Permission.WRITE_POSTS, True)
# 
#     @staticmethod
#     def admin():
#         return (Permission.ADMIN, False)


# Path: yapper/blueprints/user/decorators.py
from functools import wraps
from flask import abort
from flask_login import current_user
from .models import Permission




def permission_required(permission):
    """
    Checks for a specific permission the current_user has or not.
    """
    def decorator(f):
        @wraps(f)
        def decorated_function(*args, **kwargs):
            if not current_user.can(permission):
                abort(403)
            return f(*args, **kwargs)
        return decorated_function
    return decorator


def admin_required(f):
    """Like `permission required`, but specific to admin."""

    return permission_required(Permission.ADMIN)(f)