Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: v2 catalog contains_content_items view #994

Merged
merged 1 commit into from
Nov 8, 2024

Conversation

iloveagent57
Copy link
Contributor

@iloveagent57 iloveagent57 commented Nov 6, 2024

  1. Set up restricted content metadata in a catalog as described here: feat: sync full metadata for restricted courses #985
  2. Observe that GET http://localhost:18160/api/v1/enterprise-catalogs/7467c9d2-433c-4f7e-ba2e-c5c7798527b2/contains_content_items/?course_run_ids=course-v1%3AedX%2BDemoX%2Brestricted_run does not contain your restricted run.
  3. Observe that the v2 endpoint http://localhost:18160/api/v2/enterprise-catalogs/7467c9d2-433c-4f7e-ba2e-c5c7798527b2/contains_content_items/?course_run_ids=course-v1%3AedX%2BDemoX%2Brestricted_run does contain your restricted content.

ENT-9408

Post-review

  • Squash commits into discrete sets of changes
  • Ensure that once the changes have been deployed to stage, prod is manually deployed

@iloveagent57 iloveagent57 force-pushed the aed/v2-catalog-contains branch from 5643a4a to 3ffc405 Compare November 6, 2024 19:39
@@ -41,6 +41,14 @@ def get_permission_object(self):
return str(enterprise_catalog.enterprise_uuid)
return None

def catalog_contains_content_items(self, content_keys):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice refactor 👍

@iloveagent57 iloveagent57 force-pushed the aed/v2-catalog-contains branch from 3ffc405 to 6b261fa Compare November 7, 2024 15:40
[restricted_run], clear=True,
)
catalog.catalog_query.content_filter[RESTRICTED_RUNS_ALLOWED_KEY] = {
content_one.content_key: [restricted_run.content_key],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the top-level key under the restricted_runs_allowed key should actually be an aggregation key, which means you should prefix this with "course:". It's merely a formality for this test suite, but I think important for people who might ever need to touch this test or refer to it as a code reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can actually be a regular course key or an aggregation key, the code is flexible about it:

@cached_property
def restricted_runs_allowed(self):
"""
Return a dict of restricted course <-> run mappings by
course key, e.g.
```
"edX+FUN": [
"course-v1:edX+FUN+3T2024"
]
```
"""
mapping = self.content_filter.get(RESTRICTED_RUNS_ALLOWED_KEY) # pylint: disable=no-member
if not mapping:
return None
if not isinstance(mapping, dict):
LOGGER.error('%s restricted runs value is not a dict', self)
return None
return {
course_key.removeprefix(AGGREGATION_KEY_PREFIX): course_run_list
for course_key, course_run_list in mapping.items()
}

@iloveagent57 iloveagent57 merged commit 624a6fb into master Nov 8, 2024
4 checks passed
@iloveagent57 iloveagent57 deleted the aed/v2-catalog-contains branch November 8, 2024 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants