Skip to content

Commit

Permalink
Merge pull request #1803 from openedx/asheehan-edx/content-to-delete-…
Browse files Browse the repository at this point in the history
…cant-be-requested

fix: removing items to delete dependency on the catalog service
  • Loading branch information
alex-sheehan-edx authored Jul 20, 2023
2 parents 49b7b49 + 0f9f90b commit 08792b2
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion enterprise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
Your project description goes here.
"""

__version__ = "4.0.1"
__version__ = "4.0.2"

default_app_config = "enterprise.apps.EnterpriseConfig"
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
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
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 08792b2

Please sign in to comment.