aboutsummaryrefslogtreecommitdiffstats
path: root/utils/decorators.py
blob: 3b12eadbc3ba8441375bfb3e3612022402b10b05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"""
Decorators
"""
# from config import only_get
from utils.errors import error_method
from database.models import UserModel
from flask_jwt_extended import get_jwt_identity


def superuser(func):
    def wrapper(*args, **kwargs):
        """Check if user is admin"""
        user_id = get_jwt_identity()
        user_admin = UserModel.objects(id=user_id, admin=True)
        if user_admin:
            return func(*args, **kwargs)
        else:
            response = error_method()
            return response

    wrapper.__name__ = func.__name__
    return wrapper