[BD-14] Migrate all environments to use database-backed organizations (#25153)
* Install `organizations` app into LMS and Studio non-optionally. * Add toggle `ORGANIZATIONS_AUTOCREATE` to Studio. * Remove the `FEATURES["ORGANIZATIONS_APP"]` toggle. * Use the new `organizations.api.ensure_organization` function to either validate or get-or-create organizations, depending on the value of `ORGANIZATIONS_AUTOCREATE`, when creating course runs and V2 content libraries. We'll soon use it for V1 content libraries as well. * Remove the `util.organizations_helpers` wrapper layer that had to exist because `organizations` was an optional app. * Add `.get_library_keys()` method to the Split modulestore. * Add Studio management command for backfilling organizations tables (`backfill_orgs_and_org_courses`). For full details, see https://github.com/edx/edx-organizations/blob/master/docs/decisions/0001-phase-in-db-backed-organizations-to-all.rst TNL-7646
This commit is contained in:
@@ -327,6 +327,23 @@ class MixedModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase):
|
||||
courses[course_id] = course
|
||||
return list(courses.values())
|
||||
|
||||
def get_library_keys(self):
|
||||
"""
|
||||
Returns a list of all unique content library keys in the mixed
|
||||
modulestore.
|
||||
|
||||
Returns: list[LibraryLocator]
|
||||
"""
|
||||
all_library_keys = set()
|
||||
for store in self.modulestores:
|
||||
if not hasattr(store, 'get_library_keys'):
|
||||
continue
|
||||
all_library_keys |= set(
|
||||
self._clean_locator_for_mapping(library_key)
|
||||
for library_key in store.get_library_keys()
|
||||
)
|
||||
return list(all_library_keys)
|
||||
|
||||
@strip_key
|
||||
def get_library_summaries(self, **kwargs):
|
||||
"""
|
||||
|
||||
@@ -1073,6 +1073,19 @@ class SplitMongoModuleStore(SplitBulkWriteMixin, ModuleStoreWriteBase):
|
||||
)
|
||||
return courses_summaries
|
||||
|
||||
def get_library_keys(self):
|
||||
"""
|
||||
Returns a list of all unique content library keys in the Split
|
||||
modulestore.
|
||||
|
||||
Returns: list[LibraryLocator]
|
||||
"""
|
||||
return list({
|
||||
self._create_library_locator(library_index, branch=None)
|
||||
for library_index
|
||||
in self.find_matching_course_indexes(branch="library")
|
||||
})
|
||||
|
||||
@autoretry_read()
|
||||
def get_library_summaries(self, **kwargs):
|
||||
"""
|
||||
|
||||
@@ -145,6 +145,13 @@ class TestLibraries(MixedSplitTestCase):
|
||||
result = self.store.get_library(LibraryLocator("non", "existent"))
|
||||
self.assertEqual(result, None)
|
||||
|
||||
def test_get_library_keys(self):
|
||||
""" Test get_library_keys() """
|
||||
libraries = [LibraryFactory.create(modulestore=self.store) for _ in range(3)]
|
||||
lib_keys_expected = {lib.location.library_key for lib in libraries}
|
||||
lib_keys_actual = set(self.store.get_library_keys())
|
||||
assert lib_keys_expected == lib_keys_actual
|
||||
|
||||
def test_get_libraries(self):
|
||||
""" Test get_libraries() """
|
||||
libraries = [LibraryFactory.create(modulestore=self.store) for _ in range(3)]
|
||||
|
||||
Reference in New Issue
Block a user