dashboard/helpers/auth_guard.py
Davor 19bc31e6e3 MR comments
- added error handler for unauthorized
2022-06-09 12:21:47 +02:00

24 lines
No EOL
673 B
Python

from functools import wraps
from areas.roles.role_service import RoleService
from flask_jwt_extended import verify_jwt_in_request
from flask_jwt_extended import get_jwt
from helpers import Unauthorized
def admin_required():
def wrapper(fn):
@wraps(fn)
def decorator(*args, **kwargs):
verify_jwt_in_request()
claims = get_jwt()
userId = claims["user_id"]
isAdmin = RoleService.is_user_admin(userId)
if isAdmin:
return fn(*args, **kwargs)
else:
raise Unauthorized("You need to have admin permissions.")
return decorator
return wrapper