def wrapped(request, *args, **kwargs): # pylint: disable=missing-docstring instructor_service = get_runtime_service('instructor') course_id = kwargs['course_id'] if 'course_id' in kwargs else None exam_id = request.data.get('exam_id', None) attempt_id = kwargs['attempt_id'] if 'attempt_id' in kwargs else None if request.user.is_staff: return func(request, *args, **kwargs) else: if course_id is None: if exam_id is not None: exam = ProctoredExam.get_exam_by_id(exam_id) course_id = exam.course_id elif attempt_id is not None: exam_attempt = ProctoredExamStudentAttempt.objects.get_exam_attempt_by_id( attempt_id) course_id = exam_attempt.proctored_exam.course_id else: response_message = _("could not determine the course_id") return Response(status=status.HTTP_403_FORBIDDEN, data={"detail": response_message}) if instructor_service.is_course_staff(request.user, course_id): return func(request, *args, **kwargs) else: return Response( status=status.HTTP_403_FORBIDDEN, data={ "detail": _("Must be a Staff User to Perform this request.") })
def wrapped(request, *args, **kwargs): # pylint: disable=missing-docstring instructor_service = get_runtime_service('instructor') course_id = kwargs['course_id'] if 'course_id' in kwargs else None exam_id = request.data.get('exam_id', None) attempt_id = kwargs['attempt_id'] if 'attempt_id' in kwargs else None if request.user.is_staff: return func(request, *args, **kwargs) else: if course_id is None: if exam_id is not None: exam = ProctoredExam.get_exam_by_id(exam_id) course_id = exam.course_id elif attempt_id is not None: exam_attempt = ProctoredExamStudentAttempt.objects.get_exam_attempt_by_id(attempt_id) course_id = exam_attempt.proctored_exam.course_id else: response_message = _("could not determine the course_id") return Response( status=status.HTTP_403_FORBIDDEN, data={"detail": response_message} ) if instructor_service.is_course_staff(request.user, course_id): return func(request, *args, **kwargs) else: return Response( status=status.HTTP_403_FORBIDDEN, data={"detail": _("Must be a Staff User to Perform this request.")} )
def update_exam(exam_id, exam_name=None, time_limit_mins=None, is_proctored=None, is_practice_exam=None, external_id=None, is_active=None): """ Given a Django ORM id, update the existing record, otherwise raise exception if not found. If an argument is not passed in, then do not change it's current value. Returns: id """ log_msg = ( u'Updating exam_id {exam_id} with parameters ' u'exam_name={exam_name}, time_limit_mins={time_limit_mins}, ' u'is_proctored={is_proctored}, is_practice_exam={is_practice_exam}, ' u'external_id={external_id}, is_active={is_active}'.format( exam_id=exam_id, exam_name=exam_name, time_limit_mins=time_limit_mins, is_proctored=is_proctored, is_practice_exam=is_practice_exam, external_id=external_id, is_active=is_active)) log.info(log_msg) proctored_exam = ProctoredExam.get_exam_by_id(exam_id) if proctored_exam is None: raise ProctoredExamNotFoundException if exam_name is not None: proctored_exam.exam_name = exam_name if time_limit_mins is not None: proctored_exam.time_limit_mins = time_limit_mins if is_proctored is not None: proctored_exam.is_proctored = is_proctored if is_practice_exam is not None: proctored_exam.is_practice_exam = is_practice_exam if external_id is not None: proctored_exam.external_id = external_id if is_active is not None: proctored_exam.is_active = is_active proctored_exam.save() return proctored_exam.id
def get_exam_by_id(exam_id): """ Looks up exam by the Primary Key. Raises exception if not found. Returns dictionary version of the Django ORM object e.g. { "course_id": "edX/DemoX/Demo_Course", "content_id": "123", "external_id": "", "exam_name": "Midterm", "time_limit_mins": 90, "is_proctored": true, "is_active": true } """ proctored_exam = ProctoredExam.get_exam_by_id(exam_id) if proctored_exam is None: raise ProctoredExamNotFoundException serialized_exam_object = ProctoredExamSerializer(proctored_exam) return serialized_exam_object.data
def update_exam(exam_id, exam_name=None, time_limit_mins=None, is_proctored=None, is_practice_exam=None, external_id=None, is_active=None): """ Given a Django ORM id, update the existing record, otherwise raise exception if not found. If an argument is not passed in, then do not change it's current value. Returns: id """ log_msg = ( u'Updating exam_id {exam_id} with parameters ' u'exam_name={exam_name}, time_limit_mins={time_limit_mins}, ' u'is_proctored={is_proctored}, is_practice_exam={is_practice_exam}, ' u'external_id={external_id}, is_active={is_active}'.format( exam_id=exam_id, exam_name=exam_name, time_limit_mins=time_limit_mins, is_proctored=is_proctored, is_practice_exam=is_practice_exam, external_id=external_id, is_active=is_active ) ) log.info(log_msg) proctored_exam = ProctoredExam.get_exam_by_id(exam_id) if proctored_exam is None: raise ProctoredExamNotFoundException if exam_name is not None: proctored_exam.exam_name = exam_name if time_limit_mins is not None: proctored_exam.time_limit_mins = time_limit_mins if is_proctored is not None: proctored_exam.is_proctored = is_proctored if is_practice_exam is not None: proctored_exam.is_practice_exam = is_practice_exam if external_id is not None: proctored_exam.external_id = external_id if is_active is not None: proctored_exam.is_active = is_active proctored_exam.save() return proctored_exam.id