Skip to content
Closed
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
1 change: 1 addition & 0 deletions cms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,7 @@
'combinedopenended',
'graphical_slider_tool',
'randomize',
'lti',
]

# Adding components in this list will disable the creation of new problems for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,16 +311,19 @@ def heartbeat(self):
else:
raise HeartbeatFailure("Can't connect to {}".format(self.database.name), 'mongo')

def get_structure(self, key, course_context=None):
def get_structure(self, key, course_context=None, deprecated_block_exits=False):
"""
Get the structure from the persistence mechanism whose id is the given key.

This method will use a cached version of the structure if it is availble.
"""
with TIMER.timer("get_structure", course_context) as tagger_get_structure:
cache = CourseStructureCache()

structure = cache.get(key, course_context)

if deprecated_block_exits:
structure = None

tagger_get_structure.tag(from_cache=str(bool(structure)).lower())
if not structure:
# Always log cache misses, because they are unexpected
Expand All @@ -329,6 +332,16 @@ def get_structure(self, key, course_context=None):
with TIMER.timer("get_structure.find_one", course_context) as tagger_find_one:
doc = self.structures.find_one({'_id': key})
tagger_find_one.measure("blocks", len(doc['blocks']))
if deprecated_block_exits:
for block in doc["blocks"]:
if block['block_type'] == 'lti':
# If I uncomment the next line, it will change the block_type but
# when we try to see the new course then it is returning the error
# ItemNotFound BlockKey(type=u'lti', id=u'c55461a8016845b9957ef3fa8ff92b1f')

block['block_type'] = "lti_consumer"
block["fields"]["launch_target"] = "new_window" \
if block["fields"].pop("open_in_a_new_page", True) else "inline"
structure = structure_from_mongo(doc, course_context)
tagger_find_one.sample_rate = 1

Expand Down
35 changes: 33 additions & 2 deletions common/lib/xmodule/xmodule/modulestore/split_mongo/split.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def update_course_index(self, course_key, updated_index_entry):
else:
self.db_connection.update_course_index(updated_index_entry, course_context=course_key)

def get_structure(self, course_key, version_guid):
def get_structure(self, course_key, version_guid, deprecated_block_exits=False):
bulk_write_record = self._get_bulk_ops_record(course_key)
if bulk_write_record.active:
structure = bulk_write_record.structures.get(version_guid)
Expand All @@ -333,7 +333,12 @@ def get_structure(self, course_key, version_guid):
else:
# cast string to ObjectId if necessary
version_guid = course_key.as_object_id(version_guid)
return self.db_connection.get_structure(version_guid, course_key)
structure = self.db_connection.get_structure(
version_guid,
course_key,
deprecated_block_exits=deprecated_block_exits
)
return structure

def update_structure(self, course_key, structure):
"""
Expand Down Expand Up @@ -1863,6 +1868,23 @@ def create_course(
search_targets, root_category, root_block_id, **kwargs
)

def _is_lti_module_exist(self, structure):
for block_key, block in structure['blocks'].iteritems():
if block_key.type == 'lti':
return True
return False

def get_updated_structure(self, course_key):
if course_key.org and course_key.course and course_key.run:
# use the course id
index = self.get_course_index(course_key)
version_guid = index['versions'][course_key.branch]
else:
version_guid = course_key.version_guid

entry = self.get_structure(course_key, version_guid, deprecated_block_exits=True)
return CourseEnvelope(course_key.replace(version_guid=version_guid), entry)

def _create_courselike(
self, locator, user_id, master_branch, fields=None,
versions_dict=None, search_targets=None, root_category='course',
Expand Down Expand Up @@ -1907,7 +1929,16 @@ def _create_courselike(
# just get the draft_version structure
draft_version = CourseLocator(version_guid=versions_dict[master_branch])
draft_structure = self._lookup_course(draft_version).structure
if self._is_lti_module_exist(draft_structure):
draft_structure = self.get_updated_structure(draft_version).structure
draft_structure = self.version_structure(locator, draft_structure, user_id)

# BlockUsageLocator(course_key=locator.id,block_type="lti",block_id='c55461a8016845b9957ef3fa8ff92b1f')
#
# bkl = BlockUsageLocator(course_key=locator, block_type="lti", block_id='c55461a8016845b9957ef3fa8ff92b1f')
# bk = BlockKey.from_usage_key(bkl)
# lti_block = draft_structure['blocks'][bk]

new_id = draft_structure['_id']
root_block = draft_structure['blocks'][draft_structure['root']]
if block_fields is not None:
Expand Down