diff --git a/cms/envs/common.py b/cms/envs/common.py index bb99b01a984d..788d4cfa1dc3 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -1067,6 +1067,7 @@ 'combinedopenended', 'graphical_slider_tool', 'randomize', + 'lti', ] # Adding components in this list will disable the creation of new problems for diff --git a/common/lib/xmodule/xmodule/modulestore/split_mongo/mongo_connection.py b/common/lib/xmodule/xmodule/modulestore/split_mongo/mongo_connection.py index 4bf908fc93b3..a59eb59672b5 100644 --- a/common/lib/xmodule/xmodule/modulestore/split_mongo/mongo_connection.py +++ b/common/lib/xmodule/xmodule/modulestore/split_mongo/mongo_connection.py @@ -311,7 +311,7 @@ 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. @@ -319,8 +319,11 @@ def get_structure(self, key, course_context=None): """ 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 @@ -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 diff --git a/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py b/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py index 71ebc3351b5e..e6b1dbf3259e 100644 --- a/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py +++ b/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py @@ -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) @@ -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): """ @@ -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', @@ -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: