2017-03-08 13:53:09 -05:00
|
|
|
from functools import wraps
|
|
|
|
from flask import abort
|
|
|
|
from flask_login import current_user
|
|
|
|
from .models import Permission
|
2017-03-08 19:55:12 -05:00
|
|
|
from threading import Thread
|
2017-03-08 13:53:09 -05:00
|
|
|
|
2017-03-08 19:55:12 -05:00
|
|
|
def async(f):
|
|
|
|
def wrapper(*args, **kwargs):
|
|
|
|
thr = Thread(target=f, args=args, kwargs=kwargs)
|
|
|
|
thr.start()
|
|
|
|
return wrapper
|
2017-03-08 13:53:09 -05:00
|
|
|
|
|
|
|
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.ADMINISTER)(f)
|
|
|
|
|