2019-07-09 13:41:16 +00:00
|
|
|
from flask import abort
|
|
|
|
from flask_login import current_user
|
2020-03-26 15:14:09 +00:00
|
|
|
from flask_socketio import disconnect
|
2020-03-27 11:06:11 +00:00
|
|
|
from functools import wraps
|
2019-07-09 13:41:16 +00:00
|
|
|
from .models import Permission
|
|
|
|
|
|
|
|
|
2020-03-26 15:14:09 +00:00
|
|
|
def admin_required(f):
|
|
|
|
@wraps(f)
|
|
|
|
def wrapped(*args, **kwargs):
|
|
|
|
if not current_user.can(Permission.ADMIN):
|
|
|
|
abort(403)
|
|
|
|
return f(*args, **kwargs)
|
|
|
|
return wrapped
|
|
|
|
|
|
|
|
|
|
|
|
def socketio_login_required(f):
|
|
|
|
@wraps(f)
|
|
|
|
def wrapped(*args, **kwargs):
|
|
|
|
if not current_user.is_authenticated:
|
|
|
|
disconnect()
|
|
|
|
else:
|
2019-07-09 13:41:16 +00:00
|
|
|
return f(*args, **kwargs)
|
2020-03-26 15:14:09 +00:00
|
|
|
return wrapped
|
2019-07-09 13:41:16 +00:00
|
|
|
|
|
|
|
|
2020-03-26 15:14:09 +00:00
|
|
|
def socketio_admin_required(f):
|
|
|
|
@wraps(f)
|
|
|
|
def wrapped(*args, **kwargs):
|
|
|
|
if not current_user.can(Permission.ADMIN):
|
|
|
|
disconnect()
|
|
|
|
else:
|
|
|
|
return f(*args, **kwargs)
|
|
|
|
return wrapped
|