diff --git a/generic/views.py b/generic/views.py index 80e752d7..80928734 100644 --- a/generic/views.py +++ b/generic/views.py @@ -172,6 +172,8 @@ class ExamViews(View, LoginRequiredMixin): return False if self.app_name == "longs" and not user.groups.filter(name='long_checker').exists(): return False + if self.app_name == "physics" and not user.groups.filter(name='physic_checker').exists(): + return False return True diff --git a/physics/views.py b/physics/views.py index af919158..967d9665 100644 --- a/physics/views.py +++ b/physics/views.py @@ -33,6 +33,19 @@ import plotly.express as px from generic.views import ExamViews +from rest_framework import viewsets, permissions +from rest_framework.pagination import PageNumberPagination + +from django.core.exceptions import PermissionDenied + +class AuthorOrCheckerRequiredMixin(object): + def get_object(self, *args, **kwargs): + obj = super().get_object(*args, **kwargs) + if self.request.user.groups.filter(name="physics_checker").exists(): + return obj + if self.request.user not in obj.author.all(): + raise PermissionDenied() # or Http404 + return obj def question_list(request): questions = Question.objects.all()