Skip to content

Commit

Permalink
Merge pull request #963 from edx/alangsto/fix_onboarding_reset_order
Browse files Browse the repository at this point in the history
fix: if multiple attempts for a user exist, return attempt with non-reset status if possible
  • Loading branch information
alangsto authored Sep 21, 2021
2 parents 4487344 + e9300e1 commit 24af502
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Change Log
Unreleased
~~~~~~~~~~

[4.0.1] - 2021-09-21
~~~~~~~~~~~~~~~~~~~~~
* Bug fix for student onboarding statuses by course. If learner has multiple attempts, return non-reset attempt status if possible.

[4.0.0] - 2021-08-25
~~~~~~~~~~~~~~~~~~~~~
**BREAKING CHANGES:**
Expand Down
2 changes: 1 addition & 1 deletion edx_proctoring/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"""

# Be sure to update the version number in edx_proctoring/package.json
__version__ = '4.0.0'
__version__ = '4.0.1'

default_app_config = 'edx_proctoring.apps.EdxProctoringConfig' # pylint: disable=invalid-name
9 changes: 8 additions & 1 deletion edx_proctoring/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1598,7 +1598,8 @@ def test_returns_correct_attempt(self, attempt_statuses, expected_onboarding_sta
self.assertEqual(response.status_code, 200)
self.assertEqual(response_data['results'][0]['status'], expected_onboarding_status)

def test_multiple_exam_attempts(self):
@ddt.data(True, False)
def test_multiple_exam_attempts(self, should_reset_attempt_be_most_recent_modified):
attempt_id = create_exam_attempt(self.onboarding_exam.id, self.user.id, True)

# create a second exam attempt by resetting the onboarding attempt
Expand All @@ -1609,6 +1610,12 @@ def test_multiple_exam_attempts(self):
# get serialized onboarding_attempt to get modified time
serialized_onboarding_attempt = get_exam_attempt_by_id(second_exam_attempt_id)

if should_reset_attempt_be_most_recent_modified:
# if we want the reset attempt to have the most recent modified date, we should resave the attempt
# a reset attempt having a more recent modified date is an edge case
attempt = ProctoredExamStudentAttempt.objects.get(id=attempt_id)
attempt.save()

response = self.client.get(reverse(
'edx_proctoring:user_onboarding.status.course',
kwargs={'course_id': self.onboarding_exam.course_id}
Expand Down
9 changes: 8 additions & 1 deletion edx_proctoring/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ def _get_onboarding_info_no_onboarding_api(self, course_id, onboarding_exam, use
onboarding_attempts = ProctoredExamStudentAttempt.objects.get_proctored_practice_attempts_by_course_id(
course_id,
users
).values('user_id', 'status', 'modified')
).values('user_id', 'status', 'modified', 'id')

# get all of the last verified onboarding attempts of these users
last_verified_attempt_dict = get_last_verified_onboarding_attempts_per_user(
Expand Down Expand Up @@ -967,6 +967,7 @@ def _get_relevant_attempt_per_user(self, attempts):
"""
Given an ordered list of attempts, return, for each learner, their most recent
exam attempt. If the learner has a verified attempt, always return verified.
If possible, do not return a reset attempt.
Parameters:
* attempts: an iterable of attempt objects
"""
Expand All @@ -979,6 +980,12 @@ def _get_relevant_attempt_per_user(self, attempts):
# Always return a verified attempt if it exists.
if attempt['status'] == ProctoredExamStudentAttemptStatus.verified:
onboarding_attempts_per_user[attempt['user_id']] = attempt
# Always return a non reset attempt if its ID is greater
if (
existing_attempt['status'] == ProctoredExamStudentAttemptStatus.onboarding_reset
and existing_attempt['id'] < attempt['id']
):
onboarding_attempts_per_user[attempt['user_id']] = attempt
else:
onboarding_attempts_per_user[attempt['user_id']] = attempt

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@edx/edx-proctoring",
"//": "Note that the version format is slightly different than that of the Python version when using prereleases.",
"version": "4.0.0",
"version": "4.0.1",
"main": "edx_proctoring/static/index.js",
"scripts": {
"test": "gulp test"
Expand Down

0 comments on commit 24af502

Please sign in to comment.