Merge pull request #16933 from edx/HarryRein/LEARNER-3636-dont-show-expired-entitlements-unenrolled
Do not show expired, unfulfilled entitlements on dashboards.
This commit is contained in:
@@ -257,3 +257,32 @@ class CourseEntitlement(TimeStampedModel):
|
||||
@classmethod
|
||||
def unexpired_entitlements_for_user(cls, user):
|
||||
return cls.objects.filter(user=user, expired_at=None).select_related('user')
|
||||
|
||||
@classmethod
|
||||
def get_entitlement_if_active(cls, user, course_uuid):
|
||||
"""
|
||||
Returns an entitlement for a given course uuid if an active entitlement exists, otherwise returns None.
|
||||
An active entitlement is defined as an entitlement that has not yet expired or has a currently enrolled session.
|
||||
"""
|
||||
return cls.objects.filter(
|
||||
user=user,
|
||||
course_uuid=course_uuid
|
||||
).exclude(expired_at__isnull=False, enrollment_course_run=None).first()
|
||||
|
||||
@classmethod
|
||||
def get_active_entitlements_for_user(cls, user):
|
||||
"""
|
||||
Returns a list of active (enrolled or not yet expired) entitlements.
|
||||
|
||||
Returns any entitlements that are:
|
||||
1) Not expired and no session selected
|
||||
2) Not expired and a session is selected
|
||||
3) Expired and a session is selected
|
||||
|
||||
Does not return any entitlements that are:
|
||||
1) Expired and no session selected
|
||||
"""
|
||||
return cls.objects.filter(user=user).exclude(
|
||||
expired_at__isnull=False,
|
||||
enrollment_course_run=None
|
||||
).select_related('user').select_related('enrollment_course_run')
|
||||
|
||||
@@ -376,11 +376,15 @@ class StudentDashboardTests(SharedModuleStoreTestCase, MilestonesTestCaseMixin):
|
||||
@patch.object(CourseOverview, 'get_from_id')
|
||||
def test_unfulfilled_expired_entitlement(self, mock_course_overview, mock_course_runs):
|
||||
"""
|
||||
When a learner has an unfulfilled, expired entitlement, their course dashboard should have:
|
||||
- a hidden 'View Course' button
|
||||
- a message saying that they can no longer select a session
|
||||
When a learner has an unfulfilled, expired entitlement, a card should NOT appear on the dashboard.
|
||||
This use case represents either an entitlement that the user waited too long to fulfill, or an entitlement
|
||||
for which they received a refund.
|
||||
"""
|
||||
CourseEntitlementFactory(user=self.user, created=self.THREE_YEARS_AGO)
|
||||
CourseEntitlementFactory(
|
||||
user=self.user,
|
||||
created=self.THREE_YEARS_AGO,
|
||||
expired_at=datetime.datetime.now()
|
||||
)
|
||||
mock_course_overview.return_value = CourseOverviewFactory(start=self.TOMORROW)
|
||||
mock_course_runs.return_value = [
|
||||
{
|
||||
@@ -391,9 +395,7 @@ class StudentDashboardTests(SharedModuleStoreTestCase, MilestonesTestCaseMixin):
|
||||
}
|
||||
]
|
||||
response = self.client.get(self.path)
|
||||
self.assertIn('class="enter-course hidden"', response.content)
|
||||
self.assertIn('You can no longer select a session', response.content)
|
||||
self.assertNotIn('<div class="course-entitlement-selection-container ">', response.content)
|
||||
self.assertEqual(response.content.count('<li class="course-item">'), 0)
|
||||
|
||||
@patch('openedx.core.djangoapps.programs.utils.get_programs')
|
||||
@patch('student.views.get_course_runs_for_course')
|
||||
|
||||
@@ -698,7 +698,7 @@ def dashboard(request):
|
||||
course_enrollments = list(get_course_enrollments(user, site_org_whitelist, site_org_blacklist))
|
||||
|
||||
# Get the entitlements for the user and a mapping to all available sessions for that entitlement
|
||||
course_entitlements = list(CourseEntitlement.objects.filter(user=user).select_related('enrollment_course_run'))
|
||||
course_entitlements = list(CourseEntitlement.get_active_entitlements_for_user(user))
|
||||
course_entitlement_available_sessions = {}
|
||||
for course_entitlement in course_entitlements:
|
||||
course_entitlement.update_expired_at()
|
||||
|
||||
Reference in New Issue
Block a user