Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set enrollment url course id to advertised course run key #1018

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 8 additions & 1 deletion enterprise_catalog/apps/catalog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
from enterprise_catalog.apps.catalog.utils import (
batch,
enterprise_proxy_login_url,
get_advertised_course_run,
get_content_filter_hash,
get_content_key,
get_content_type,
Expand Down Expand Up @@ -555,10 +556,16 @@ def get_content_enrollment_url(self, content_metadata):
else:
# Catalog param only needed for legacy (non-learner-portal) enrollment URLs
params['catalog'] = self.uuid

course_key = content_key if parent_content_key else None
course_run_key = content_key if not parent_content_key else None
if not parent_content_key:
if advertised_course_run := get_advertised_course_run(content_metadata.json_metadata):
course_run_key = advertised_course_run['key']
url = '{}/enterprise/{}/course/{}/enroll/'.format(
settings.LMS_BASE_URL,
self.enterprise_uuid,
content_key,
course_run_key or course_key,
)

return update_query_parameters(url, params)
Expand Down
2 changes: 1 addition & 1 deletion enterprise_catalog/apps/catalog/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _json_metadata(self):
'logo_image_url': fake.image_url() + '.jpg',
}]
course_runs = [{
'key': 'course-v1:edX+DemoX',
'key': 'course-v1:edX+DemoX+2T2024',
'uuid': str(FAKE_ADVERTISED_COURSE_RUN_UUID),
'content_language': 'en-us',
'status': 'published',
Expand Down
40 changes: 40 additions & 0 deletions enterprise_catalog/apps/catalog/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,46 @@ def test_get_content_enrollment_url(
else:
assert settings.LMS_BASE_URL in content_enrollment_url

@ddt.data(
{
'content_key': 'course-v1:edX+DemoX+2T2024',
'parent_content_key': 'edX+DemoX',
},
{
'content_key': 'edX+DemoX',
'parent_content_key': None
},
)
@ddt.unpack
def test_get_content_enrollment_url_disabled_learner_portal(
self,
content_key,
parent_content_key,
):
enterprise_uuid = uuid4()
enterprise_slug = 'sluggy'

enterprise_catalog = factories.EnterpriseCatalogFactory(enterprise_uuid=enterprise_uuid)
content_metadata = factories.ContentMetadataFactory(
content_key=content_key,
parent_content_key=parent_content_key,
content_type=COURSE,
)

enterprise_catalog.catalog_query.contentmetadata_set.add(*[content_metadata])

mock_enterprise_customer_return_value = {
'slug': enterprise_slug,
'enable_learner_portal': False,
}

with self._mock_enterprise_customer_cache(
mock_enterprise_customer_return_value,
):
content_enrollment_url = enterprise_catalog.get_content_enrollment_url(content_metadata)

assert "/course/course-v1:edX+DemoX+2T2024/enroll/" in content_enrollment_url

@mock.patch('enterprise_catalog.apps.api_client.enterprise_cache.EnterpriseApiClient')
@ddt.data(
{
Expand Down
17 changes: 17 additions & 0 deletions enterprise_catalog/apps/catalog/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,20 @@ def get_course_run_by_uuid(course, course_run_uuid):
except IndexError:
return None
return course_run


def get_advertised_course_run(course):
"""
Get part of the advertised course_run as per advertised_course_run_uuid

Argument:
course (dict)

Returns:
dict: containing key, pacing_type, start, end, and upgrade deadline
for the course_run, or None
"""
full_course_run = get_course_run_by_uuid(course, course.get('advertised_course_run_uuid'))
if full_course_run is None:
return None
return full_course_run
Loading