This commit is contained in:
Ross
2021-10-17 10:14:40 +01:00
parent 6196a81989
commit b4ccacdcce
+10 -8
View File
@@ -194,7 +194,7 @@ class ExamViews(View, LoginRequiredMixin):
#group_map = {"rapids" : "rapid_checker", "anatomy" : "anatomy_checker", "longs":"long_checker"}
#exam_group = group_map[self.app_name]
def check_user_access(self, user, exam_id):
def check_user_access(self, user, exam_id=None):
"""Check if a user should be able to access a view
Args:
@@ -203,9 +203,10 @@ class ExamViews(View, LoginRequiredMixin):
Returns:
[boolean]: True if the user has access
"""
exam = get_object_or_404(self.Exam, pk=exam_id)
if user in exam.get_author_objects():
return True
if exam_id is not None:
exam = get_object_or_404(self.Exam, pk=exam_id)
if user in exam.get_author_objects():
return True
if self.app_name == "rapids" and not user.groups.filter(name='rapid_checker').exists():
return False
@@ -219,7 +220,7 @@ class ExamViews(View, LoginRequiredMixin):
return False
return True
def check_user_edit_access(self, user, exam_id):
def check_user_edit_access(self, user, exam_id=None):
"""Check if a user should be able to access a view
Args:
@@ -229,9 +230,10 @@ class ExamViews(View, LoginRequiredMixin):
[boolean]: True if the user has access
"""
# If a user is an exam author they should have acccess
exam = get_object_or_404(self.Exam, pk=exam_id)
if user in exam.get_author_objects():
return True
if exam_id is not None:
exam = get_object_or_404(self.Exam, pk=exam_id)
if user in exam.get_author_objects():
return True
if self.app_name == "rapids" and not user.groups.filter(name='rapid_checker').exists():
return False