Skip to content

Commit

Permalink
fix: removing items to delete dependency on the catalog service
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-sheehan-edx committed Jul 18, 2023
1 parent 30c55ca commit 690afd4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,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,
Expand All @@ -537,11 +536,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
Expand Down Expand Up @@ -582,6 +579,14 @@ def export(self, **kwargs):
# collections of ContentMetadataItemTransmission objects
return create_payload, update_payload, delete_payload

def _apply_delete_transformation(self, item):
"""
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 item

def _transform_exec_ed_content(self, content):
"""
Transform only executive education course type content to add executive education identifying tags to both the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 690afd4

Please sign in to comment.