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
20 changes: 6 additions & 14 deletions common/lib/xmodule/xmodule/modulestore/split_mongo/split_draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,20 +416,12 @@ def import_xblock(self, user_id, course_key, block_type, block_id, fields=None,
new_usage_key = course_key.make_usage_key(block_type, block_id)

if self.get_branch_setting() == ModuleStoreEnum.Branch.published_only:
# if importing a direct only, override existing draft
if block_type in DIRECT_ONLY_CATEGORIES:
draft_course = course_key.for_branch(ModuleStoreEnum.BranchName.draft)
with self.branch_setting(ModuleStoreEnum.Branch.draft_preferred, draft_course):
draft = self.import_xblock(user_id, draft_course, block_type, block_id, fields, runtime)
self._auto_publish_no_children(draft.location, block_type, user_id)
return self.get_item(new_usage_key.for_branch(ModuleStoreEnum.BranchName.published))
# check whether it's new to draft (PLAT_297, need to check even if not new to pub)
elif not self.has_item(new_usage_key.for_branch(ModuleStoreEnum.BranchName.draft)):
# add to draft too
draft_course = course_key.for_branch(ModuleStoreEnum.BranchName.draft)
with self.branch_setting(ModuleStoreEnum.Branch.draft_preferred, draft_course):
draft = self.import_xblock(user_id, draft_course, block_type, block_id, fields, runtime)
return self.publish(draft.location, user_id, blacklist=EXCLUDE_ALL)
# override existing draft (PLAT-297, PLAT-299). NOTE: this has the effect of removing
# any local changes w/ the import.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment for DIRECT_ONLY_CATEGORIES says "Things w/ these categories should never be marked as version=DRAFT". Why?

draft_course = course_key.for_branch(ModuleStoreEnum.BranchName.draft)
with self.branch_setting(ModuleStoreEnum.Branch.draft_preferred, draft_course):
draft_block = self.import_xblock(user_id, draft_course, block_type, block_id, fields, runtime)
return self.publish(draft_block.location.version_agnostic(), user_id, blacklist=EXCLUDE_ALL, **kwargs)

# do the import
partitioned_fields = self.partition_fields_by_scope(block_type, fields)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import mimetypes
from opaque_keys.edx.keys import CourseKey
from xmodule.modulestore.xml_importer import import_from_xml
from nose import SkipTest

if not settings.configured:
settings.configure()
Expand Down Expand Up @@ -1873,7 +1874,7 @@ def test_clone_xml_split(self):
self.assertCoursesEqual(source_store, source_course_key, dest_store, dest_course_id)

@ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split)
def test_import_edit_import(self, default):
def test_import_delete_import(self, default):
"""
Test that deleting an element after import and then re-importing restores that element in draft
as well as published branches (PLAT_297)
Expand Down Expand Up @@ -1918,6 +1919,53 @@ def test_import_edit_import(self, default):
with self.store.branch_setting(ModuleStoreEnum.Branch.published_only, course_id):
self.assertTrue(self.store.has_item(vertical_loc))

@ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split)
def test_import_edit_import(self, default):
"""
Test that editing an element after import and then re-importing resets the draft and pub'd
to the imported pub'd value (PLAT-299)
"""
if default == ModuleStoreEnum.Type.mongo:
raise SkipTest
# set the default modulestore
with MongoContentstoreBuilder().build() as contentstore:
self.store = MixedModuleStore(
contentstore=contentstore,
create_modulestore_instance=create_modulestore_instance,
mappings={},
**self.OPTIONS
)
self.addCleanup(self.store.close_all_connections)
with self.store.default_store(default):
dest_course_key = self.store.make_course_key('a', 'course', 'course')
courses = import_from_xml(
self.store, self.user_id, DATA_DIR, ['toy'], load_error_modules=False,
static_content_store=contentstore,
target_course_id=dest_course_key,
create_new_course_if_not_present=True,
)
course_id = courses[0].id
# no need to verify course content here as test_cross_modulestore_import_export does that
# delete the vertical
vertical_loc = course_id.make_usage_key('vertical', 'vertical_test')
with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, course_id):
vertical = self.store.get_item(vertical_loc)
vertical.display_name = "4"
self.store.update_item(vertical, self.user_id)

# now re-import
import_from_xml(
self.store, self.user_id, DATA_DIR, ['toy'], load_error_modules=False,
static_content_store=contentstore,
target_course_id=dest_course_key,
)
# verify it's the same in both published and draft (toy has no drafts)
with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, course_id):
draft_vertical = self.store.get_item(vertical_loc)
with self.store.branch_setting(ModuleStoreEnum.Branch.published_only, course_id):
published_vertical = self.store.get_item(vertical_loc)
self.assertEqual(draft_vertical.display_name, published_vertical.display_name)

# ============================================================================================================
# General utils for not using django settings
# ============================================================================================================
Expand Down