Skip to content

Commit 6d40556

Browse files
kdmccormickmarslanabdulrauf
authored andcommitted
refactor: Upgrade to openedx-core 0.44.0 (for OEP-68) (openedx#38402)
This incorporates a major set of renamings and key semantic changes, agreed upon in OEP-68 [1] and released in openedx core v0.43.0 [2] [1] https://docs.openedx.org/projects/openedx-proposals/en/latest/best-practices/oep-0068-bp-content-identifiers.html [2] https://github.com/openedx/openedx-core/releases/tag/v0.43.0 Additionally, we now show `unknown / unknown` in the restore UI when a learning package's package_ref cannot be parsed as a library key. This is because we are no longer assuming any specific format for package_refs. In the future, we may want a more graceful way handling un-parseable package_refs, especially if we have learning packages of courses instead of libraries. Part of: openedx/openedx-core#322
1 parent 192ffc3 commit 6d40556

13 files changed

Lines changed: 582 additions & 0 deletions

File tree

cms/djangoapps/modulestore_migrator/tasks.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,12 +965,18 @@ def _migrate_component(
965965
if filename_no_ext not in olx:
966966
continue
967967
new_path = f"static/{filename}"
968+
<<<<<<< HEAD
968969
paths_to_media_ids[new_path] = media_pk
969970

970971
# Create the new component version for it
971972
component_version = libraries_api.set_library_block_olx(
972973
target_key, new_olx_str=olx, paths_to_media=paths_to_media_ids,
973974
)
975+
=======
976+
content_api.create_component_version_media(
977+
component_version.pk, media_pk, path=new_path
978+
)
979+
>>>>>>> 847aa95b85 (refactor: Upgrade to openedx-core 0.44.0 (for OEP-68) (#38402))
974980

975981
# Publish the component
976982
libraries_api.publish_component_changes(target_key, context.created_by)

openedx/core/djangoapps/content/search/tests/test_api.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,11 +946,18 @@ def test_delete_collection(self, mock_meilisearch) -> None:
946946
mock_meilisearch.return_value.index.reset_mock()
947947

948948
# Soft-delete the collection
949+
<<<<<<< HEAD
949950
with self.captureOnCommitCallbacks(execute=True):
950951
content_api.delete_collection(
951952
self.collection.learning_package_id,
952953
self.collection.collection_code,
953954
)
955+
=======
956+
content_api.delete_collection(
957+
self.collection.learning_package_id,
958+
self.collection.collection_code,
959+
)
960+
>>>>>>> 847aa95b85 (refactor: Upgrade to openedx-core 0.44.0 (for OEP-68) (#38402))
954961

955962
doc_problem_without_collection = {
956963
"id": self.doc_problem1["id"],
@@ -1004,12 +1011,20 @@ def test_delete_collection(self, mock_meilisearch) -> None:
10041011
mock_meilisearch.return_value.index.reset_mock()
10051012

10061013
# Hard-delete the collection
1014+
<<<<<<< HEAD
10071015
with self.captureOnCommitCallbacks(execute=True):
10081016
content_api.delete_collection(
10091017
self.collection.learning_package_id,
10101018
self.collection.collection_code,
10111019
hard_delete=True,
10121020
)
1021+
=======
1022+
content_api.delete_collection(
1023+
self.collection.learning_package_id,
1024+
self.collection.collection_code,
1025+
hard_delete=True,
1026+
)
1027+
>>>>>>> 847aa95b85 (refactor: Upgrade to openedx-core 0.44.0 (for OEP-68) (#38402))
10131028

10141029
# Should delete the collection document
10151030
mock_meilisearch.return_value.index.return_value.delete_document.assert_called_once_with(

openedx/core/djangoapps/content_libraries/api/blocks.py

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,15 @@ def _import_staged_block(
674674
data=file_data,
675675
created=now,
676676
)
677+
<<<<<<< HEAD
677678
paths_to_media[filename] = media.id
679+
=======
680+
content_api.create_component_version_media(
681+
component_version.pk,
682+
content.id,
683+
path=filename,
684+
)
685+
>>>>>>> 847aa95b85 (refactor: Upgrade to openedx-core 0.44.0 (for OEP-68) (#38402))
678686

679687
# This will create the first component version and set the OLX/title
680688
# appropriately. It will not publish. Once we get the newly created
@@ -897,21 +905,122 @@ def delete_library_block(
897905
)
898906
raise
899907

908+
<<<<<<< HEAD
909+
content_api.soft_delete_draft(component.id, deleted_by=user_id)
910+
911+
=======
912+
affected_collections = content_api.get_entity_collections(component.learning_package_id, component.entity_ref)
913+
affected_containers = get_containers_contains_item(usage_key)
914+
900915
content_api.soft_delete_draft(component.id, deleted_by=user_id)
901916

917+
send_block_deleted_signal()
918+
919+
# For each collection, trigger LIBRARY_COLLECTION_UPDATED signal and set background=True to trigger
920+
# collection indexing asynchronously.
921+
#
922+
# To delete the component on collections
923+
for collection in affected_collections:
924+
# .. event_implemented_name: LIBRARY_COLLECTION_UPDATED
925+
# .. event_type: org.openedx.content_authoring.content_library.collection.updated.v1
926+
LIBRARY_COLLECTION_UPDATED.send_event(
927+
library_collection=LibraryCollectionData(
928+
collection_key=library_collection_locator(
929+
library_key=library_key,
930+
collection_key=collection.collection_code,
931+
),
932+
background=True,
933+
)
934+
)
935+
936+
# For each container, trigger LIBRARY_CONTAINER_UPDATED signal and set background=True to trigger
937+
# container indexing asynchronously.
938+
#
939+
# To update the components count in containers
940+
for container in affected_containers:
941+
# .. event_implemented_name: LIBRARY_CONTAINER_UPDATED
942+
# .. event_type: org.openedx.content_authoring.content_library.container.updated.v1
943+
LIBRARY_CONTAINER_UPDATED.send_event(
944+
library_container=LibraryContainerData(
945+
container_key=container.container_key,
946+
background=True,
947+
)
948+
)
949+
950+
>>>>>>> 847aa95b85 (refactor: Upgrade to openedx-core 0.44.0 (for OEP-68) (#38402))
902951

903952
def restore_library_block(usage_key: LibraryUsageLocatorV2, user_id: int | None = None) -> None:
904953
"""
905954
Restore the specified library block.
906955
"""
907956
component = get_component_from_usage_key(usage_key)
957+
<<<<<<< HEAD
958+
=======
959+
library_key = usage_key.context_key
960+
affected_collections = content_api.get_entity_collections(component.learning_package_id, component.entity_ref)
961+
962+
>>>>>>> 847aa95b85 (refactor: Upgrade to openedx-core 0.44.0 (for OEP-68) (#38402))
908963
# Set draft version back to the latest available component version id.
909964
content_api.set_draft_version(
910965
component.id,
911966
component.versioning.latest.pk,
912967
set_by=user_id,
913968
)
914969

970+
<<<<<<< HEAD
971+
=======
972+
# .. event_implemented_name: LIBRARY_BLOCK_CREATED
973+
# .. event_type: org.openedx.content_authoring.library_block.created.v1
974+
LIBRARY_BLOCK_CREATED.send_event(
975+
library_block=LibraryBlockData(
976+
library_key=library_key,
977+
usage_key=usage_key
978+
)
979+
)
980+
981+
# Add tags and collections back to index
982+
# .. event_implemented_name: CONTENT_OBJECT_ASSOCIATIONS_CHANGED
983+
# .. event_type: org.openedx.content_authoring.content.object.associations.changed.v1
984+
CONTENT_OBJECT_ASSOCIATIONS_CHANGED.send_event(
985+
content_object=ContentObjectChangedData(
986+
object_id=str(usage_key),
987+
changes=["collections", "tags", "units"],
988+
),
989+
)
990+
991+
# For each collection, trigger LIBRARY_COLLECTION_UPDATED signal and set background=True to trigger
992+
# collection indexing asynchronously.
993+
#
994+
# To restore the component in the collections
995+
for collection in affected_collections:
996+
# .. event_implemented_name: LIBRARY_COLLECTION_UPDATED
997+
# .. event_type: org.openedx.content_authoring.content_library.collection.updated.v1
998+
LIBRARY_COLLECTION_UPDATED.send_event(
999+
library_collection=LibraryCollectionData(
1000+
collection_key=library_collection_locator(
1001+
library_key=library_key,
1002+
collection_key=collection.collection_code,
1003+
),
1004+
background=True,
1005+
)
1006+
)
1007+
1008+
# For each container, trigger LIBRARY_CONTAINER_UPDATED signal and set background=True to trigger
1009+
# container indexing asynchronously.
1010+
#
1011+
# To update the components count in containers
1012+
affected_containers = get_containers_contains_item(usage_key)
1013+
for container in affected_containers:
1014+
# .. event_implemented_name: LIBRARY_CONTAINER_UPDATED
1015+
# .. event_type: org.openedx.content_authoring.content_library.container.updated.v1
1016+
LIBRARY_CONTAINER_UPDATED.send_event(
1017+
library_container=LibraryContainerData(
1018+
container_key=container.container_key,
1019+
background=True,
1020+
)
1021+
)
1022+
1023+
>>>>>>> 847aa95b85 (refactor: Upgrade to openedx-core 0.44.0 (for OEP-68) (#38402))
9151024

9161025
def get_library_block_static_asset_files(usage_key: LibraryUsageLocatorV2) -> list[LibraryXBlockStaticFile]:
9171026
"""
@@ -1099,12 +1208,26 @@ def _create_component_for_block(
10991208
component_type = content_api.get_or_create_component_type(
11001209
"xblock.v1", usage_key.block_type
11011210
)
1211+
<<<<<<< HEAD
11021212
block_olx_media = content_api.get_or_create_text_media(
1213+
=======
1214+
component, component_version = content_api.create_component_and_version(
1215+
learning_package.id,
1216+
component_type=component_type,
1217+
component_code=usage_key.block_id,
1218+
title=display_name,
1219+
created=now,
1220+
created_by=user_id,
1221+
can_stand_alone=can_stand_alone,
1222+
)
1223+
content = content_api.get_or_create_text_media(
1224+
>>>>>>> 847aa95b85 (refactor: Upgrade to openedx-core 0.44.0 (for OEP-68) (#38402))
11031225
learning_package.id,
11041226
get_or_create_olx_media_type(usage_key.block_type).id,
11051227
text=xml_text,
11061228
created=now,
11071229
)
1230+
<<<<<<< HEAD
11081231
_component, component_version = content_api.create_component_and_version(
11091232
learning_package.id,
11101233
component_type=component_type,
@@ -1116,6 +1239,12 @@ def _create_component_for_block(
11161239
media={
11171240
'block.xml': block_olx_media
11181241
}
1242+
=======
1243+
content_api.create_component_version_media(
1244+
component_version.pk,
1245+
content.id,
1246+
path="block.xml",
1247+
>>>>>>> 847aa95b85 (refactor: Upgrade to openedx-core 0.44.0 (for OEP-68) (#38402))
11191248
)
11201249

11211250
return component_version

openedx/core/djangoapps/content_libraries/api/collections.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,24 @@ def set_library_item_collections(
220220
created_by=created_by,
221221
)
222222

223+
<<<<<<< HEAD
224+
=======
225+
# For each collection, trigger LIBRARY_COLLECTION_UPDATED signal and set background=True to trigger
226+
# collection indexing asynchronously.
227+
for collection in affected_collections:
228+
# .. event_implemented_name: LIBRARY_COLLECTION_UPDATED
229+
# .. event_type: org.openedx.content_authoring.content_library.collection.updated.v1
230+
LIBRARY_COLLECTION_UPDATED.send_event(
231+
library_collection=LibraryCollectionData(
232+
collection_key=library_collection_locator(
233+
library_key=library_key,
234+
collection_key=collection.collection_code,
235+
),
236+
background=True,
237+
)
238+
)
239+
240+
>>>>>>> 847aa95b85 (refactor: Upgrade to openedx-core 0.44.0 (for OEP-68) (#38402))
223241
return publishable_entity
224242

225243

0 commit comments

Comments
 (0)