This commit is contained in:
Ross
2021-04-22 13:03:24 +01:00
parent b7d32e6589
commit c1bbd13312
3 changed files with 29 additions and 1 deletions
+13 -1
View File
@@ -1,5 +1,5 @@
from django.core.exceptions import PermissionDenied
from .models import Rapid
from .models import Exam
def user_is_author_or_rapid_checker(function):
def wrap(request, *args, **kwargs):
@@ -11,3 +11,15 @@ def user_is_author_or_rapid_checker(function):
wrap.__doc__ = function.__doc__
wrap.__name__ = function.__name__
return wrap
def user_is_exam_author_or_rapid_checker(function):
def wrap(request, *args, **kwargs):
exam = Exam.objects.get(pk=kwargs['pk'])
if request.user in exam.author.all() or request.user.groups.filter(name='rapid_checker').exists():
return function(request, *args, **kwargs)
else:
raise PermissionDenied
wrap.__doc__ = function.__doc__
wrap.__name__ = function.__name__
return wrap