-
Notifications
You must be signed in to change notification settings - Fork 19
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
Conversation
5643a4a
to
3ffc405
Compare
@@ -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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice refactor 👍
enterprise_catalog/apps/api/v2/tests/test_enterprise_catalog_views.py
Outdated
Show resolved
Hide resolved
3ffc405
to
6b261fa
Compare
[restricted_run], clear=True, | ||
) | ||
catalog.catalog_query.content_filter[RESTRICTED_RUNS_ALLOWED_KEY] = { | ||
content_one.content_key: [restricted_run.content_key], |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
enterprise-catalog/enterprise_catalog/apps/catalog/models.py
Lines 117 to 137 in 5425510
@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() | |
} |
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.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