diff --git a/cms/djangoapps/contentstore/tests/test_contentstore.py b/cms/djangoapps/contentstore/tests/test_contentstore.py index 300e338cbe..8c321f03dd 100644 --- a/cms/djangoapps/contentstore/tests/test_contentstore.py +++ b/cms/djangoapps/contentstore/tests/test_contentstore.py @@ -1761,8 +1761,27 @@ class ContentStoreTest(ModuleStoreTestCase): self.assertEquals(course_module.pdf_textbooks[0]["chapters"][0]["url"], '/c4x/MITx/999/asset/Chapter1.pdf') self.assertEquals(course_module.pdf_textbooks[0]["chapters"][1]["url"], '/c4x/MITx/999/asset/Chapter2.pdf') - # check that URL slug got updated to new course slug - self.assertEquals(course_module.wiki_slug, '999') + def test_import_into_new_course_id_wiki_slug_renamespacing(self): + module_store = modulestore('direct') + target_location = Location('i4x', 'MITx', '999', 'course', '2013_Spring') + course_data = { + 'org': target_location.org, + 'number': target_location.course, + 'display_name': 'Robot Super Course', + 'run': target_location.name + } + target_course_id = '{0}/{1}/{2}'.format(target_location.org, target_location.course, target_location.name) + _create_course(self, course_data) + + # Import a course with wiki_slug == location.course + import_from_xml(module_store, 'common/test/data/', ['toy'], target_location_namespace=target_location) + course_module = module_store.get_instance(target_location.course_id, target_location) + self.assertEquals(course_module.wiki_slug, 'MITx.999.2013_Spring') + + # Now try importing a course with wiki_slug == '{0}{1}{2}'.format(location.org, location.course, location.name) + import_from_xml(module_store, 'common/test/data/', ['two_toys'], target_location_namespace=target_location) + course_module = module_store.get_instance(target_course_id, target_location) + self.assertEquals(course_module.wiki_slug, 'MITx.999.2013_Spring') def test_import_metadata_with_attempts_empty_string(self): module_store = modulestore('direct') @@ -1915,6 +1934,14 @@ class ContentStoreTest(ModuleStoreTestCase): _test_no_locations(self, resp) return resp + def test_wiki_slug(self): + """When creating a course a unique wiki_slug should be set.""" + + course_location = Location(['i4x', 'MITx', '999', 'course', '2013_Spring']) + _create_course(self, self.course_data) + course_module = modulestore('direct').get_item(course_location) + self.assertEquals(course_module.wiki_slug, 'MITx.999.2013_Spring') + @override_settings(MODULESTORE=TEST_MODULESTORE) class MetadataSaveTestCase(ModuleStoreTestCase): diff --git a/cms/djangoapps/contentstore/views/course.py b/cms/djangoapps/contentstore/views/course.py index 138e323d1c..af7f1324de 100644 --- a/cms/djangoapps/contentstore/views/course.py +++ b/cms/djangoapps/contentstore/views/course.py @@ -376,8 +376,15 @@ def create_new_course(request): metadata = {} else: metadata = {'display_name': display_name} + + # Set a unique wiki_slug for newly created courses. To maintain active wiki_slugs for existing xml courses this + # cannot be changed in CourseDescriptor. + wiki_slug = "{0}.{1}.{2}".format(dest_location.org, dest_location.course, dest_location.name) + definition_data = {'wiki_slug': wiki_slug} + modulestore('direct').create_and_save_xmodule( dest_location, + definition_data=definition_data, metadata=metadata ) new_course = modulestore('direct').get_item(dest_location) diff --git a/common/lib/xmodule/xmodule/modulestore/xml_importer.py b/common/lib/xmodule/xmodule/modulestore/xml_importer.py index 61ca0b62f1..cd82f97aec 100644 --- a/common/lib/xmodule/xmodule/modulestore/xml_importer.py +++ b/common/lib/xmodule/xmodule/modulestore/xml_importer.py @@ -514,11 +514,20 @@ def remap_namespace(module, target_location_namespace): chapter['url'], target_location_namespace ) - # if there is a wiki_slug which is the same as the original location - # (aka default value), then remap that so the wiki doesn't point to - # the old Wiki. - if module.wiki_slug == original_location.course: - module.wiki_slug = target_location_namespace.course + # Original wiki_slugs had value location.course. To make them unique this was changed to 'org.course.name'. + # If the wiki_slug is equal to either of these default values then remap that so that the wiki does not point + # to the old wiki. + original_unique_wiki_slug = '{0}.{1}.{2}'.format( + original_location.org, + original_location.course, + original_location.name + ) + if module.wiki_slug == original_unique_wiki_slug or module.wiki_slug == original_location.course: + module.wiki_slug = '{0}.{1}.{2}'.format( + target_location_namespace.org, + target_location_namespace.course, + target_location_namespace.name, + ) module.save() diff --git a/common/test/data/two_toys/course/TT_2012_Fall.xml b/common/test/data/two_toys/course/TT_2012_Fall.xml index b6dbd48b4c..107612deec 100644 --- a/common/test/data/two_toys/course/TT_2012_Fall.xml +++ b/common/test/data/two_toys/course/TT_2012_Fall.xml @@ -1,3 +1,4 @@ +