コード例 #1
0
ファイル: views.py プロジェクト: harambee-sa/edx-platform
    def get_queryset(self):
        CREATED = 'created'
        CREATED_REVERSE = 'created_reverse'
        COURSE_NAME = 'course_name'
        COURSE_NAME_REVERSE = 'course_name_reverse'
        
        queryset_options = {
            CREATED: self.queryset_order_by_created,
            CREATED_REVERSE: self.queryset_order_by_created_reverse,
            COURSE_NAME: self.queryset_order_by_course_name,
            COURSE_NAME_REVERSE: self.queryset_order_by_course_name_reverse
        }

        partial_queryset =\
            self.queryset.filter(
                user__username=self.kwargs['username'],
                is_active=True
            )

        order_by =\
            configuration_helpers.get_value(
                'USER_COURSE_ENROLLMENTS_ORDER_BY',
                settings.USER_COURSE_ENROLLMENTS_ORDER_BY
            )

        enrollments = queryset_options[order_by](partial_queryset)
        org = self.request.query_params.get('org', None)
        orgs = configuration_helpers.get_all_orgs()
        return [
            enrollment for enrollment in enrollments
            if enrollment.course_overview and
            self.is_org(org, enrollment.course_overview.org) and
            (org or enrollment.course_overview.org not in orgs) and
            is_mobile_available_for_user(self.request.user, enrollment.course_overview)
        ]
コード例 #2
0
 def test_get_all_orgs(self):
     """
     Test that get_all_orgs returns organizations defined in both site configuration and microsite configuration.
     """
     test_orgs = [test_config['course_org_filter'], "LogistrationX", "TestSiteX"]
     with with_site_configuration_context(configuration=test_config):
         self.assertItemsEqual(
             list(configuration_helpers.get_all_orgs()),
             test_orgs,
         )
コード例 #3
0
 def test_get_all_orgs(self):
     """
     Test that get_all_orgs returns organizations defined in site configuration
     """
     test_orgs = [test_config['course_org_filter']]
     with with_site_configuration_context(configuration=test_config):
         self.assertCountEqual(
             list(configuration_helpers.get_all_orgs()),
             test_orgs,
         )
コード例 #4
0
 def test_get_all_orgs(self):
     """
     Test that get_all_orgs returns organizations defined in both site configuration and microsite configuration.
     """
     test_orgs = [test_config['course_org_filter'], "LogistrationX", "TestSiteX"]
     with with_site_configuration_context(configuration=test_config):
         self.assertItemsEqual(
             list(configuration_helpers.get_all_orgs()),
             test_orgs,
         )
コード例 #5
0
 def test_get_all_orgs(self):
     """
     Test that get_all_orgs returns correct values.
     """
     test_orgs = [test_config['course_org_filter']]
     with with_site_configuration_context(configuration=test_config):
         self.assertItemsEqual(
             list(configuration_helpers.get_all_orgs()),
             test_orgs,
         )
コード例 #6
0
ファイル: __init__.py プロジェクト: ntakma/edx-platform-1
def get_visible_courses(org=None, filter_=None):
    """
    Yield the CourseOverviews that should be visible in this branded
    instance.

    Arguments:
        org (string): Optional parameter that allows case-insensitive
            filtering by organization.
        filter_ (dict): Optional parameter that allows custom filtering by
            fields on the course.
    """
    # Import is placed here to avoid model import at project startup.
    from openedx.core.djangoapps.content.course_overviews.models import CourseOverview

    current_site_orgs = configuration_helpers.get_current_site_orgs()

    courses = CourseOverview.objects.none()

    if org:
        # Check the current site's orgs to make sure the org's courses should be displayed
        if not current_site_orgs or org in current_site_orgs:
            courses = CourseOverview.get_all_courses(orgs=[org],
                                                     filter_=filter_)
    elif current_site_orgs:
        # Only display courses that should be displayed on this site
        courses = CourseOverview.get_all_courses(orgs=current_site_orgs,
                                                 filter_=filter_)
    else:
        courses = CourseOverview.get_all_courses(filter_=filter_)

    courses = courses.order_by('id')

    # Filtering can stop here.
    if current_site_orgs:
        return courses

    # See if we have filtered course listings in this domain
    filtered_visible_ids = None

    # this is legacy format, which also handle dev case, which should not filter
    subdomain = configuration_helpers.get_value('subdomain', 'default')
    if hasattr(
            settings, 'COURSE_LISTINGS'
    ) and subdomain in settings.COURSE_LISTINGS and not settings.DEBUG:
        filtered_visible_ids = frozenset([
            CourseKey.from_string(c)
            for c in settings.COURSE_LISTINGS[subdomain]
        ])

    if filtered_visible_ids:
        return courses.filter(id__in=filtered_visible_ids)
    else:
        # Filter out any courses based on current org, to avoid leaking these.
        orgs = configuration_helpers.get_all_orgs()
        return courses.exclude(org__in=orgs)
