Example #1
0
def get_course_tab_list(user, course):
    """
    Retrieves the course tab list from xmodule.tabs and manipulates the set as necessary
    """
    xmodule_tab_list = CourseTabList.iterate_displayable(course, user=user)

    # Now that we've loaded the tabs for this course, perform the Entrance Exam work.
    # If the user has to take an entrance exam, we'll need to hide away all but the
    # "Courseware" tab. The tab is then renamed as "Entrance Exam".
    course_tab_list = []
    must_complete_ee = not user_can_skip_entrance_exam(user, course)
    for tab in xmodule_tab_list:
        if must_complete_ee:
            # Hide all of the tabs except for 'Courseware'
            # Rename 'Courseware' tab to 'Entrance Exam'
            if tab.type != 'courseware':
                continue
            tab.name = _("Entrance Exam")
        # TODO: LEARNER-611 - once the course_info tab is removed, remove this code
        if not DISABLE_UNIFIED_COURSE_TAB_FLAG.is_enabled(course.id) and tab.type == 'course_info':
            continue
        if tab.type == 'static_tab' and tab.course_staff_only and \
                not bool(user and has_access(user, 'staff', course, course.id)):
            continue
        # We had initially created a CourseTab.load() for dates that ended up
        # persisting the dates tab tomodulestore on Course Run creation, but
        # ignoring any static dates tab here we can fix forward without
        # allowing the bug to continue to surface
        if tab.type == 'dates':
            continue
        course_tab_list.append(tab)

    # Add in any dynamic tabs, i.e. those that are not persisted
    course_tab_list += _get_dynamic_tabs(course, user)
    # Sorting here because although the CourseTabPluginManager.get_tab_types function
    # does do sorting on priority, we only use it for getting the dynamic tabs.
    # We can't switch this function to just use the CourseTabPluginManager without
    # further investigation since CourseTabList.iterate_displayable returns
    # Static Tabs that are not returned by the CourseTabPluginManager.
    course_tab_list.sort(key=lambda tab: tab.priority or float('inf'))
    return course_tab_list
 def test_can_skip_entrance_exam_with_anonymous_user(self):
     """
     Test can_skip_entrance_exam method with anonymous user
     """
     assert not user_can_skip_entrance_exam(self.anonymous_user, self.course)