From 867d67752382ac5af60ebb4e44a5f319a899bb54 Mon Sep 17 00:00:00 2001 From: ha-D Date: Fri, 20 Aug 2021 12:05:49 +0000 Subject: [PATCH 1/2] feat: options for excluding courses from search Adds two new fields to the indexed course data: - invitation_only - catalog_visibility Also adds two new settings: `SEARCH_SKIP_INVITATION_ONLY_FILTERING` `SEARCH_SKIP_SHOW_IN_CATALOG_FILTERING` These settings can be used to filter out courses in the search results based on their catalog visibility or based on whether they are invitation-only courses. --- cms/djangoapps/contentstore/courseware_index.py | 2 ++ lms/envs/common.py | 4 ++++ lms/envs/production.py | 9 +++++++++ lms/lib/courseware_search/lms_filter_generator.py | 6 ++++++ 4 files changed, 21 insertions(+) diff --git a/cms/djangoapps/contentstore/courseware_index.py b/cms/djangoapps/contentstore/courseware_index.py index 8bffd64a1fa8..0fb132dc4713 100644 --- a/cms/djangoapps/contentstore/courseware_index.py +++ b/cms/djangoapps/contentstore/courseware_index.py @@ -587,6 +587,8 @@ class CourseAboutSearchIndexer(CoursewareSearchIndexer): AboutInfo("org", AboutInfo.PROPERTY, AboutInfo.FROM_COURSE_PROPERTY), AboutInfo("modes", AboutInfo.PROPERTY, AboutInfo.FROM_COURSE_MODE), AboutInfo("language", AboutInfo.PROPERTY, AboutInfo.FROM_COURSE_PROPERTY), + AboutInfo("invitation_only", AboutInfo.PROPERTY, AboutInfo.FROM_COURSE_PROPERTY), + AboutInfo("catalog_visibility", AboutInfo.PROPERTY, AboutInfo.FROM_COURSE_PROPERTY), ] @classmethod diff --git a/lms/envs/common.py b/lms/envs/common.py index d5b3ac2b1afc..a8f99f42240a 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -3934,6 +3934,10 @@ def _make_locale_paths(settings): # pylint: disable=missing-function-docstring SEARCH_FILTER_GENERATOR = "lms.lib.courseware_search.lms_filter_generator.LmsSearchFilterGenerator" # Override to skip enrollment start date filtering in course search SEARCH_SKIP_ENROLLMENT_START_DATE_FILTERING = False +# Override to skip excluding invitation-only courses in course search +SEARCH_SKIP_INVITATION_ONLY_FILTERING = True +# Override to skip excluding non-catalog courses in course search +SEARCH_SKIP_SHOW_IN_CATALOG_FILTERING = True # The configuration visibility of account fields. ACCOUNT_VISIBILITY_CONFIGURATION = { diff --git a/lms/envs/production.py b/lms/envs/production.py index 9ede3006ac36..d156c91f04d1 100644 --- a/lms/envs/production.py +++ b/lms/envs/production.py @@ -715,6 +715,15 @@ def get_env_setting(setting): SEARCH_ENGINE = "search.elastic.ElasticSearchEngine" SEARCH_FILTER_GENERATOR = ENV_TOKENS.get('SEARCH_FILTER_GENERATOR', SEARCH_FILTER_GENERATOR) +SEARCH_SKIP_INVITATION_ONLY_FILTERING = ENV_TOKENS.get( + 'SEARCH_SKIP_INVITATION_ONLY_FILTERING', + SEARCH_SKIP_INVITATION_ONLY_FILTERING +) +SEARCH_SKIP_SHOW_IN_CATALOG_FILTERING = ENV_TOKENS.get( + 'SEARCH_SKIP_SHOW_IN_CATALOG_FILTERING', + SEARCH_SKIP_SHOW_IN_CATALOG_FILTERING +) + # TODO: Once we have successfully upgraded to ES7, switch this back to ELASTIC_SEARCH_CONFIG. ELASTIC_SEARCH_CONFIG = ENV_TOKENS.get('ELASTIC_SEARCH_CONFIG_ES7', [{}]) diff --git a/lms/lib/courseware_search/lms_filter_generator.py b/lms/lib/courseware_search/lms_filter_generator.py index 14b539b4291e..6fb880dc59c2 100644 --- a/lms/lib/courseware_search/lms_filter_generator.py +++ b/lms/lib/courseware_search/lms_filter_generator.py @@ -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 django.conf import settings from search.filter_generator import SearchFilterGenerator from openedx.core.djangoapps.course_groups.partition_scheme import CohortPartitionScheme @@ -52,4 +53,9 @@ def exclude_dictionary(self, **kwargs): if org_filter_out_set: exclude_dictionary['org'] = list(org_filter_out_set) + if not getattr(settings, "SEARCH_SKIP_INVITATION_ONLY_FILTERING", False): + exclude_dictionary['invitation_only'] = True + if not getattr(settings, "SEARCH_SKIP_SHOW_IN_CATALOG_FILTERING", False): + exclude_dictionary['catalog_visibility'] = 'none' + return exclude_dictionary From a5ba091d563f9a31c23252cfb7abe281d061cade Mon Sep 17 00:00:00 2001 From: ha-D Date: Thu, 26 Aug 2021 23:13:34 +0000 Subject: [PATCH 2/2] fixup! feat: options for excluding courses from search --- lms/envs/common.py | 15 +++++++++++++-- lms/envs/production.py | 4 ++-- lms/lib/courseware_search/lms_filter_generator.py | 4 ++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lms/envs/common.py b/lms/envs/common.py index a8f99f42240a..426fef291409 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -3934,9 +3934,20 @@ def _make_locale_paths(settings): # pylint: disable=missing-function-docstring SEARCH_FILTER_GENERATOR = "lms.lib.courseware_search.lms_filter_generator.LmsSearchFilterGenerator" # Override to skip enrollment start date filtering in course search SEARCH_SKIP_ENROLLMENT_START_DATE_FILTERING = False -# Override to skip excluding invitation-only courses in course search +# .. toggle_name: SEARCH_SKIP_INVITATION_ONLY_FILTERING +# .. toggle_implementation: DjangoSetting +# .. toggle_default: True +# .. toggle_description: If enabled, invitation-only courses will appear in search results. +# .. toggle_use_cases: open_edx +# .. toggle_creation_date: 2021-08-27 SEARCH_SKIP_INVITATION_ONLY_FILTERING = True -# Override to skip excluding non-catalog courses in course search +# .. toggle_name: SEARCH_SKIP_SHOW_IN_CATALOG_FILTERING +# .. toggle_implementation: DjangoSetting +# .. toggle_default: True +# .. toggle_description: If enabled, courses with a catalog_visibility set to "none" will still +# appear in search results. +# .. toggle_use_cases: open_edx +# .. toggle_creation_date: 2021-08-27 SEARCH_SKIP_SHOW_IN_CATALOG_FILTERING = True # The configuration visibility of account fields. diff --git a/lms/envs/production.py b/lms/envs/production.py index d156c91f04d1..6c59b8cc8161 100644 --- a/lms/envs/production.py +++ b/lms/envs/production.py @@ -717,11 +717,11 @@ def get_env_setting(setting): SEARCH_SKIP_INVITATION_ONLY_FILTERING = ENV_TOKENS.get( 'SEARCH_SKIP_INVITATION_ONLY_FILTERING', - SEARCH_SKIP_INVITATION_ONLY_FILTERING + SEARCH_SKIP_INVITATION_ONLY_FILTERING, ) SEARCH_SKIP_SHOW_IN_CATALOG_FILTERING = ENV_TOKENS.get( 'SEARCH_SKIP_SHOW_IN_CATALOG_FILTERING', - SEARCH_SKIP_SHOW_IN_CATALOG_FILTERING + SEARCH_SKIP_SHOW_IN_CATALOG_FILTERING, ) # TODO: Once we have successfully upgraded to ES7, switch this back to ELASTIC_SEARCH_CONFIG. diff --git a/lms/lib/courseware_search/lms_filter_generator.py b/lms/lib/courseware_search/lms_filter_generator.py index 6fb880dc59c2..c4e5ab7ac736 100644 --- a/lms/lib/courseware_search/lms_filter_generator.py +++ b/lms/lib/courseware_search/lms_filter_generator.py @@ -53,9 +53,9 @@ def exclude_dictionary(self, **kwargs): if org_filter_out_set: exclude_dictionary['org'] = list(org_filter_out_set) - if not getattr(settings, "SEARCH_SKIP_INVITATION_ONLY_FILTERING", False): + if not getattr(settings, "SEARCH_SKIP_INVITATION_ONLY_FILTERING", True): exclude_dictionary['invitation_only'] = True - if not getattr(settings, "SEARCH_SKIP_SHOW_IN_CATALOG_FILTERING", False): + if not getattr(settings, "SEARCH_SKIP_SHOW_IN_CATALOG_FILTERING", True): exclude_dictionary['catalog_visibility'] = 'none' return exclude_dictionary