Update the entitlement fulfilment logic to work with enrollment end

[LEARNER-5275]

Update the endtitlement fulfillment logic to work for users who have
enrolled, enrollment window has closed, but upgrade window is still
open. These users should be able to use that enrollment on their course
run that they are enrolled in.
This commit is contained in:
Albert St. Aubin
2018-06-21 14:52:03 -04:00
parent df16836a8f
commit 06af818322
4 changed files with 27 additions and 4 deletions

View File

@@ -139,6 +139,20 @@ class TestCourseRunFulfillableForEntitlement(ModuleStoreTestCase):
assert is_course_run_entitlement_fulfillable(course_overview.id, entitlement)
def test_course_run_fulfillable_enrollment_ended_upgrade_open(self):
course_overview = self.create_course(
start_from_now=-3,
end_from_now=2,
enrollment_start_from_now=-2,
enrollment_end_from_now=-1,
)
entitlement = CourseEntitlementFactory.create(mode=CourseMode.VERIFIED)
# Enroll User in the Course, but do not update the entitlement
CourseEnrollmentFactory.create(user=entitlement.user, course_id=course_overview.id)
assert is_course_run_entitlement_fulfillable(course_overview.id, entitlement)
def test_course_run_not_fulfillable_upgrade_ended(self):
course_overview = self.create_course(
start_from_now=-3,

View File

@@ -8,16 +8,21 @@ from django.utils import timezone
from course_modes.models import CourseMode
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
from student.models import CourseEnrollment
log = logging.getLogger("common.entitlements.utils")
def is_course_run_entitlement_fulfillable(course_run_key, entitlement, compare_date=timezone.now()):
def is_course_run_entitlement_fulfillable(
course_run_key,
entitlement,
compare_date=timezone.now(),
):
"""
Checks that the current run meets the following criteria for an entitlement
1) Is currently running or start in the future
2) A User can enroll in
2) A User can enroll in or is currently enrolled
3) A User can upgrade to the entitlement mode
Arguments:
@@ -50,8 +55,11 @@ def is_course_run_entitlement_fulfillable(course_run_key, entitlement, compare_d
and (not enrollment_end or enrollment_end > compare_date)
)
# Is the user already enrolled in the Course Run
is_enrolled = CourseEnrollment.is_enrolled(entitlement.user, course_run_key)
# Ensure the course run is upgradeable and the mode matches the entitlement's mode
unexpired_paid_modes = [mode.slug for mode in CourseMode.paid_modes_for_course(course_run_key)]
can_upgrade = unexpired_paid_modes and entitlement.mode in unexpired_paid_modes
return is_running and can_upgrade and can_enroll
return is_running and can_upgrade and (is_enrolled or can_enroll)

View File

@@ -1270,7 +1270,7 @@ class CourseEnrollment(models.Model):
Args:
user (User): The user associated with the enrollment.
course_id (CourseKey): The key of the course associated with the enrollment.
course_key (CourseKey): The key of the course associated with the enrollment.
Returns:
Course enrollment object or None

View File

@@ -94,6 +94,7 @@ class EntitlementForm extends React.Component {
{ label: '--', value: '' },
{ label: 'Verified', value: 'verified' },
{ label: 'Professional', value: 'professional' },
{ label: 'No ID Professional', value: 'no-id-professional' },
]}
onChange={this.handleModeChange}
/>