From 79501ab33fc631ef77db1cf926c07d491c1a9c7b Mon Sep 17 00:00:00 2001 From: Alexander Dusenbery Date: Wed, 11 Dec 2024 15:53:03 -0500 Subject: [PATCH] feat: request restricted runs --- CHANGELOG.rst | 7 +++++- federated_content_connector/__init__.py | 2 +- .../course_metadata_importer.py | 24 +++++++++++++++---- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b5b025f..aa58d27 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -13,9 +13,14 @@ Change Log Unreleased ---------- +* Nothing unreleased + +1.6.0 +----- +* feat: request restricted runs when importing course run data 1.5.2 ------------------- +----- * fix: gets custom course URL from DB if possible 1.5.1 – 2024-07-25 diff --git a/federated_content_connector/__init__.py b/federated_content_connector/__init__.py index be1b500..b2085ef 100644 --- a/federated_content_connector/__init__.py +++ b/federated_content_connector/__init__.py @@ -2,4 +2,4 @@ One-line description for README and other doc files. """ -__version__ = '1.5.2' +__version__ = '1.6.0' diff --git a/federated_content_connector/course_metadata_importer.py b/federated_content_connector/course_metadata_importer.py index fb5afec..a91e4cb 100644 --- a/federated_content_connector/course_metadata_importer.py +++ b/federated_content_connector/course_metadata_importer.py @@ -113,10 +113,15 @@ def fetch_courses_details(cls, courserun_locators, api_base_url): course_uuids = courserun_with_course_uuids.values() course_uuids_str = ','.join(course_uuids) + query_params = { + 'limit': 50, + 'include_hidden_course_runs': 1, + 'uuids': course_uuids_str, + 'include_restricted': 'custom-b2b-enterprise', + } + url_params = urlencode(query_params) + api_url = urljoin(f"{api_base_url}/", f"courses/?{url_params}") logger.info(f'[{cls.LOG_PREFIX}] Fetching details from discovery. Course UUIDs {course_uuids}.') - api_url = urljoin( - f"{api_base_url}/", f"courses/?limit=50&include_hidden_course_runs=1&uuids={course_uuids_str}" - ) response = cls.get_response_from_api(api_url) courses_details = response.json() results = courses_details.get('results', []) @@ -131,10 +136,18 @@ def fetch_course_uuids(cls, api_base_url, courserun_locators): courserun_keys = list(map(str, courserun_locators)) encoded_courserun_keys = ','.join(map(quote_plus, courserun_keys)) - logger.info(f'[{cls.LOG_PREFIX}] Fetching uuids for Courseruns {encoded_courserun_keys}') + query_param_str = ( + '?limit=50&' + 'include_hidden_course_runs=1&' + 'include_restricted=custom-b2b-enterprise&' + f'keys={encoded_courserun_keys}' + ) api_url = urljoin( - f"{api_base_url}/", f"course_runs/?limit=50&include_hidden_course_runs=1&keys={encoded_courserun_keys}" + f"{api_base_url}/", + f"course_runs/{query_param_str}" ) + + logger.info(f'[{cls.LOG_PREFIX}] Fetching uuids for Courseruns {courserun_keys}') response = cls.get_response_from_api(api_url) courses_details = response.json() results = courses_details.get('results', []) @@ -157,6 +170,7 @@ def courses(cls, timestamp): 'timestamp': timestamp, 'limit': 50, 'include_hidden_course_runs': 1, + 'include_restricted': 'custom-b2b-enterprise', } api_base_url = get_catalog_api_base_url()