Skip to content

Commit

Permalink
feat: Add api functions to update tags in collections
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisChV committed Sep 13, 2024
1 parent 5a34dbd commit f0d83ff
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
11 changes: 11 additions & 0 deletions openedx/core/djangoapps/content/search/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,17 @@ def upsert_block_collections_index_docs(usage_key: UsageKey):
_update_index_docs([doc])


def upsert_collection_tags_index_docs(collection_usage_key: LibraryLocatorV2):
"""
Updates the tags data in documents for the given library collection
"""
collection = lib_api.get_library_collection_from_usage_key(collection_usage_key)

doc = {Fields.id: collection.id}
doc.update(collection_usage_key.library_key, collection)
_update_index_docs([doc])


def _get_user_orgs(request: Request) -> list[str]:
"""
Get the org.short_names for the organizations that the requesting user has OrgStaffRole or OrgInstructorRole.
Expand Down
19 changes: 19 additions & 0 deletions openedx/core/djangoapps/content_libraries/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,25 @@ def get_library_collection_usage_key(
return LibraryCollectionLocator(library_key, collection_key)


def get_library_collection_from_usage_key(
collection_usage_key: LibraryCollectionLocator,
) -> Collection:
"""
Return a Collection ussing the LibraryCollectionLocator
"""

library_key = collection_usage_key.library_key
collection_key = collection_usage_key.collection_id
content_library = ContentLibrary.objects.get_by_key(library_key) # type: ignore[attr-defined]
try:
return authoring_api.get(
content_library.learning_package_id,
collection_key,
)
except Collection.DoesNotExist as exc:
raise ContentLibraryCollectionNotFound from exc


# V1/V2 Compatibility Helpers
# (Should be removed as part of
# https://github.com/openedx/edx-platform/issues/32457)
Expand Down

0 comments on commit f0d83ff

Please sign in to comment.