Merge pull request #19250 from edx/REV-503/add-banner-to-courseware
add expiration banner
This commit is contained in:
@@ -12,9 +12,12 @@ from django.utils.translation import ugettext as _
|
||||
from util.date_utils import DEFAULT_SHORT_DATE_FORMAT, strftime_localized
|
||||
from lms.djangoapps.courseware.access_response import AccessError
|
||||
from lms.djangoapps.courseware.access_utils import ACCESS_GRANTED
|
||||
from lms.djangoapps.courseware.date_summary import verified_upgrade_deadline_link
|
||||
from openedx.core.djangoapps.catalog.utils import get_course_run_details
|
||||
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
|
||||
|
||||
from openedx.core.djangoapps.util.user_messages import PageLevelMessages
|
||||
from openedx.core.djangolib.markup import HTML
|
||||
from openedx.features.course_duration_limits.config import CONTENT_TYPE_GATING_FLAG
|
||||
|
||||
MIN_DURATION = timedelta(weeks=4)
|
||||
MAX_DURATION = timedelta(weeks=12)
|
||||
@@ -91,3 +94,21 @@ def check_course_expired(user, course):
|
||||
return AuditExpiredError(user, course, expiration_date)
|
||||
|
||||
return ACCESS_GRANTED
|
||||
|
||||
|
||||
def register_course_expired_message(request, course):
|
||||
"""
|
||||
Add a banner notifying the user of the user course expiration date if it exists.
|
||||
"""
|
||||
if CONTENT_TYPE_GATING_FLAG.is_enabled():
|
||||
expiration_date = get_user_course_expiration_date(request.user, course)
|
||||
if expiration_date:
|
||||
upgrade_message = _('Your access to this course expires on {expiration_date}. \
|
||||
<a href="{upgrade_link}">Upgrade now</a> for unlimited access.')
|
||||
PageLevelMessages.register_info_message(
|
||||
request,
|
||||
HTML(upgrade_message).format(
|
||||
expiration_date=expiration_date.strftime('%b %-d'),
|
||||
upgrade_link=verified_upgrade_deadline_link(user=request.user, course=course)
|
||||
)
|
||||
)
|
||||
|
||||
@@ -17,6 +17,7 @@ from waffle.testutils import override_flag
|
||||
|
||||
from course_modes.models import CourseMode
|
||||
from courseware.tests.factories import StaffFactory
|
||||
from courseware.tests.helpers import get_expiration_banner_text
|
||||
from lms.djangoapps.commerce.models import CommerceConfiguration
|
||||
from lms.djangoapps.commerce.utils import EcommerceService
|
||||
from lms.djangoapps.course_goals.api import add_course_goal, remove_course_goal
|
||||
@@ -180,7 +181,7 @@ class TestCourseHomePage(CourseHomePageTestCase):
|
||||
course_home_url(self.course)
|
||||
|
||||
# Fetch the view and verify the query counts
|
||||
with self.assertNumQueries(67, table_blacklist=QUERY_COUNT_TABLE_BLACKLIST):
|
||||
with self.assertNumQueries(70, table_blacklist=QUERY_COUNT_TABLE_BLACKLIST):
|
||||
with check_mongo_calls(4):
|
||||
url = course_home_url(self.course)
|
||||
self.client.get(url)
|
||||
@@ -414,7 +415,9 @@ class TestCourseHomePageAccess(CourseHomePageTestCase):
|
||||
2) Unenrolled users are shown a course message allowing them to enroll
|
||||
3) Enrolled users who show up on the course page after the course has begun
|
||||
are not shown a course message.
|
||||
4) Enrolled users who show up on the course page before the course begins
|
||||
4) Enrolled users who show up on the course page after the course has begun will
|
||||
see the course expiration banner if course duration limits are on for the course.
|
||||
5) Enrolled users who show up on the course page before the course begins
|
||||
are shown a message explaining when the course starts as well as a call to
|
||||
action button that allows them to add a calendar event.
|
||||
"""
|
||||
@@ -439,6 +442,20 @@ class TestCourseHomePageAccess(CourseHomePageTestCase):
|
||||
self.assertNotContains(response, TEST_COURSE_HOME_MESSAGE_UNENROLLED)
|
||||
self.assertNotContains(response, TEST_COURSE_HOME_MESSAGE_PRE_START)
|
||||
|
||||
# Verify that enrolled users are shown the course expiration banner if content gating is enabled
|
||||
with override_waffle_flag(CONTENT_TYPE_GATING_FLAG, True):
|
||||
url = course_home_url(self.course)
|
||||
response = self.client.get(url)
|
||||
bannerText = get_expiration_banner_text(user, self.course)
|
||||
self.assertContains(response, bannerText, html=True)
|
||||
|
||||
# Verify that enrolled users are not shown the course expiration banner if content gating is disabled
|
||||
with override_waffle_flag(CONTENT_TYPE_GATING_FLAG, False):
|
||||
url = course_home_url(self.course)
|
||||
response = self.client.get(url)
|
||||
bannerText = get_expiration_banner_text(user, self.course)
|
||||
self.assertNotContains(response, bannerText, html=True)
|
||||
|
||||
# Verify that enrolled users are shown 'days until start' message before start date
|
||||
future_course = self.create_future_course()
|
||||
CourseEnrollment.enroll(user, future_course.id)
|
||||
|
||||
@@ -127,7 +127,7 @@ class TestCourseUpdatesPage(SharedModuleStoreTestCase):
|
||||
course_updates_url(self.course)
|
||||
|
||||
# Fetch the view and verify that the query counts haven't changed
|
||||
with self.assertNumQueries(39, table_blacklist=QUERY_COUNT_TABLE_BLACKLIST):
|
||||
with self.assertNumQueries(42, table_blacklist=QUERY_COUNT_TABLE_BLACKLIST):
|
||||
with check_mongo_calls(4):
|
||||
url = course_updates_url(self.course)
|
||||
self.client.get(url)
|
||||
|
||||
Reference in New Issue
Block a user