コード例 #7
0
ファイル: __init__.py プロジェクト: vesloguzov/edx-platform
def get_visible_courses(org=None, filter_=None):
    """
    Return the set of CourseOverviews that should be visible in this branded
    instance.

    Arguments:
        org (string): Optional parameter that allows case-insensitive
            filtering by organization.
        filter_ (dict): Optional parameter that allows custom filtering by
            fields on the course.
    """
    courses = []
    current_site_orgs = configuration_helpers.get_current_site_orgs()

    if org:
        # Check the current site's orgs to make sure the org's courses should be displayed
        if not current_site_orgs or org in current_site_orgs:
            courses = CourseOverview.get_all_courses(orgs=[org],
                                                     filter_=filter_)
    elif current_site_orgs:
        # Only display courses that should be displayed on this site
        courses = CourseOverview.get_all_courses(orgs=current_site_orgs,
                                                 filter_=filter_)
    else:
        courses = CourseOverview.get_all_courses(filter_=filter_)

    courses = sorted(courses, key=lambda course: course.number)

    # Filtering can stop here.
    if current_site_orgs:
        return courses

    # See if we have filtered course listings in this domain
    filtered_visible_ids = None

    # this is legacy format, which also handle dev case, which should not filter
    subdomain = configuration_helpers.get_value('subdomain', 'default')
    if hasattr(
            settings, 'COURSE_LISTINGS'
    ) and subdomain in settings.COURSE_LISTINGS and not settings.DEBUG:
        filtered_visible_ids = frozenset([
            CourseKey.from_string(c)
            for c in settings.COURSE_LISTINGS[subdomain]
        ])

    if filtered_visible_ids:
        return [
            course for course in courses if course.id in filtered_visible_ids
        ]
    else:
        # Filter out any courses based on current org, to avoid leaking these.
        orgs = configuration_helpers.get_all_orgs()
        return [
            course for course in courses if course.location.org not in orgs
        ]
コード例 #8
0
    def exclude_dictionary(self, **kwargs):
        """
            Exclude any courses defined outside the current org.
        """
        exclude_dictionary = super(LmsSearchFilterGenerator, self).exclude_dictionary(**kwargs)
        course_org_filter = configuration_helpers.get_value('course_org_filter')
        # If we have a course filter we are ensuring that we only get those courses above
        if not course_org_filter:
            org_filter_out_set = configuration_helpers.get_all_orgs()
            if org_filter_out_set:
                exclude_dictionary['org'] = list(org_filter_out_set)

        return exclude_dictionary
コード例 #9
0
    def exclude_dictionary(self, **kwargs):
        """
            Exclude any courses defined outside the current org.
        """
        exclude_dictionary = super(LmsSearchFilterGenerator, self).exclude_dictionary(**kwargs)
        course_org_filter = configuration_helpers.get_current_site_orgs()
        # If we have a course filter we are ensuring that we only get those courses above
        if not course_org_filter:
            org_filter_out_set = configuration_helpers.get_all_orgs()
            if org_filter_out_set:
                exclude_dictionary['org'] = list(org_filter_out_set)

        return exclude_dictionary
コード例 #10
0
def get_visible_courses(org=None, filter_=None):
    """
    Yield the CourseOverviews that should be visible in this branded
    instance.

    Arguments:
        org (string): Optional parameter that allows case-insensitive
            filtering by organization.
        filter_ (dict): Optional parameter that allows custom filtering by
            fields on the course.
    """
    # Import is placed here to avoid model import at project startup.
    from openedx.core.djangoapps.content.course_overviews.models import CourseOverview

    current_site_orgs = configuration_helpers.get_current_site_orgs()

    courses = CourseOverview.objects.none()

    if org:
        # Check the current site's orgs to make sure the org's courses should be displayed
        if not current_site_orgs or org in current_site_orgs:
            courses = CourseOverview.get_all_courses(orgs=[org], filter_=filter_)
    elif current_site_orgs:
        # Only display courses that should be displayed on this site
        courses = CourseOverview.get_all_courses(orgs=current_site_orgs, filter_=filter_)
    else:
        courses = CourseOverview.get_all_courses(filter_=filter_)

    courses = courses.order_by('id')

    # Filtering can stop here.
    if current_site_orgs:
        return courses

    # See if we have filtered course listings in this domain
    filtered_visible_ids = None

    # this is legacy format, which also handle dev case, which should not filter
    subdomain = configuration_helpers.get_value('subdomain', 'default')
    if hasattr(settings, 'COURSE_LISTINGS') and subdomain in settings.COURSE_LISTINGS and not settings.DEBUG:
        filtered_visible_ids = frozenset(
            [CourseKey.from_string(c) for c in settings.COURSE_LISTINGS[subdomain]]
        )

    if filtered_visible_ids:
        return courses.filter(id__in=filtered_visible_ids)
    else:
        # Filter out any courses based on current org, to avoid leaking these.
        orgs = configuration_helpers.get_all_orgs()
        return courses.exclude(org__in=orgs)
