From 19d53e528a8b2e103831e4ab1a4148f24cbc034a Mon Sep 17 00:00:00 2001 From: tpanda-sonata Date: Mon, 1 Dec 2025 01:59:15 +0000 Subject: [PATCH 1/2] solved unpublished --- ...enterprise_catalog_get_content_metadata.py | 44 +++++++++++++++---- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/enterprise_catalog/apps/api/v1/views/enterprise_catalog_get_content_metadata.py b/enterprise_catalog/apps/api/v1/views/enterprise_catalog_get_content_metadata.py index bbca33fd..c7b46f54 100644 --- a/enterprise_catalog/apps/api/v1/views/enterprise_catalog_get_content_metadata.py +++ b/enterprise_catalog/apps/api/v1/views/enterprise_catalog_get_content_metadata.py @@ -209,6 +209,23 @@ def get(self, request, **kwargs): return self.get_content_metadata(request, traverse_pagination, content_keys_filter) + # def is_active(self, item): + # """ + # Determines if a content item is active. + # Args: + # item (ContentMetadata): The content metadata item to check. + # Returns: + # bool: True if the item is active, False otherwise. + # For courses, checks if any course run is active. + # For other content types, always returns True. + # """ + # if item.content_type == 'course': + # active = is_any_course_run_active( + # item.json_metadata.get('course_runs', [])) + # if not active: + # logger.debug(f'[get_content_metadata]: Content item {item.content_key} is not active.') + # return active + # return True def is_active(self, item): """ Determines if a content item is active. @@ -218,14 +235,21 @@ def is_active(self, item): bool: True if the item is active, False otherwise. For courses, checks if any course run is active. For other content types, always returns True. - """ - if item.content_type == 'course': - active = is_any_course_run_active( - item.json_metadata.get('course_runs', [])) - if not active: - logger.debug(f'[get_content_metadata]: Content item {item.content_key} is not active.') - return active - return True + For courses, requires that the course has at least one published course run. + This prevents courses that only contain unsubmitted/draft runs from being + returned to enterprise customers. The serializer still uses + `is_any_course_run_active` to set the `active` field in the payload. + """ + if item.content_type == 'course': + course_runs = item.json_metadata.get('course_runs', []) or [] + has_published = any( + (run.get('status') or '').lower() == 'published' for run in course_runs + ) + if not has_published: + logger.debug( + f"[get_content_metadata]: Excluding course {item.content_key} because it has no published runs." + ) + return has_published @action(detail=True) def get_content_metadata(self, request, traverse_pagination, content_keys_filter): @@ -243,7 +267,9 @@ def get_content_metadata(self, request, traverse_pagination, content_keys_filter # Only filter out archived courses if content_keys_filter is not provided, # to ensure active content is always returned if not content_keys_filter: - queryset = [item for item in queryset if self.is_active(item)] + # queryset = [item for item in queryset if self.is_active(item)] + # NEW: Remove courseruns from final output + queryset = [item for item in queryset if item.content_type == "course"] filtered_queryset_length = len(queryset) logger.debug(f'[get_content_metadata]: Filtered queryset length: {filtered_queryset_length}, ' f'{self.enterprise_catalog}') From 2c084927c9a39df708392fa09920a4a583004505 Mon Sep 17 00:00:00 2001 From: tpanda-sonata Date: Mon, 1 Dec 2025 13:40:10 +0000 Subject: [PATCH 2/2] ENT-11150:Code changes for ourses report to customer to build their LMS discovery mechanism --- ...enterprise_catalog_get_content_metadata.py | 27 +++---------------- 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/enterprise_catalog/apps/api/v1/views/enterprise_catalog_get_content_metadata.py b/enterprise_catalog/apps/api/v1/views/enterprise_catalog_get_content_metadata.py index c7b46f54..d05051d8 100644 --- a/enterprise_catalog/apps/api/v1/views/enterprise_catalog_get_content_metadata.py +++ b/enterprise_catalog/apps/api/v1/views/enterprise_catalog_get_content_metadata.py @@ -209,23 +209,6 @@ def get(self, request, **kwargs): return self.get_content_metadata(request, traverse_pagination, content_keys_filter) - # def is_active(self, item): - # """ - # Determines if a content item is active. - # Args: - # item (ContentMetadata): The content metadata item to check. - # Returns: - # bool: True if the item is active, False otherwise. - # For courses, checks if any course run is active. - # For other content types, always returns True. - # """ - # if item.content_type == 'course': - # active = is_any_course_run_active( - # item.json_metadata.get('course_runs', [])) - # if not active: - # logger.debug(f'[get_content_metadata]: Content item {item.content_key} is not active.') - # return active - # return True def is_active(self, item): """ Determines if a content item is active. @@ -235,12 +218,8 @@ def is_active(self, item): bool: True if the item is active, False otherwise. For courses, checks if any course run is active. For other content types, always returns True. - For courses, requires that the course has at least one published course run. - This prevents courses that only contain unsubmitted/draft runs from being - returned to enterprise customers. The serializer still uses - `is_any_course_run_active` to set the `active` field in the payload. - """ - if item.content_type == 'course': + """ + if item.content_type == 'course': course_runs = item.json_metadata.get('course_runs', []) or [] has_published = any( (run.get('status') or '').lower() == 'published' for run in course_runs @@ -265,7 +244,7 @@ def get_content_metadata(self, request, traverse_pagination, content_keys_filter logger.debug(f'[get_content_metadata]: Original queryset length: {len(queryset)}, {self.enterprise_catalog}') # Only filter out archived courses if content_keys_filter is not provided, - # to ensure active content is always returned + # to ensure active content is always ret if not content_keys_filter: # queryset = [item for item in queryset if self.is_active(item)] # NEW: Remove courseruns from final output