2022-06-08 21:41:59 +02:00
|
|
|
from functools import wraps
|
|
|
|
|
|
|
|
from areas.roles.role_service import RoleService
|
|
|
|
|
2022-06-21 14:41:54 +02:00
|
|
|
from flask_jwt_extended import get_jwt, verify_jwt_in_request
|
2022-06-09 12:21:47 +02:00
|
|
|
from helpers import Unauthorized
|
2022-06-08 21:41:59 +02:00
|
|
|
|
2022-06-21 14:41:54 +02:00
|
|
|
|
2022-06-08 21:41:59 +02:00
|
|
|
def admin_required():
|
|
|
|
def wrapper(fn):
|
|
|
|
@wraps(fn)
|
|
|
|
def decorator(*args, **kwargs):
|
|
|
|
verify_jwt_in_request()
|
2022-11-08 09:52:45 +01:00
|
|
|
# claims = get_jwt()
|
|
|
|
# user_id = claims["user_id"]
|
|
|
|
is_admin = True # RoleService.is_user_admin(user_id)
|
|
|
|
# TODO: actually check if admin
|
2022-06-10 11:34:33 +02:00
|
|
|
if is_admin:
|
2022-06-08 21:41:59 +02:00
|
|
|
return fn(*args, **kwargs)
|
|
|
|
else:
|
2022-06-09 12:21:47 +02:00
|
|
|
raise Unauthorized("You need to have admin permissions.")
|
2022-06-08 21:41:59 +02:00
|
|
|
|
|
|
|
return decorator
|
|
|
|
|
2022-06-21 14:41:54 +02:00
|
|
|
return wrapper
|