aboutsummaryrefslogtreecommitdiffstats
path: root/utils/decorators.py
diff options
context:
space:
mode:
authorJesús <heckyel@hyperbola.info>2022-03-22 00:39:40 +0800
committerJesús <heckyel@hyperbola.info>2022-03-22 00:39:40 +0800
commit3fca03988b42adaf8e67cc7137dd1fdba327e197 (patch)
treead39a5bc12a03c82b9a4fd980c1b92ca0a1dac93 /utils/decorators.py
downloadheroeapi-3fca03988b42adaf8e67cc7137dd1fdba327e197.tar.lz
heroeapi-3fca03988b42adaf8e67cc7137dd1fdba327e197.tar.xz
heroeapi-3fca03988b42adaf8e67cc7137dd1fdba327e197.zip
initial commit
Diffstat (limited to 'utils/decorators.py')
-rw-r--r--utils/decorators.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/utils/decorators.py b/utils/decorators.py
new file mode 100644
index 0000000..3b12ead
--- /dev/null
+++ b/utils/decorators.py
@@ -0,0 +1,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