This commit is contained in:
Ross
2021-04-29 23:01:39 +01:00
parent 934b7dcf96
commit 9427c1d8b5
+11 -5
View File
@@ -145,6 +145,16 @@ class ExamViews(View, LoginRequiredMixin):
self.question_type = question_type
self.loadJsonAnswer = loadJsonAnswer
def check_user_access(user):
if self.app_name == "rapids" and not user.groups.filter(name='rapid_checker').exists():
return False
if self.app_name == "anatomy" and not user.groups.filter(name='anatomy_checker').exists():
return False
if self.app_name == "longs" and not user.groups.filter(name='long_checker').exists():
return False
return True
@method_decorator(login_required)
def exam_toggle_results_published(self, request, pk):
if request.is_ajax() and request.method == "POST":
@@ -200,11 +210,7 @@ class ExamViews(View, LoginRequiredMixin):
def exam_list(self, request):
exams = self.Exam.objects.filter(exam_mode=True)
if self.app_name == "rapids" and not request.user.groups.filter(name='rapid_checker').exists():
raise PermissionDenied
if self.app_name == "anatomy" and not request.user.groups.filter(name='anatomy_checker').exists():
raise PermissionDenied
if self.app_name == "longs" and not request.user.groups.filter(name='long_checker').exists():
if not self.check_user_access(request.user)
raise PermissionDenied
return render(request, "{}/exam_list.html".format(self.app_name), {"exams": exams})