コード例 #11
0
def get_visible_courses(org=None, filter_=None):
    """
    Return the set of CourseOverviews that should be visible in this branded
    instance.

    Arguments:
        org (string): Optional parameter that allows case-insensitive
            filtering by organization.
        filter_ (dict): Optional parameter that allows custom filtering by
            fields on the course.
    """
    current_site_org = configuration_helpers.get_value('course_org_filter')

    if org and current_site_org:
        # Return an empty result if the org passed by the caller does not match the designated site org.
        courses = CourseOverview.get_all_courses(
            org=org,
            filter_=filter_,
        ) if org == current_site_org else []
    else:
        # We only make it to this point if one of org or current_site_org is defined.
        # If both org and current_site_org were defined, the code would have fallen into the
        # first branch of the conditional above, wherein an equality check is performed.
        target_org = org or current_site_org
        courses = CourseOverview.get_all_courses(org=target_org, filter_=filter_)

    courses = sorted(courses, key=lambda course: course.number)

    # Filtering can stop here.
    if current_site_org:
        return courses

    # See if we have filtered course listings in this domain
    filtered_visible_ids = None

    # this is legacy format, which also handle dev case, which should not filter
    subdomain = configuration_helpers.get_value('subdomain', 'default')
    if hasattr(settings, 'COURSE_LISTINGS') and subdomain in settings.COURSE_LISTINGS and not settings.DEBUG:
        filtered_visible_ids = frozenset(
            [SlashSeparatedCourseKey.from_deprecated_string(c) for c in settings.COURSE_LISTINGS[subdomain]]
        )

    if filtered_visible_ids:
        return [course for course in courses if course.id in filtered_visible_ids]
    else:
        # Filter out any courses based on current org, to avoid leaking these.
        orgs = configuration_helpers.get_all_orgs()
        return [course for course in courses if course.location.org not in orgs]
コード例 #12
0
def get_visible_courses(org=None, filter_=None):
    """
    Return the set of CourseOverviews that should be visible in this branded
    instance.

    Arguments:
        org (string): Optional parameter that allows case-insensitive
            filtering by organization.
        filter_ (dict): Optional parameter that allows custom filtering by
            fields on the course.
    """
    courses = []
    current_site_orgs = configuration_helpers.get_current_site_orgs()

    if org:
        # Check the current site's orgs to make sure the org's courses should be displayed
        if not current_site_orgs or org in current_site_orgs:
            courses = CourseOverview.get_all_courses(orgs=[org], filter_=filter_)
    elif current_site_orgs:
        # Only display courses that should be displayed on this site
        courses = CourseOverview.get_all_courses(orgs=current_site_orgs, filter_=filter_)
    else:
        courses = CourseOverview.get_all_courses(filter_=filter_)

    courses = sorted(courses, key=lambda course: course.number)

    # Filtering can stop here.
    if current_site_orgs:
        return courses

    # See if we have filtered course listings in this domain
    filtered_visible_ids = None

    # this is legacy format, which also handle dev case, which should not filter
    subdomain = configuration_helpers.get_value('subdomain', 'default')
    if hasattr(settings, 'COURSE_LISTINGS') and subdomain in settings.COURSE_LISTINGS and not settings.DEBUG:
        filtered_visible_ids = frozenset(
            [SlashSeparatedCourseKey.from_deprecated_string(c) for c in settings.COURSE_LISTINGS[subdomain]]
        )

    if filtered_visible_ids:
        return [course for course in courses if course.id in filtered_visible_ids]
    else:
        # Filter out any courses based on current org, to avoid leaking these.
        orgs = configuration_helpers.get_all_orgs()
        return [course for course in courses if course.location.org not in orgs]
コード例 #13
0
    def exclude_dictionary(self, **kwargs):
        """
            Exclude any courses defined outside the current org.
        """
        exclude_dictionary = super().exclude_dictionary(**kwargs)
        course_org_filter = configuration_helpers.get_current_site_orgs()
        # If we have a course filter we are ensuring that we only get those courses above
        if not course_org_filter:
            org_filter_out_set = configuration_helpers.get_all_orgs()
            if org_filter_out_set:
                exclude_dictionary['org'] = list(org_filter_out_set)

        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",
                       True):
            exclude_dictionary['catalog_visibility'] = 'none'

        return exclude_dictionary
コード例 #14
0
ファイル: coursekey_h_v1.py プロジェクト: saltfun/eox-core
def validate_org(course_id):
    """
    Validate the course organization against all possible orgs for the site

    To determine if the Org is valid we must look at 3 things
    1 Orgs in the current site
    2 Orgs in other sites
    3 flag EOX_CORE_USER_ENABLE_MULTI_TENANCY
    """

    if not settings.EOX_CORE_USER_ENABLE_MULTI_TENANCY:
        return True

    course_key = get_valid_course_key(course_id)
    current_site_orgs = get_current_site_orgs() or []

    if not current_site_orgs:
        if course_key.org in get_all_orgs():
            return False
        return True
    else:
        return course_key.org in current_site_orgs
コード例 #15
0
def get_org_black_and_whitelist_for_site():
    """
    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
コード例 #16
0
ファイル: dashboard.py プロジェクト: luisvasq/edx-platform
def get_org_black_and_whitelist_for_site():
    """
    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