diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 725408c523..8625abf1cb 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -15,6 +15,10 @@ Change Log Unreleased ---------- +[4.0.2] +------- +fix: removing items to delete dependency on the catalog service + [4.0.1] -------- chore: upgrade course_enrollment from audit to verified diff --git a/enterprise/__init__.py b/enterprise/__init__.py index fcd8c10961..a49b695a3a 100644 --- a/enterprise/__init__.py +++ b/enterprise/__init__.py @@ -2,6 +2,6 @@ Your project description goes here. """ -__version__ = "4.0.1" +__version__ = "4.0.2" default_app_config = "enterprise.apps.EnterpriseConfig" diff --git a/integrated_channels/integrated_channel/exporters/content_metadata.py b/integrated_channels/integrated_channel/exporters/content_metadata.py index 2337994da3..e7bb3595ef 100644 --- a/integrated_channels/integrated_channel/exporters/content_metadata.py +++ b/integrated_channels/integrated_channel/exporters/content_metadata.py @@ -18,7 +18,6 @@ EXEC_ED_CONTENT_DESCRIPTION_TAG, EXEC_ED_COURSE_TYPE, IC_CREATE_ACTION, - IC_DELETE_ACTION, IC_UPDATE_ACTION, TRANSMISSION_MARK_CREATE, ) @@ -511,8 +510,7 @@ def export(self, **kwargs): self._log_info(f'diff items_to_update: {items_to_update}') self._log_info(f'diff items_to_delete: {items_to_delete}') - content_keys_filter = list(items_to_create.keys()) + list(items_to_update.keys()) + \ - list(items_to_delete.keys()) + content_keys_filter = list(items_to_create.keys()) + list(items_to_update.keys()) if content_keys_filter: content_metadata_items = self.enterprise_catalog_api.get_content_metadata( self.enterprise_customer, @@ -537,11 +535,9 @@ def export(self, **kwargs): update_payload[key] = item for key, item in items_to_delete.items(): - self._sanitize_and_set_item_metadata(item, key_to_content_metadata_mapping[key], IC_DELETE_ACTION) - # Sanity check - item.enterprise_customer_catalog_uuid = enterprise_customer_catalog.uuid + metadata = self._apply_delete_transformation(item.channel_metadata) + item.channel_metadata = metadata item.save() - delete_payload[key] = item # If we're not at the max payload count, we can check for orphaned content and shove it in the delete payload @@ -582,6 +578,14 @@ def export(self, **kwargs): # collections of ContentMetadataItemTransmission objects return create_payload, update_payload, delete_payload + def _apply_delete_transformation(self, metadata): + """ + Base implementation of a delete transformation method. This method is designed to be a NOOP as it is up to the + individual channel to define specific transformations for the channel metadata payload of transmissions + intended for deletion. + """ + return metadata + def _transform_exec_ed_content(self, content): """ Transform only executive education course type content to add executive education identifying tags to both the diff --git a/integrated_channels/sap_success_factors/exporters/content_metadata.py b/integrated_channels/sap_success_factors/exporters/content_metadata.py index ba9897073e..226c704b0e 100644 --- a/integrated_channels/sap_success_factors/exporters/content_metadata.py +++ b/integrated_channels/sap_success_factors/exporters/content_metadata.py @@ -47,6 +47,21 @@ class SapSuccessFactorsContentMetadataExporter(ContentMetadataExporter): 'price': 'price', } + def _apply_delete_transformation(self, metadata): + """ + Specific transformations required for "deleting" a course on a SAP external service. + """ + # Applying the metadata payload update to "delete" the course on SAP instances + metadata['status'] = 'INACTIVE' + + # Sanity check as we've seen issues with schedule structure + metadata_schedule = metadata.get('schedule') + if metadata_schedule: + schedule = metadata_schedule[0] + if not schedule.get('startDate') or not schedule.get('endDate'): + metadata['schedule'] = [] + return metadata + def transform_provider_id(self, content_metadata_item): # pylint: disable=unused-argument """ Return the provider ID from the integrated channel configuration. diff --git a/tests/test_integrated_channels/test_integrated_channel/test_exporters/test_content_metadata.py b/tests/test_integrated_channels/test_integrated_channel/test_exporters/test_content_metadata.py index 315cef0570..aad438caf4 100644 --- a/tests/test_integrated_channels/test_integrated_channel/test_exporters/test_content_metadata.py +++ b/tests/test_integrated_channels/test_integrated_channel/test_exporters/test_content_metadata.py @@ -477,8 +477,8 @@ def test_content_exporter_truncation_bug_export(self, mock_api_client): assert delete_payload.get(FAKE_COURSE_RUN2['key']) == past_transmission_to_delete # get_catalog_diff is called once per customer catalog assert mock_api_client.return_value.get_catalog_diff.call_count == 1 - # get_content_metadata is called once for the single item to delete - assert mock_api_client.return_value.get_content_metadata.call_count == 1 + # get_content_metadata isn't called for the item to delete + assert mock_api_client.return_value.get_content_metadata.call_count == 0 @mock.patch('integrated_channels.integrated_channel.exporters.content_metadata.EnterpriseCatalogApiClient') def test_content_exporter_update_not_needed_export(self, mock_api_client):