Commit 344e13b1 by Robert Raposa Committed by GitHub

Merge pull request #16179 from edx/robrap/refactor-site-enrollment-filter

Refactor site course enrollment filtering.
parents 0702df51 112938e4
......@@ -275,15 +275,14 @@ def reverification_info(statuses):
return reverifications
def get_course_enrollments(user, orgs_to_include, orgs_to_exclude):
def get_course_enrollments(user, org_whitelist, org_blacklist):
"""
Given a user, return a filtered set of his or her course enrollments.
Arguments:
user (User): the user in question.
orgs_to_include (list[str]): If not None, ONLY courses of these orgs will be returned.
orgs_to_exclude (list[str]): If orgs_to_include is not None, this
argument is ignored. Else, courses of this org will be excluded.
org_whitelist (list[str]): If not None, ONLY courses of these orgs will be returned.
org_blacklist (list[str]): Courses of these orgs will be excluded.
Returns:
generator[CourseEnrollment]: a sequence of enrollments to be displayed
......@@ -301,12 +300,12 @@ def get_course_enrollments(user, orgs_to_include, orgs_to_exclude):
)
continue
# Filter out anything that is not attributed to the orgs to include.
if orgs_to_include and course_overview.location.org not in orgs_to_include:
# Filter out anything that is not in the whitelist.
if org_whitelist and course_overview.location.org not in org_whitelist:
continue
# Conversely, filter out any enrollments with courses attributed to current ORG.
elif course_overview.location.org in orgs_to_exclude:
# Conversely, filter out any enrollments in the blacklist.
elif org_blacklist and course_overview.location.org in org_blacklist:
continue
# Else, include the enrollment.
......@@ -314,6 +313,31 @@ def get_course_enrollments(user, orgs_to_include, orgs_to_exclude):
yield enrollment
def get_org_black_and_whitelist_for_site(user):
"""
Returns the org blacklist and whitelist for the current site.
Returns:
(org_whitelist, org_blacklist): A tuple of lists of orgs that serve as
either a blacklist or a whitelist of orgs for the current site. The
whitelist takes precedence, and the blacklist is used if the
whitelist is None.
"""
# Default blacklist is empty.
org_blacklist = None
# Whitelist the orgs configured for the current site. Each site outside
# of edx.org has a list of orgs associated with its configuration.
org_whitelist = configuration_helpers.get_current_site_orgs()
if not org_whitelist:
# If there is no whitelist, the blacklist will include all orgs that
# have been configured for any other sites. This applies to edx.org,
# where it is easier to blacklist all other orgs.
org_blacklist = configuration_helpers.get_all_orgs()
return (org_whitelist, org_blacklist)
def _cert_info(user, course_overview, cert_status, course_mode): # pylint: disable=unused-argument
"""
Implements the logic for cert_info -- split out for testing.
......@@ -647,21 +671,9 @@ def dashboard(request):
'ACTIVATION_EMAIL_SUPPORT_LINK', settings.ACTIVATION_EMAIL_SUPPORT_LINK
) or settings.SUPPORT_SITE_LINK
# Let's filter out any courses in an "org" that has been declared to be
# in a configuration
org_filter_out_set = configuration_helpers.get_all_orgs()
# Remove current site orgs from the "filter out" list, if applicable.
# We want to filter and only show enrollments for courses within
# the organizations defined in configuration for the current site.
course_org_filter = configuration_helpers.get_current_site_orgs()
if course_org_filter:
org_filter_out_set = org_filter_out_set - set(course_org_filter)
# Build our (course, enrollment) list for the user, but ignore any courses that no
# longer exist (because the course IDs have changed). Still, we don't delete those
# enrollments, because it could have been a data push snafu.
course_enrollments = list(get_course_enrollments(user, course_org_filter, org_filter_out_set))
# get the org whitelist or the org blacklist for the current site
site_org_whitelist, site_org_blacklist = get_org_black_and_whitelist_for_site(user)
course_enrollments = list(get_course_enrollments(user, site_org_whitelist, site_org_blacklist))
# Record how many courses there are so that we can get a better
# understanding of usage patterns on prod.
......@@ -808,7 +820,7 @@ def dashboard(request):
denied_banner = any(item.display for item in reverifications["denied"])
# Populate the Order History for the side-bar.
order_history_list = order_history(user, course_org_filter=course_org_filter, org_filter_out_set=org_filter_out_set)
order_history_list = order_history(user, course_org_filter=site_org_whitelist, org_filter_out_set=site_org_blacklist)
# get list of courses having pre-requisites yet to be completed
courses_having_prerequisites = frozenset(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment