Skip to content
Snippets Groups Projects
Commit 0c031382 authored by Matthew Piatetsky's avatar Matthew Piatetsky
Browse files

show graded content block without the upsell when the upgrade deadline is expired

parent 44c96b4e
No related branches found
No related tags found
No related merge requests found
......@@ -7,9 +7,11 @@ of audit learners.
from __future__ import absolute_import
import datetime
import logging
import crum
import pytz
import six
from django.template.loader import render_to_string
from django.utils.translation import ugettext_lazy as _
......@@ -79,13 +81,18 @@ class ContentTypeGatingPartition(UserPartition):
def access_denied_fragment(self, block, user, user_group, allowed_groups):
course_key = self._get_course_key_from_course_block(block)
course = CourseOverview.get_from_id(course_key)
modes = CourseMode.modes_for_course_dict(course=course)
modes = CourseMode.modes_for_course_dict(course=course, include_expired=True)
verified_mode = modes.get(CourseMode.VERIFIED)
if (verified_mode is None or user_group == FULL_ACCESS or
user_group in allowed_groups):
return None
ecommerce_checkout_link = self._get_checkout_link(user, verified_mode.sku)
expiration_datetime = verified_mode.expiration_datetime
if expiration_datetime and expiration_datetime < datetime.datetime.now(pytz.UTC):
ecommerce_checkout_link = None
else:
ecommerce_checkout_link = self._get_checkout_link(user, verified_mode.sku)
request = crum.get_current_request()
upgrade_price, _ = format_strikeout_price(user, course)
......
......@@ -334,13 +334,9 @@ class TestProblemTypeAccess(SharedModuleStoreTestCase):
cls.courses['expired_upgrade_deadline'] = cls._create_course(
run='expired_upgrade_deadline_run_1',
display_name='Expired Upgrade Deadline Course Title',
modes=['audit'],
component_types=['problem', 'html']
)
CourseModeFactory.create(
course_id=cls.courses['expired_upgrade_deadline']['course'].scope_ids.usage_id.course_key,
mode_slug='verified',
expiration_datetime=datetime(2018, 1, 1)
modes=['audit', 'verified'],
component_types=['problem', 'html'],
expired_upgrade_deadline=True
)
def setUp(self):
......@@ -382,7 +378,7 @@ class TestProblemTypeAccess(SharedModuleStoreTestCase):
ContentTypeGatingConfig.objects.create(enabled=True, enabled_as_of=datetime(2018, 1, 1))
@classmethod
def _create_course(cls, run, display_name, modes, component_types):
def _create_course(cls, run, display_name, modes, component_types, expired_upgrade_deadline=False):
"""
Helper method to create a course
Arguments:
......@@ -403,7 +399,10 @@ class TestProblemTypeAccess(SharedModuleStoreTestCase):
course = CourseFactory.create(run=run, display_name=display_name, start=start_date)
for mode in modes:
CourseModeFactory.create(course_id=course.id, mode_slug=mode)
if expired_upgrade_deadline and mode == 'verified':
CourseModeFactory.create(course_id=course.id, mode_slug=mode, expiration_datetime=datetime(2020, 1, 1))
else:
CourseModeFactory.create(course_id=course.id, mode_slug=mode)
with cls.store.bulk_operations(course.id):
blocks_dict = {}
......@@ -531,9 +530,9 @@ class TestProblemTypeAccess(SharedModuleStoreTestCase):
the user will continue to see gated content, but the upgrade messaging will be removed.
"""
_assert_block_is_gated(
block=self.courses['default']['blocks']['problem'],
block=self.courses['expired_upgrade_deadline']['blocks']['problem'],
user=self.users['audit'],
course=self.courses['default']['course'],
course=self.courses['expired_upgrade_deadline']['course'],
is_gated=True,
request_factory=self.factory,
has_upgrade_link=False
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment