Skip to content

Commit

Permalink
Merge pull request #35 from Medality-Health/MRI-4839
Browse files Browse the repository at this point in the history
[MRI-4839] Patch Course Imports for 'Select From Library' Blocks
  • Loading branch information
ianj-lewis authored Oct 25, 2023
2 parents 306962d + e3fd50c commit 4ac6887
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
7 changes: 6 additions & 1 deletion xmodule/modulestore/inheritance.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,12 @@ def compute_inherited_metadata(descriptor):
# inherited_settings values are json repr
parent_metadata[field.name] = field.read_json(descriptor)

for child in descriptor.get_children():
get_children_kwargs = {} # @medality_custom start

if descriptor.category == "select_from_library":
get_children_kwargs["context"] = "course_import"

for child in descriptor.get_children(**get_children_kwargs): # @medality_custom end
inherit_metadata(child, parent_metadata)
compute_inherited_metadata(child)

Expand Down
7 changes: 6 additions & 1 deletion xmodule/modulestore/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,12 @@ def fallback_name(orig_name=None):
xmlstore.modules[course_id][descriptor.scope_ids.usage_id] = descriptor

if descriptor.has_children:
for child in descriptor.get_children():
get_children_kwargs = {} # @medality_custom start

if descriptor.category == "select_from_library":
get_children_kwargs["context"] = "course_import"

for child in descriptor.get_children(**get_children_kwargs): # @medality_custom end
# parent is alphabetically least
if child.parent is None or child.parent > descriptor.scope_ids.usage_id:
child.parent = descriptor.location
Expand Down
13 changes: 10 additions & 3 deletions xmodule/modulestore/xml_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,12 @@ def depth_first(subtree):
Import top down just so import code can make assumptions about parents always being available
"""
if subtree.has_children:
for child in subtree.get_children():
get_children_kwargs = {} # @medality_custom start

if subtree.category == "select_from_library":
get_children_kwargs["context"] = "course_import"

for child in subtree.get_children(**get_children_kwargs): # @medality_custom end
try:
all_locs.remove(child.location)
except KeyError:
Expand Down Expand Up @@ -858,7 +863,9 @@ def _convert_ref_fields_to_new_namespace(reference):
fields = _update_module_references(module, source_course_id, dest_course_id)
asides = module.get_asides() if isinstance(module, XModuleMixin) else None

if module.location.block_type == 'library_content':
lib_content_block_already_published = False # @medality_custom

if module.location.block_type == 'library_content' or module.location.block_type == 'library_content': # @medality_custom
with store.branch_setting(branch_setting=ModuleStoreEnum.Branch.published_only):
lib_content_block_already_published = store.has_item(module.location)

Expand All @@ -875,7 +882,7 @@ def _convert_ref_fields_to_new_namespace(reference):
# Special case handling for library content blocks. The fact that this is
# in Modulestore code is _bad_ and breaks abstraction barriers, but is too
# much work to factor out at this point.
if block.location.block_type == 'library_content':
if block.location.block_type == 'library_content' or block.location.block_type == 'select_from_library': # @medality_custom
# If library exists, update source_library_version and children
# according to this existing library and library content block.
if block.source_library_id and store.get_library(block.source_library_key):
Expand Down

0 comments on commit 4ac6887

Please sign in to comment.