Skip to content

Commit

Permalink
fix: don't directly tie restricted runs to catalog queries
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveagent57 committed Nov 13, 2024
1 parent 1c6fc4e commit 23caf6b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 0 additions & 2 deletions enterprise_catalog/apps/catalog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,8 +940,6 @@ def update_course_run_relationships(self):
# We use a set() here, with clear=True, to clear and then reset the related allowed runs
# for this restricted course. This is necessary in the case that a previously-allowed
# run becomes unassociated from the restricted course.
self.catalog_query.contentmetadata_set.set(restricted_runs, clear=True)
LOGGER.info('Updated restricted runs on catalog query of %s to %s', self, restricted_runs)
self.restricted_run_allowed_for_restricted_course.set(restricted_runs, clear=True)
LOGGER.info('Updated restricted runs of %s to %s', self, restricted_runs)
self.refresh_from_db()
Expand Down
12 changes: 12 additions & 0 deletions enterprise_catalog/apps/catalog/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,18 @@ def test_synchronize_restricted_content(self, mock_client):
'content_key',
)
)

# The catalog_query should not have any content metadata related directly
# to it via the "normal" content_metadata M2M relationship.
self.assertEqual(catalog_query.contentmetadata_set.all().count(), 0)

# But the catalog_query should have a direct restricted relationship with
# the restricted course.
self.assertEqual(
list(catalog_query.restricted_content_metadata.all()),
[restricted_course],
)

self.assertEqual(
[run.content_key for run in restricted_runs],
['course-v1:edX+course+run2', 'course-v1:edX+course+run3'],
Expand Down

0 comments on commit 23caf6b

Please sign in to comment.