Created
January 22, 2020 16:57
-
-
Save Porter97/5a8c8ffab26f1021c507bf81075e9fe4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import wraps | |
from flask import abort | |
from flask_login import current_user | |
from .models import Permission | |
def permission_required(permission): | |
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): | |
return permission_required(Permission.ADMIN)(f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment