From 13ff461461f13beb2482ef07a973d73349545e08 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Fri, 16 Aug 2013 10:30:47 -0400 Subject: [PATCH] add a filter to get_courses to not surface any courses that haven't been mapped, unless the store provider has been labeled as 'default' --- common/lib/xmodule/xmodule/modulestore/mixed.py | 15 ++++++++++++++- .../modulestore/tests/test_mixed_modulestore.py | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/common/lib/xmodule/xmodule/modulestore/mixed.py b/common/lib/xmodule/xmodule/modulestore/mixed.py index ec2b563cac..9548323115 100644 --- a/common/lib/xmodule/xmodule/modulestore/mixed.py +++ b/common/lib/xmodule/xmodule/modulestore/mixed.py @@ -103,7 +103,20 @@ class MixedModuleStore(ModuleStoreBase): ''' courses = [] for key in self.modulestores: - courses = courses + (self.modulestores[key].get_courses()) + store_courses = self.modulestores[key].get_courses() + # If the store has not been labeled as 'default' then we should + # only surface courses that have a mapping entry, for example the XMLModuleStore will + # slurp up anything that is on disk, however, we don't want to surface those to + # consumers *unless* there is an explicit mapping in the configuration + if key != 'default': + for course in store_courses: + # make sure that the courseId is mapped to the store in question + if key == self.mappings.get(course.location.course_id, 'default'): + courses = courses + ([course]) + else: + # if we're the 'default' store provider, then we surface all courses hosted in + # that store provider + courses = courses + (store_courses) return courses diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py b/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py index c065b14de9..70e4d1a5d3 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py @@ -187,6 +187,7 @@ class TestMixedModuleStore(object): def test_get_courses(self): # we should have 3 total courses aggregated courses = self.store.get_courses() + assert_equals(len(courses), 3) course_ids = [] for course in courses: course_ids.append(course.location.course_id)