Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions openedx/core/djangoapps/content/search/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ def update_library_components_collections(

Because there may be a lot of components, we send these updates to Meilisearch in batches.
"""
library_key = collection_key.library_key
library_key = collection_key.lib_key
library = lib_api.get_library(library_key)
components = authoring_api.get_collection_components(
library.learning_package_id,
Expand Down Expand Up @@ -795,7 +795,7 @@ def update_library_containers_collections(

Because there may be a lot of containers, we send these updates to Meilisearch in batches.
"""
library_key = collection_key.library_key
library_key = collection_key.lib_key
library = lib_api.get_library(library_key)
containers = authoring_api.get_collection_containers(
library.learning_package_id,
Expand Down
14 changes: 7 additions & 7 deletions openedx/core/djangoapps/content/search/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from django.core.exceptions import ObjectDoesNotExist
from django.utils.text import slugify
from opaque_keys.edx.keys import LearningContextKey, UsageKey, OpaqueKey
from opaque_keys.edx.keys import ContainerKey, LearningContextKey, UsageKey, OpaqueKey
from opaque_keys.edx.locator import LibraryCollectionLocator, LibraryContainerLocator
from openedx_learning.api import authoring as authoring_api
from openedx_learning.api.authoring_models import Collection
Expand Down Expand Up @@ -523,7 +523,7 @@ def searchable_doc_for_collection(
).count()

doc.update({
Fields.context_key: str(collection_key.library_key),
Fields.context_key: str(collection_key.context_key),
Fields.org: str(collection_key.org),
Fields.usage_key: str(collection_key),
Fields.block_id: collection.key,
Expand All @@ -536,7 +536,7 @@ def searchable_doc_for_collection(
Fields.published: {
Fields.published_num_children: published_num_children,
},
Fields.access_id: _meili_access_id_from_context_key(collection_key.library_key),
Fields.access_id: _meili_access_id_from_context_key(collection_key.context_key),
Fields.breadcrumbs: [{"display_name": collection.learning_package.title}],
})

Expand All @@ -549,7 +549,7 @@ def searchable_doc_for_collection(


def searchable_doc_for_container(
container_key: LibraryContainerLocator,
container_key: ContainerKey,
) -> dict:
"""
Generate a dictionary document suitable for ingestion into a search engine
Expand All @@ -562,15 +562,15 @@ def searchable_doc_for_container(
"""
doc = {
Fields.id: meili_id_from_opaque_key(container_key),
Fields.context_key: str(container_key.library_key),
Fields.context_key: str(container_key.context_key),
Fields.org: str(container_key.org),
# In the future, this may be either course_container or library_container
Fields.type: DocType.library_container,
# To check if it is "unit", "section", "subsection", etc..
Fields.block_type: container_key.container_type,
Fields.usage_key: str(container_key), # Field name isn't exact but this is the closest match
Fields.block_id: container_key.container_id, # Field name isn't exact but this is the closest match
Fields.access_id: _meili_access_id_from_context_key(container_key.library_key),
Fields.access_id: _meili_access_id_from_context_key(container_key.context_key),
Fields.publish_status: PublishStatus.never,
Fields.last_published: None,
}
Expand All @@ -596,7 +596,7 @@ def searchable_doc_for_container(
Fields.publish_status: publish_status,
Fields.last_published: container.last_published.timestamp() if container.last_published else None,
})
library = lib_api.get_library(container_key.library_key)
library = lib_api.get_library(container_key.context_key)
if library:
doc[Fields.breadcrumbs] = [{"display_name": library.title}]

Expand Down
8 changes: 4 additions & 4 deletions openedx/core/djangoapps/content/search/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def update_library_collection_index_doc(collection_key_str: str) -> None:
Celery task to update the content index document for a library collection
"""
collection_key = LibraryCollectionLocator.from_string(collection_key_str)
library_key = collection_key.library_key
library_key = collection_key.lib_key

log.info("Updating content index documents for collection %s in library%s", collection_key, library_key)

Expand All @@ -112,7 +112,7 @@ def update_library_components_collections(collection_key_str: str) -> None:
Celery task to update the "collections" field for components in the given content library collection.
"""
collection_key = LibraryCollectionLocator.from_string(collection_key_str)
library_key = collection_key.library_key
library_key = collection_key.lib_key

log.info("Updating document.collections for library %s collection %s components", library_key, collection_key)

Expand All @@ -126,7 +126,7 @@ def update_library_containers_collections(collection_key_str: str) -> None:
Celery task to update the "collections" field for containers in the given content library collection.
"""
collection_key = LibraryCollectionLocator.from_string(collection_key_str)
library_key = collection_key.library_key
library_key = collection_key.lib_key

log.info("Updating document.collections for library %s collection %s containers", library_key, collection_key)

Expand All @@ -140,7 +140,7 @@ def update_library_container_index_doc(container_key_str: str) -> None:
Celery task to update the content index document for a library container
"""
container_key = LibraryContainerLocator.from_string(container_key_str)
library_key = container_key.library_key
library_key = container_key.lib_key

log.info("Updating content index documents for container %s in library%s", container_key, library_key)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def get_library_collection_from_locator(
"""
Return a Collection using the LibraryCollectionLocator
"""
library_key = collection_locator.library_key
library_key = collection_locator.lib_key
collection_key = collection_locator.collection_id
content_library = ContentLibrary.objects.get_by_key(library_key) # type: ignore[attr-defined]
assert content_library.learning_package_id is not None # shouldn't happen but it's technically possible.
Expand Down
18 changes: 9 additions & 9 deletions openedx/core/djangoapps/content_libraries/api/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def get_container_from_key(container_key: LibraryContainerLocator, isDeleted=Fal
Raises ContentLibraryContainerNotFound if no container found, or if the container has been soft deleted.
"""
assert isinstance(container_key, LibraryContainerLocator)
content_library = ContentLibrary.objects.get_by_key(container_key.library_key)
content_library = ContentLibrary.objects.get_by_key(container_key.lib_key)
learning_package = content_library.learning_package
assert learning_package is not None
container = authoring_api.get_container_by_key(
Expand All @@ -204,7 +204,7 @@ def get_container(container_key: LibraryContainerLocator, include_collections=Fa
else:
associated_collections = None
container_meta = ContainerMetadata.from_container(
container_key.library_key,
container_key.lib_key,
container,
associated_collections=associated_collections,
)
Expand Down Expand Up @@ -268,7 +268,7 @@ def update_container(
Update a container (e.g. a Unit) title.
"""
container = get_container_from_key(container_key)
library_key = container_key.library_key
library_key = container_key.lib_key

assert container.unit
unit_version = authoring_api.create_next_unit_version(
Expand All @@ -295,7 +295,7 @@ def delete_container(

No-op if container doesn't exist or has already been soft-deleted.
"""
library_key = container_key.library_key
library_key = container_key.lib_key
container = get_container_from_key(container_key)

affected_collections = authoring_api.get_entity_collections(
Expand Down Expand Up @@ -330,7 +330,7 @@ def restore_container(container_key: LibraryContainerLocator) -> None:
"""
Restore the specified library container.
"""
library_key = container_key.library_key
library_key = container_key.lib_key
container = get_container_from_key(container_key, isDeleted=True)

affected_collections = authoring_api.get_entity_collections(
Expand Down Expand Up @@ -380,13 +380,13 @@ def get_container_children(
if container_key.container_type == ContainerType.Unit.value:
child_components = authoring_api.get_components_in_unit(container.unit, published=published)
return [LibraryXBlockMetadata.from_component(
container_key.library_key,
container_key.lib_key,
entry.component
) for entry in child_components]
else:
child_entities = authoring_api.get_entities_in_container(container, published=published)
return [ContainerMetadata.from_container(
container_key.library_key,
container_key.lib_key,
entry.entity
) for entry in child_entities]

Expand All @@ -411,7 +411,7 @@ def update_container_children(
"""
Adds children components or containers to given container.
"""
library_key = container_key.library_key
library_key = container_key.lib_key
container_type = container_key.container_type
container = get_container_from_key(container_key)
match container_type:
Expand Down Expand Up @@ -459,7 +459,7 @@ def publish_container_changes(container_key: LibraryContainerLocator, user_id: i
containers/blocks.
"""
container = get_container_from_key(container_key)
library_key = container_key.library_key
library_key = container_key.lib_key
content_library = ContentLibrary.objects.get_by_key(library_key) # type: ignore[attr-defined]
learning_package = content_library.learning_package
assert learning_package
Expand Down
18 changes: 9 additions & 9 deletions openedx/core/djangoapps/content_libraries/rest_api/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def get(self, request, container_key: LibraryContainerLocator):
Get information about a container
"""
api.require_permission_for_library_key(
container_key.library_key,
container_key.lib_key,
request.user,
permissions.CAN_VIEW_THIS_CONTENT_LIBRARY,
)
Expand All @@ -94,7 +94,7 @@ def patch(self, request, container_key: LibraryContainerLocator):
Update a Container.
"""
api.require_permission_for_library_key(
container_key.library_key,
container_key.lib_key,
request.user,
permissions.CAN_EDIT_THIS_CONTENT_LIBRARY,
)
Expand All @@ -115,7 +115,7 @@ def delete(self, request, container_key: LibraryContainerLocator):
Delete a Container (soft delete).
"""
api.require_permission_for_library_key(
container_key.library_key,
container_key.lib_key,
request.user,
permissions.CAN_EDIT_THIS_CONTENT_LIBRARY,
)
Expand Down Expand Up @@ -180,7 +180,7 @@ def get(self, request, container_key: LibraryContainerLocator):
"""
published = request.GET.get('published', False)
api.require_permission_for_library_key(
container_key.library_key,
container_key.lib_key,
request.user,
permissions.CAN_VIEW_THIS_CONTENT_LIBRARY,
)
Expand All @@ -201,7 +201,7 @@ def _update_component_children(
Helper function to update children in container.
"""
api.require_permission_for_library_key(
container_key.library_key,
container_key.lib_key,
request.user,
permissions.CAN_EDIT_THIS_CONTENT_LIBRARY,
)
Expand Down Expand Up @@ -288,7 +288,7 @@ def post(self, request, container_key: LibraryContainerLocator) -> Response:
Restores a soft-deleted library container
"""
api.require_permission_for_library_key(
container_key.library_key,
container_key.lib_key,
request.user,
permissions.CAN_EDIT_THIS_CONTENT_LIBRARY,
)
Expand All @@ -310,7 +310,7 @@ def patch(self, request: RestRequest, container_key: LibraryContainerLocator) ->
Collection and Components must all be part of the given library/learning package.
"""
content_library = api.require_permission_for_library_key(
container_key.library_key,
container_key.lib_key,
request.user,
permissions.CAN_EDIT_THIS_CONTENT_LIBRARY
)
Expand All @@ -320,7 +320,7 @@ def patch(self, request: RestRequest, container_key: LibraryContainerLocator) ->

collection_keys = serializer.validated_data['collection_keys']
api.set_library_item_collections(
library_key=container_key.library_key,
library_key=container_key.lib_key,
publishable_entity=container.publishable_entity,
collection_keys=collection_keys,
created_by=request.user.id,
Expand All @@ -342,7 +342,7 @@ def post(self, request: RestRequest, container_key: LibraryContainerLocator) ->
Publish the container and its children
"""
api.require_permission_for_library_key(
container_key.library_key,
container_key.lib_key,
request.user,
permissions.CAN_EDIT_THIS_CONTENT_LIBRARY,
)
Expand Down
21 changes: 10 additions & 11 deletions openedx/core/djangoapps/content_libraries/rest_api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
from rest_framework.exceptions import ValidationError

from opaque_keys import OpaqueKey
from opaque_keys.edx.keys import UsageKeyV2
from opaque_keys.edx.locator import LibraryContainerLocator
from opaque_keys.edx.locator import LibraryContainerLocator, LibraryUsageLocatorV2
from opaque_keys import InvalidKeyError

from openedx_learning.api.authoring_models import Collection
Expand Down Expand Up @@ -319,22 +318,22 @@ class ContentLibraryCollectionUpdateSerializer(serializers.Serializer):

class UsageKeyV2Serializer(serializers.BaseSerializer):
"""
Serializes a UsageKeyV2.
Serializes a library Component (XBlock) key.
"""
def to_representation(self, value: UsageKeyV2) -> str:
def to_representation(self, value: LibraryUsageLocatorV2) -> str:
"""
Returns the UsageKeyV2 value as a string.
Returns the LibraryUsageLocatorV2 value as a string.
"""
return str(value)

def to_internal_value(self, value: str) -> UsageKeyV2:
def to_internal_value(self, value: str) -> LibraryUsageLocatorV2:
"""
Returns a UsageKeyV2 from the string value.
Returns a LibraryUsageLocatorV2 from the string value.

Raises ValidationError if invalid UsageKeyV2.
Raises ValidationError if invalid LibraryUsageLocatorV2.
"""
try:
return UsageKeyV2.from_string(value)
return LibraryUsageLocatorV2.from_string(value)
except InvalidKeyError as err:
raise ValidationError from err

Expand All @@ -359,12 +358,12 @@ def to_representation(self, value: OpaqueKey) -> str:

def to_internal_value(self, value: str) -> OpaqueKey:
"""
Returns a UsageKeyV2 or a LibraryContainerLocator from the string value.
Returns a LibraryUsageLocatorV2 or a LibraryContainerLocator from the string value.

Raises ValidationError if invalid UsageKeyV2 or LibraryContainerLocator.
"""
try:
return UsageKeyV2.from_string(value)
return LibraryUsageLocatorV2.from_string(value)
except InvalidKeyError:
try:
return LibraryContainerLocator.from_string(value)
Expand Down
7 changes: 3 additions & 4 deletions openedx/core/djangoapps/content_tagging/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
from itertools import groupby
import csv
from typing import Iterator
from opaque_keys.edx.keys import UsageKey
from opaque_keys.edx.keys import CourseKey, CollectionKey, ContainerKey, UsageKey

import openedx_tagging.core.tagging.api as oel_tagging
from django.db.models import Exists, OuterRef, Q, QuerySet
from django.utils.timezone import now
from opaque_keys.edx.keys import CourseKey, LibraryItemKey
from opaque_keys.edx.locator import LibraryLocatorV2
from openedx_tagging.core.tagging.models import ObjectTag, Taxonomy
from openedx_tagging.core.tagging.models.utils import TAGS_CSV_SEPARATOR
Expand Down Expand Up @@ -230,8 +229,8 @@ def generate_csv_rows(object_id, buffer) -> Iterator[str]:
"""
content_key = get_content_key_from_string(object_id)

if isinstance(content_key, (UsageKey, LibraryItemKey)):
raise ValueError("The object_id must be a CourseKey or a LibraryLocatorV2.")
if isinstance(content_key, (UsageKey, CollectionKey, ContainerKey)):
raise ValueError("The object_id must be a component, collection, or container.")

all_object_tags, taxonomies = get_all_object_tags(content_key)
tagged_content = build_object_tree_with_objecttags(content_key, all_object_tags)
Expand Down
4 changes: 2 additions & 2 deletions openedx/core/djangoapps/content_tagging/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

from typing import Dict, List, Union

from opaque_keys.edx.keys import CourseKey, UsageKey, LibraryItemKey
from opaque_keys.edx.keys import CourseKey, UsageKey, CollectionKey, ContainerKey
from opaque_keys.edx.locator import LibraryLocatorV2
from openedx_tagging.core.tagging.models import Taxonomy

ContentKey = Union[LibraryLocatorV2, CourseKey, UsageKey, LibraryItemKey]
ContentKey = Union[LibraryLocatorV2, CourseKey, UsageKey, CollectionKey, ContainerKey]
ContextKey = Union[LibraryLocatorV2, CourseKey]

TagValuesByTaxonomyIdDict = Dict[int, List[str]]
Expand Down
Loading