Exclude filtering for micorosite orgs
This commit is contained in:
@@ -106,7 +106,7 @@ class SearchIndexerBase(object):
|
||||
response = searcher.search(
|
||||
doc_type=cls.DOCUMENT_TYPE,
|
||||
field_dictionary=cls._get_location_info(structure_key),
|
||||
exclude_ids=exclude_items
|
||||
exclude_dictionary={"id": list(exclude_items)}
|
||||
)
|
||||
result_ids = [result["data"]["id"] for result in response["results"]]
|
||||
for result_id in result_ids:
|
||||
@@ -298,7 +298,7 @@ class CoursewareSearchIndexer(SearchIndexerBase):
|
||||
@classmethod
|
||||
def _get_location_info(cls, normalized_structure_key):
|
||||
""" Builds location info dictionary """
|
||||
return {"course": unicode(normalized_structure_key)}
|
||||
return {"course": unicode(normalized_structure_key), "org": normalized_structure_key.org}
|
||||
|
||||
@classmethod
|
||||
def do_course_reindex(cls, modulestore, course_key):
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
This file contains implementation override of SearchFilterGenerator which will allow
|
||||
* Filter by all courses in which the user is enrolled in
|
||||
"""
|
||||
from microsite_configuration import microsite
|
||||
from student.models import CourseEnrollment
|
||||
|
||||
from search.filter_generator import SearchFilterGenerator
|
||||
@@ -19,4 +20,20 @@ class LmsSearchFilterGenerator(SearchFilterGenerator):
|
||||
user_enrollments = CourseEnrollment.enrollments_for_user(kwargs['user'])
|
||||
field_dictionary['course'] = [unicode(enrollment.course_id) for enrollment in user_enrollments]
|
||||
|
||||
# if we have an org filter, only include results for this org filter
|
||||
course_org_filter = microsite.get_value('course_org_filter')
|
||||
if course_org_filter:
|
||||
field_dictionary['org'] = course_org_filter
|
||||
|
||||
return field_dictionary
|
||||
|
||||
def exclude_dictionary(self, **kwargs):
|
||||
""" If we are not on a microsite, then exclude any microsites that are defined """
|
||||
exclude_dictionary = super(LmsSearchFilterGenerator, self).exclude_dictionary(**kwargs)
|
||||
course_org_filter = microsite.get_value('course_org_filter')
|
||||
# If we have a course filter we are ensuring that we only get those courses above
|
||||
org_filter_out_set = microsite.get_all_orgs()
|
||||
if not course_org_filter and org_filter_out_set:
|
||||
exclude_dictionary['org'] = list(org_filter_out_set)
|
||||
|
||||
return exclude_dictionary
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
"""
|
||||
Tests for the lms_filter_generator
|
||||
"""
|
||||
from mock import patch, Mock
|
||||
|
||||
from xmodule.modulestore.tests.factories import CourseFactory
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
from student.tests.factories import UserFactory
|
||||
@@ -44,7 +46,7 @@ class LmsSearchFilterGeneratorTestCase(ModuleStoreTestCase):
|
||||
"""
|
||||
Tests that we get the list of IDs of courses the user is enrolled in when the course ID is null or not provided
|
||||
"""
|
||||
field_dictionary, filter_dictionary = LmsSearchFilterGenerator.generate_field_filters(user=self.user)
|
||||
field_dictionary, filter_dictionary, _ = LmsSearchFilterGenerator.generate_field_filters(user=self.user)
|
||||
|
||||
self.assertTrue('start_date' in filter_dictionary)
|
||||
self.assertIn(unicode(self.courses[0].id), field_dictionary['course'])
|
||||
@@ -54,7 +56,7 @@ class LmsSearchFilterGeneratorTestCase(ModuleStoreTestCase):
|
||||
"""
|
||||
Tests that we get the course ID when the course ID is provided
|
||||
"""
|
||||
field_dictionary, filter_dictionary = LmsSearchFilterGenerator.generate_field_filters(
|
||||
field_dictionary, filter_dictionary, _ = LmsSearchFilterGenerator.generate_field_filters(
|
||||
user=self.user,
|
||||
course_id=unicode(self.courses[0].id)
|
||||
)
|
||||
@@ -66,7 +68,53 @@ class LmsSearchFilterGeneratorTestCase(ModuleStoreTestCase):
|
||||
"""
|
||||
Tests that we get empty list of courses in case the user is not provided
|
||||
"""
|
||||
field_dictionary, filter_dictionary = LmsSearchFilterGenerator.generate_field_filters()
|
||||
field_dictionary, filter_dictionary, _ = LmsSearchFilterGenerator.generate_field_filters()
|
||||
|
||||
self.assertTrue('start_date' in filter_dictionary)
|
||||
self.assertEqual(0, len(field_dictionary['course']))
|
||||
|
||||
def test_excludes_microsite(self):
|
||||
""" By default there is the test microsite to exclude """
|
||||
_, _, exclude_dictionary = LmsSearchFilterGenerator.generate_field_filters(user=self.user)
|
||||
self.assertIn('org', exclude_dictionary)
|
||||
exclude_orgs = exclude_dictionary['org']
|
||||
self.assertEqual(1, len(exclude_orgs))
|
||||
self.assertEqual('TestMicrositeX', exclude_orgs[0])
|
||||
|
||||
@patch('microsite_configuration.microsite.get_all_orgs', Mock(return_value=[]))
|
||||
def test_excludes_no_microsite(self):
|
||||
""" Test when no microsite is present - nothing to exclude """
|
||||
_, _, exclude_dictionary = LmsSearchFilterGenerator.generate_field_filters(user=self.user)
|
||||
self.assertNotIn('org', exclude_dictionary)
|
||||
|
||||
@patch('microsite_configuration.microsite.get_value', Mock(return_value='TestMicrositeX'))
|
||||
def test_excludes_microsite_within(self):
|
||||
field_dictionary, _, exclude_dictionary = LmsSearchFilterGenerator.generate_field_filters(user=self.user)
|
||||
self.assertNotIn('org', exclude_dictionary)
|
||||
self.assertIn('org', field_dictionary)
|
||||
self.assertEqual('TestMicrositeX', field_dictionary['org'])
|
||||
|
||||
@patch(
|
||||
'microsite_configuration.microsite.get_all_orgs',
|
||||
Mock(return_value=["TestMicrosite1", "TestMicrosite2", "TestMicrosite3", "TestMicrosite4"])
|
||||
)
|
||||
def test_excludes_multi_microsites(self):
|
||||
_, _, exclude_dictionary = LmsSearchFilterGenerator.generate_field_filters(user=self.user)
|
||||
self.assertIn('org', exclude_dictionary)
|
||||
exclude_orgs = exclude_dictionary['org']
|
||||
self.assertEqual(4, len(exclude_orgs))
|
||||
self.assertIn('TestMicrosite1', exclude_orgs)
|
||||
self.assertIn('TestMicrosite2', exclude_orgs)
|
||||
self.assertIn('TestMicrosite3', exclude_orgs)
|
||||
self.assertIn('TestMicrosite4', exclude_orgs)
|
||||
|
||||
@patch(
|
||||
'microsite_configuration.microsite.get_all_orgs',
|
||||
Mock(return_value=["TestMicrosite1", "TestMicrosite2", "TestMicrosite3", "TestMicrosite4"])
|
||||
)
|
||||
@patch('microsite_configuration.microsite.get_value', Mock(return_value='TestMicrosite3'))
|
||||
def test_excludes_multi_microsites_within(self):
|
||||
field_dictionary, _, exclude_dictionary = LmsSearchFilterGenerator.generate_field_filters(user=self.user)
|
||||
self.assertNotIn('org', exclude_dictionary)
|
||||
self.assertIn('org', field_dictionary)
|
||||
self.assertEqual('TestMicrosite3', field_dictionary['org'])
|
||||
|
||||
@@ -43,7 +43,7 @@ git+https://github.com/pmitros/pyfs.git@96e1922348bfe6d99201b9512a9ed946c87b7e0b
|
||||
-e git+https://github.com/edx/edx-val.git@d6087908aa3dd05ceaa7f56a21284f86c53cb3f0#egg=edx-val
|
||||
-e git+https://github.com/pmitros/RecommenderXBlock.git@9b07e807c89ba5761827d0387177f71aa57ef056#egg=recommender-xblock
|
||||
-e git+https://github.com/edx/edx-milestones.git@547f2250ee49e73ce8d7ff4e78ecf1b049892510#egg=edx-milestones
|
||||
-e git+https://github.com/edx/edx-search.git@9d566b88fd80cb0b60c052eee2bee30eb9f35b9c#egg=edx-search
|
||||
-e git+https://github.com/edx/edx-search.git@59c7b4a8b61e8f7c4607669ea48e070555cca2fe#egg=edx-search
|
||||
git+https://github.com/edx/edx-lint.git@8bf82a32ecb8598c415413df66f5232ab8d974e9#egg=edx_lint==0.2.1
|
||||
-e git+https://github.com/edx/xblock-utils.git@581ed636c862b286002bb9a3724cc883570eb54c#egg=xblock-utils
|
||||
-e git+https://github.com/edx-solutions/xblock-google-drive.git@138e6fa0bf3a2013e904a085b9fed77dab7f3f21#egg=xblock-google-drive
|
||||
|
||||
Reference in New Issue
Block a user