def put(self, request, attempt_id): """ HTTP POST handler. To stop an exam. """ attempt = get_exam_attempt_by_id(attempt_id) if not attempt: err_msg = (u'Attempted to access attempt_id {attempt_id} but ' u'it does not exist.'.format(attempt_id=attempt_id)) raise StudentExamAttemptDoesNotExistsException(err_msg) # make sure the the attempt belongs to the calling user_id if attempt['user']['id'] != request.user.id: err_msg = (u'Attempted to access attempt_id {attempt_id} but ' u'does not have access to it.'.format( attempt_id=attempt_id)) raise ProctoredExamPermissionDenied(err_msg) action = request.data.get('action') if action == 'stop': exam_attempt_id = stop_exam_attempt( exam_id=attempt['proctored_exam']['id'], user_id=request.user.id) elif action == 'start': exam_attempt_id = start_exam_attempt( exam_id=attempt['proctored_exam']['id'], user_id=request.user.id) elif action == 'submit': exam_attempt_id = update_attempt_status( attempt['proctored_exam']['id'], request.user.id, ProctoredExamStudentAttemptStatus.submitted) elif action == 'click_download_software': exam_attempt_id = update_attempt_status( attempt['proctored_exam']['id'], request.user.id, ProctoredExamStudentAttemptStatus.download_software_clicked) elif action == 'error': backend = attempt['proctored_exam']['backend'] waffle_name = PING_FAILURE_PASSTHROUGH_TEMPLATE.format(backend) should_block_user = not ( backend and waffle.switch_is_active(waffle_name)) and ( not attempt['status'] == ProctoredExamStudentAttemptStatus.submitted) if should_block_user: exam_attempt_id = update_attempt_status( attempt['proctored_exam']['id'], request.user.id, ProctoredExamStudentAttemptStatus.error) else: exam_attempt_id = False LOG.warning( u'Browser JS reported problem with proctoring desktop ' u'application. Did block user: %s, for attempt: %s', should_block_user, attempt['id']) elif action == 'decline': exam_attempt_id = update_attempt_status( attempt['proctored_exam']['id'], request.user.id, ProctoredExamStudentAttemptStatus.declined) data = {"exam_attempt_id": exam_attempt_id} return Response(data)
def put(self, request, attempt_id): """ HTTP POST handler. To stop an exam. """ try: attempt = get_exam_attempt_by_id(attempt_id) if not attempt: err_msg = ( 'Attempted to access attempt_id {attempt_id} but ' 'it does not exist.'.format( attempt_id=attempt_id ) ) raise StudentExamAttemptDoesNotExistsException(err_msg) # make sure the the attempt belongs to the calling user_id if attempt['user']['id'] != request.user.id: err_msg = ( 'Attempted to access attempt_id {attempt_id} but ' 'does not have access to it.'.format( attempt_id=attempt_id ) ) raise ProctoredExamPermissionDenied(err_msg) action = request.DATA.get('action') if action == 'stop': exam_attempt_id = stop_exam_attempt( exam_id=attempt['proctored_exam']['id'], user_id=request.user.id ) elif action == 'start': exam_attempt_id = start_exam_attempt( exam_id=attempt['proctored_exam']['id'], user_id=request.user.id ) elif action == 'submit': exam_attempt_id = update_attempt_status( attempt['proctored_exam']['id'], request.user.id, ProctoredExamStudentAttemptStatus.submitted ) elif action == 'decline': exam_attempt_id = update_attempt_status( attempt['proctored_exam']['id'], request.user.id, ProctoredExamStudentAttemptStatus.declined ) return Response({"exam_attempt_id": exam_attempt_id}) except ProctoredBaseException, ex: LOG.exception(ex) return Response( status=status.HTTP_400_BAD_REQUEST, data={"detail": str(ex)} )
def put(self, request, attempt_id): """ HTTP POST handler. To stop an exam. """ try: attempt_id = int(attempt_id) attempt = get_exam_attempt_by_id(attempt_id) except: attempt = get_exam_attempt_by_code(attempt_id) try: if not attempt: err_msg = ('Attempted to access attempt_id {attempt_id} but ' 'it does not exist.'.format(attempt_id=attempt_id)) raise StudentExamAttemptDoesNotExistsException(err_msg) # make sure the the attempt belongs to the calling user_id if attempt['user']['id'] != request.user.id: err_msg = ('Attempted to access attempt_id {attempt_id} but ' 'does not have access to it.'.format( attempt_id=attempt_id)) raise ProctoredExamPermissionDenied(err_msg) action = request.data.get('action') if action == 'stop': exam_attempt_id = stop_exam_attempt( exam_id=attempt['proctored_exam']['id'], user_id=request.user.id) elif action == 'start': exam_attempt_id = start_exam_attempt( exam_id=attempt['proctored_exam']['id'], user_id=request.user.id) elif action == 'submit': exam_attempt_id = update_attempt_status( attempt['proctored_exam']['id'], request.user.id, ProctoredExamStudentAttemptStatus.submitted) elif action == 'click_download_software': exam_attempt_id = update_attempt_status( attempt['proctored_exam']['id'], request.user.id, ProctoredExamStudentAttemptStatus.download_software_clicked ) elif action == 'decline': exam_attempt_id = update_attempt_status( attempt['proctored_exam']['id'], request.user.id, ProctoredExamStudentAttemptStatus.declined) return Response({"exam_attempt_id": exam_attempt_id}) except ProctoredBaseException, ex: LOG.exception(ex) return Response(status=status.HTTP_400_BAD_REQUEST, data={"detail": str(ex)})
def put(self, request, attempt_id): """ HTTP POST handler. To stop an exam. """ try: attempt = get_exam_attempt_by_id(attempt_id) if not attempt: err_msg = "Attempted to access attempt_id {attempt_id} but " "it does not exist.".format( attempt_id=attempt_id ) raise StudentExamAttemptDoesNotExistsException(err_msg) # make sure the the attempt belongs to the calling user_id if attempt["user"]["id"] != request.user.id: err_msg = "Attempted to access attempt_id {attempt_id} but " "does not have access to it.".format( attempt_id=attempt_id ) raise ProctoredExamPermissionDenied(err_msg) action = request.data.get("action") if action == "stop": exam_attempt_id = stop_exam_attempt(exam_id=attempt["proctored_exam"]["id"], user_id=request.user.id) elif action == "start": exam_attempt_id = start_exam_attempt(exam_id=attempt["proctored_exam"]["id"], user_id=request.user.id) elif action == "submit": exam_attempt_id = update_attempt_status( attempt["proctored_exam"]["id"], request.user.id, ProctoredExamStudentAttemptStatus.submitted ) elif action == "click_download_software": exam_attempt_id = update_attempt_status( attempt["proctored_exam"]["id"], request.user.id, ProctoredExamStudentAttemptStatus.download_software_clicked, ) elif action == "decline": exam_attempt_id = update_attempt_status( attempt["proctored_exam"]["id"], request.user.id, ProctoredExamStudentAttemptStatus.declined ) return Response({"exam_attempt_id": exam_attempt_id}) except ProctoredBaseException, ex: LOG.exception(ex) return Response(status=status.HTTP_400_BAD_REQUEST, data={"detail": str(ex)})
def put(self, request, attempt_id): """ HTTP POST handler. To stop an exam. """ attempt = get_exam_attempt_by_id(attempt_id) if not attempt: err_msg = ( 'Attempted to access attempt_id {attempt_id} but ' 'it does not exist.'.format( attempt_id=attempt_id ) ) raise StudentExamAttemptDoesNotExistsException(err_msg) # make sure the the attempt belongs to the calling user_id if attempt['user']['id'] != request.user.id: err_msg = ( 'Attempted to access attempt_id {attempt_id} but ' 'does not have access to it.'.format( attempt_id=attempt_id ) ) raise ProctoredExamPermissionDenied(err_msg) action = request.data.get('action') if action == 'stop': exam_attempt_id = stop_exam_attempt( exam_id=attempt['proctored_exam']['id'], user_id=request.user.id ) elif action == 'start': exam_attempt_id = start_exam_attempt( exam_id=attempt['proctored_exam']['id'], user_id=request.user.id ) elif action == 'submit': exam_attempt_id = update_attempt_status( attempt['proctored_exam']['id'], request.user.id, ProctoredExamStudentAttemptStatus.submitted ) elif action == 'click_download_software': exam_attempt_id = update_attempt_status( attempt['proctored_exam']['id'], request.user.id, ProctoredExamStudentAttemptStatus.download_software_clicked ) elif action == 'error': backend = attempt['proctored_exam']['backend'] waffle_name = PING_FAILURE_PASSTHROUGH_TEMPLATE.format(backend) should_block_user = not (backend and waffle.switch_is_active(waffle_name)) and ( not attempt['status'] == ProctoredExamStudentAttemptStatus.submitted ) if should_block_user: exam_attempt_id = update_attempt_status( attempt['proctored_exam']['id'], request.user.id, ProctoredExamStudentAttemptStatus.error ) else: exam_attempt_id = False LOG.warning(u'Browser JS reported problem with proctoring desktop ' u'application. Did block user: %s, for attempt: %s', should_block_user, attempt['id']) elif action == 'decline': exam_attempt_id = update_attempt_status( attempt['proctored_exam']['id'], request.user.id, ProctoredExamStudentAttemptStatus.declined ) data = {"exam_attempt_id": exam_attempt_id} return Response(data)