From e26a3fb7e67817dfa8409dfac237fa090ad0e314 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B4mulo=20Penido?= Date: Wed, 24 Dec 2025 15:25:09 -0300 Subject: [PATCH] fix: add course name on collection description on import (#37817) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Chris Chávez --- cms/djangoapps/modulestore_migrator/tasks.py | 17 +++++++++++--- .../modulestore_migrator/tests/test_tasks.py | 22 ++++++++++++++++++- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/cms/djangoapps/modulestore_migrator/tasks.py b/cms/djangoapps/modulestore_migrator/tasks.py index e0b0b0fe2e..fe1182716f 100644 --- a/cms/djangoapps/modulestore_migrator/tasks.py +++ b/cms/djangoapps/modulestore_migrator/tasks.py @@ -417,7 +417,11 @@ def _populate_collection(user_id: int, migration: models.ModulestoreMigration) - log.warning("No target entities found to add to collection") -def _create_collection(library_key: LibraryLocatorV2, title: str) -> Collection: +def _create_collection( + library_key: LibraryLocatorV2, + title: str, + course_name: str | None = None, +) -> Collection: """ Creates a collection in the given library @@ -428,7 +432,10 @@ def _create_collection(library_key: LibraryLocatorV2, title: str) -> Collection: collection: Collection | None = None attempt = 0 created_at = strftime_localized(datetime.now(timezone.utc), DEFAULT_DATE_TIME_FORMAT) - description = f"{_('This collection contains content migrated from a legacy library on')}: {created_at}" + if course_name: + description = f"{_('This collection contains content imported from the course')} {course_name} on: {created_at}" + else: + description = f"{_('This collection contains content migrated from a legacy library on')}: {created_at}" while not collection: modified_key = key if attempt == 0 else key + '-' + str(attempt) try: @@ -694,7 +701,11 @@ def bulk_migrate_from_modulestore( pass migration.target_collection = ( existing_collection_to_use or - _create_collection(library_key=target_library_locator, title=legacy_root_list[i].display_name) + _create_collection( + library_key=target_library_locator, + title=legacy_root_list[i].display_name, + course_name=legacy_root_list[i].display_name if source_data.source.key.is_course else None, + ) ) _populate_collection(user_id, migration) models.ModulestoreMigration.objects.bulk_update( diff --git a/cms/djangoapps/modulestore_migrator/tests/test_tasks.py b/cms/djangoapps/modulestore_migrator/tests/test_tasks.py index 02ac7c6f2b..7bb9b7fcf5 100644 --- a/cms/djangoapps/modulestore_migrator/tests/test_tasks.py +++ b/cms/djangoapps/modulestore_migrator/tests/test_tasks.py @@ -1118,11 +1118,12 @@ class TestMigrateFromModulestore(ModuleStoreTestCase): """ source = ModulestoreSource.objects.create(key=self.legacy_library.location.library_key) source_2 = ModulestoreSource.objects.create(key=self.legacy_library_2.location.library_key) + source_3 = ModulestoreSource.objects.create(key=self.course.id) task = bulk_migrate_from_modulestore.apply_async( kwargs={ "user_id": self.user.id, - "sources_pks": [source.id, source_2.id], + "sources_pks": [source.id, source_2.id, source_3.id], "target_library_key": str(self.lib_key), "target_collection_pks": [], "create_collections": True, @@ -1142,6 +1143,10 @@ class TestMigrateFromModulestore(ModuleStoreTestCase): self.assertEqual(migration.composition_level, CompositionLevel.Unit.value) self.assertEqual(migration.repeat_handling_strategy, RepeatHandlingStrategy.Skip.value) self.assertEqual(migration.target_collection.title, self.legacy_library.display_name) + self.assertIn( + "This collection contains content migrated from a legacy library on:", + migration.target_collection.description, + ) migration_2 = ModulestoreMigration.objects.get( source=source_2, target=self.learning_package @@ -1149,6 +1154,21 @@ class TestMigrateFromModulestore(ModuleStoreTestCase): self.assertEqual(migration_2.composition_level, CompositionLevel.Unit.value) self.assertEqual(migration_2.repeat_handling_strategy, RepeatHandlingStrategy.Skip.value) self.assertEqual(migration_2.target_collection.title, self.legacy_library_2.display_name) + self.assertIn( + "This collection contains content migrated from a legacy library on:", + migration_2.target_collection.description, + ) + + migration_3 = ModulestoreMigration.objects.get( + source=source_3, target=self.learning_package + ) + self.assertEqual(migration_3.composition_level, CompositionLevel.Unit.value) + self.assertEqual(migration_3.repeat_handling_strategy, RepeatHandlingStrategy.Skip.value) + self.assertEqual(migration_3.target_collection.title, self.course.display_name) + self.assertIn( + f"This collection contains content imported from the course {self.course.display_name} on:", + migration_3.target_collection.description, + ) @ddt.data( RepeatHandlingStrategy.Skip,