Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions common/djangoapps/course_modes/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def test_suggested_prices(self, price_list):
# that the right template rendered

@httpretty.activate
@patch('common.djangoapps.course_modes.views.enterprise_customer_for_request')
@patch('common.djangoapps.course_modes.views.CourseModeCheckoutStarted.run_filter')
@patch('common.djangoapps.course_modes.views.get_course_final_price')
@ddt.data(
(1.0, True),
Expand All @@ -198,7 +198,7 @@ def test_display_after_discounted_price(
discounted_price,
is_enterprise_enabled,
mock_get_course_final_price,
mock_enterprise_customer_for_request
mock_run_filter
):
verified_mode = CourseModeFactory.create(mode_slug='verified', course_id=self.course.id, sku='dummy')
CourseEnrollmentFactory(
Expand All @@ -207,7 +207,8 @@ def test_display_after_discounted_price(
user=self.user
)

mock_enterprise_customer_for_request.return_value = {'name': 'dummy'} if is_enterprise_enabled else {}
enterprise_customer = {'name': 'dummy', 'uuid': 'test-uuid'} if is_enterprise_enabled else None
mock_run_filter.return_value = {'enterprise_customer': enterprise_customer}
mock_get_course_final_price.return_value = discounted_price
url = reverse('course_modes_choose', args=[self.course.id])
response = self.client.get(url)
Expand Down
12 changes: 6 additions & 6 deletions common/djangoapps/course_modes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from django.views.generic.base import View
from edx_django_utils.monitoring.utils import increment
from opaque_keys.edx.keys import CourseKey
from openedx_filters.learning.filters import CourseModeCheckoutStarted
from urllib.parse import urljoin # lint-amnesty, pylint: disable=wrong-import-order

from common.djangoapps.course_modes.models import CourseMode
Expand All @@ -39,7 +40,6 @@
from openedx.features.course_duration_limits.models import CourseDurationLimitConfig
from openedx.features.course_duration_limits.access import get_user_course_duration, get_user_course_expiration_date
from openedx.features.course_experience import course_home_url
from openedx.features.enterprise_support.api import enterprise_customer_for_request
from common.djangoapps.student.models import CourseEnrollment
from common.djangoapps.util.db import outer_atomic
from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order
Expand Down Expand Up @@ -188,12 +188,12 @@ def get(self, request, course_id, error=None): # lint-amnesty, pylint: disable=
]
price_before_discount = verified_mode.min_price
course_price = price_before_discount
enterprise_customer = enterprise_customer_for_request(request)
LOG.info(
'[e-commerce calculate API] Going to hit the API for user [%s] linked to [%s] enterprise',
request.user.username,
enterprise_customer.get('name') if isinstance(enterprise_customer, dict) else None # Test Purpose
checkout_context = CourseModeCheckoutStarted.run_filter(
context={},
request=request,
course_mode=verified_mode,
)
enterprise_customer = checkout_context.get('enterprise_customer')
if enterprise_customer and verified_mode.sku:
course_price = get_course_final_price(request.user, verified_mode.sku, price_before_discount)

Expand Down
12 changes: 12 additions & 0 deletions lms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3172,3 +3172,15 @@ def _should_send_certificate_events(settings):
SSL_AUTH_DN_FORMAT_STRING = (
"/C=US/ST=Massachusetts/O=Massachusetts Institute of Technology/OU=Client CA v1/CN={0}/emailAddress={1}"
)

# .. setting_name: OPEN_EDX_FILTERS_CONFIG
# .. setting_default: {}
# .. setting_description: Configuration dict for openedx-filters pipeline steps.
# Keys are filter type strings; values are dicts with 'fail_silently' (bool) and
# 'pipeline' (list of dotted-path strings to PipelineStep subclasses).
OPEN_EDX_FILTERS_CONFIG = {
"org.openedx.learning.course_mode.checkout.started.v1": {
"fail_silently": True,
"pipeline": ["enterprise.filters.course_modes.CheckoutEnterpriseContextInjector"],
},
}
14 changes: 14 additions & 0 deletions lms/envs/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def get_env_setting(setting):
'EVENT_BUS_PRODUCER_CONFIG',
'DEFAULT_FILE_STORAGE',
'STATICFILES_STORAGE',
'OPEN_EDX_FILTERS_CONFIG',
]
})

Expand Down Expand Up @@ -515,6 +516,19 @@ def get_env_setting(setting):
_YAML_TOKENS.get('EVENT_BUS_PRODUCER_CONFIG', {})
)

# Merge OPEN_EDX_FILTERS_CONFIG from YAML into the default defined in common.py.
# Pipeline steps from YAML are appended after steps defined in common.py.
# The fail_silently value from YAML takes precedence over the one in common.py.
for _filter_type, _filter_config in _YAML_TOKENS.get('OPEN_EDX_FILTERS_CONFIG', {}).items():
if _filter_type in OPEN_EDX_FILTERS_CONFIG:
OPEN_EDX_FILTERS_CONFIG[_filter_type]['pipeline'].extend(
_filter_config.get('pipeline', [])
)
if 'fail_silently' in _filter_config:
OPEN_EDX_FILTERS_CONFIG[_filter_type]['fail_silently'] = _filter_config['fail_silently']
else:
OPEN_EDX_FILTERS_CONFIG[_filter_type] = _filter_config

#######################################################################################################################
# HEY! Don't add anything to the end of this file.
# Add your defaults to common.py instead!
Expand Down
Loading