Skip to content

Commit

Permalink
Merge pull request #1088 from openedx/ashultz0/expired-onboarding
Browse files Browse the repository at this point in the history
fix expiration dates and display for onboarding exams
  • Loading branch information
ashultz0 authored Nov 2, 2022
2 parents a188301 + 9666d10 commit 3a6ae10
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Change Log
Unreleased
~~~~~~~~~~
[4.13.2] - 2022-10-27
~~~~~~~~~~~~~~~~~~~~~
* Fix onboarding expiration messaging to not say expiring soon after expiration.

[4.13.1] - 2022-10-27
~~~~~~~~~~~~~~~~~~~~~
* Adjust verification time to one year down from two
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.13.1'
__version__ = '4.13.2'

default_app_config = 'edx_proctoring.apps.EdxProctoringConfig' # pylint: disable=invalid-name
40 changes: 26 additions & 14 deletions edx_proctoring/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3106,7 +3106,6 @@ def get_onboarding_attempt_data_for_learner(course_id, user, backend):
* user: User object
* backend: proctoring provider to filter exams on
"""
data = {'onboarding_status': None, 'expiration_date': None}
attempts = ProctoredExamStudentAttempt.objects.get_proctored_practice_attempts_by_course_id(course_id, [user])

# Default to the most recent attempt in the course if there are no verified attempts
Expand All @@ -3116,19 +3115,32 @@ def get_onboarding_attempt_data_for_learner(course_id, user, backend):
relevant_attempt = attempt
break

# If there is no verified attempt in the current course, check for a verified attempt in another course
verified_attempt = None
if not relevant_attempt or relevant_attempt.status != ProctoredExamStudentAttemptStatus.verified:
attempt_dict = get_last_verified_onboarding_attempts_per_user(
[user],
backend,
)
verified_attempt = attempt_dict.get(user.id)
if relevant_attempt and relevant_attempt.status == ProctoredExamStudentAttemptStatus.verified:
return {
'onboarding_status': relevant_attempt.status,
'expiration_date': relevant_attempt.modified + timedelta(days=constants.VERIFICATION_DAYS_VALID),
}

# otherwise look for another course's verified attempt
attempt_dict = get_last_verified_onboarding_attempts_per_user(
[user],
backend,
)
verified_attempt = attempt_dict.get(user.id)

if verified_attempt:
data['onboarding_status'] = InstructorDashboardOnboardingAttemptStatus.other_course_approved
data['expiration_date'] = verified_attempt.modified + timedelta(days=constants.VERIFICATION_DAYS_VALID)
elif relevant_attempt:
data['onboarding_status'] = relevant_attempt.status
return {
'onboarding_status': InstructorDashboardOnboardingAttemptStatus.other_course_approved,
'expiration_date': verified_attempt.modified + timedelta(days=constants.VERIFICATION_DAYS_VALID),
}

return data
if relevant_attempt:
return {
'onboarding_status': relevant_attempt.status,
'expiration_date': None,
}

return {
'onboarding_status': None,
'expiration_date': None,
}
33 changes: 27 additions & 6 deletions edx_proctoring/static/proctoring/js/views/proctored_exam_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

var examStatusReadableFormat, notStartedText, startedText, submittedText;

// warning threshold for "onboarding expires soon"
var twentyeightDays = 28 * 24 * 60 * 60 * 1000;

edx.courseware = edx.courseware || {};
edx.courseware.proctored_exam = edx.courseware.proctored_exam || {};

Expand Down Expand Up @@ -51,11 +54,18 @@
expiring_soon: {
status: gettext('Expiring Soon'),
message: gettext(
'Your onboarding profile has been approved in another course. ' +
'Your onboarding profile has been approved. ' +
'However, your onboarding status is expiring soon. Please ' +
'complete onboarding again to ensure that you will be ' +
'able to continue taking proctored exams.'
)
},
expired: {
status: gettext('Expired'),
message: gettext(
'Your onboarding status has expired. Please ' +
'complete onboarding again to continue taking proctored exams.'
)
}
};

Expand Down Expand Up @@ -142,12 +152,21 @@
},

isExpiringSoon: function(expirationDate) {
var today = new Date();
var expirationDateObject = new Date(expirationDate);
// Return true if the expiration date is within 28 days
return today.getTime() > expirationDateObject.getTime() - 2419200000;
// returns true if expiring soon, returns false if not soon or already expired
var expirationTime = new Date(expirationDate).getTime();
var now = new Date().getTime();
return (!this.isExpired(expirationDate))
&& (now > (expirationTime - twentyeightDays));
},

isExpired: function(expirationDate) {
// returns true if already expired
var expirationTime = new Date(expirationDate).getTime();
var now = new Date().getTime();
return now >= expirationTime;
},


shouldShowExamLink: function(status) {
// show the exam link if the user should retry onboarding, or if they haven't submitted the exam
var NO_SHOW_STATES = ['submitted', 'second_review_required', 'verified'];
Expand All @@ -160,7 +179,9 @@
var now = new Date();
var data = this.model.toJSON();
if (this.template) {
if (data.expiration_date && this.isExpiringSoon(data.expiration_date)) {
if (data.expiration_date && this.isExpired(data.expiration_date)) {
this.status = 'expired';
} else if (data.expiration_date && this.isExpiringSoon(data.expiration_date)) {
this.status = 'expiring_soon';
} else {
this.status = data.onboarding_status;
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.13.1",
"version": "4.13.2",
"main": "edx_proctoring/static/index.js",
"scripts": {
"test": "gulp test"
Expand Down

0 comments on commit 3a6ae10

Please sign in to comment.