start migrating from DRF to ninja
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
# constants.py
|
||||
|
||||
from enum import Enum
|
||||
class Group(Enum):
|
||||
cid_user_manager = "cid_user_manager"
|
||||
marker = "marker"
|
||||
anatomy_marker = "anatomy_marker"
|
||||
@@ -1,5 +1,9 @@
|
||||
from django.core.exceptions import PermissionDenied
|
||||
|
||||
from django.http import Http404
|
||||
from .constants import Group
|
||||
|
||||
from functools import wraps
|
||||
|
||||
def user_is_cid_user_manager(function):
|
||||
def wrap(request, *args, **kwargs):
|
||||
@@ -14,3 +18,21 @@ def user_is_cid_user_manager(function):
|
||||
wrap.__doc__ = function.__doc__
|
||||
wrap.__name__ = function.__name__
|
||||
return wrap
|
||||
|
||||
|
||||
def check_user_in_group(*groups: Group):
|
||||
print("DEC")
|
||||
print(groups)
|
||||
|
||||
def decorator(function):
|
||||
@wraps(function)
|
||||
def wrapper(request, *args, **kwargs):
|
||||
print(request.user)
|
||||
if request.user.is_superuser or request.user.groups.filter(
|
||||
name__in=[group.name for group in groups]
|
||||
).exists():
|
||||
return function(request, *args, **kwargs)
|
||||
raise PermissionDenied
|
||||
|
||||
return wrapper
|
||||
return decorator
|
||||
+2
-2
@@ -195,10 +195,10 @@ def generic_exam_json_edit(request):
|
||||
if request.method == "POST":
|
||||
question_type = request.POST.get("type")
|
||||
|
||||
if question_type == "rapid":
|
||||
if question_type == "rapids":
|
||||
Exam = RapidExam
|
||||
Question = RapidQuestion
|
||||
elif question_type == "long":
|
||||
elif question_type == "longs":
|
||||
Exam = LongExam
|
||||
Question = LongQuestion
|
||||
elif question_type == "anatomy":
|
||||
|
||||
Reference in New Issue
Block a user