Esempio n. 1
0
 def test_default_tab(self):
     # Verify that the course info tab is the first tab
     tabs = get_course_tab_list(self.user, self.course)
     # So I know this means course_info is not the first tab, but it is going to be
     # retired soon (https://openedx.atlassian.net/browse/TNL-7061) and also it has
     # a lower priority than courseware so seems odd that it would ever be first.
     # As such, I feel comfortable updating this test so it passes until it is removed
     # as part of the linked ticket
     assert tabs[1].type == 'course_info'
Esempio n. 2
0
 def test_course_tabs_list_for_staff_members(self):
     """
     Tests tab list is not limited if user is member of staff
     and has not passed entrance exam.
     """
     # Login as member of staff
     self.client.logout()
     staff_user = StaffFactory(course_key=self.course.id)
     self.client.login(username=staff_user.username, password='******')
     course_tab_list = get_course_tab_list(staff_user, self.course)
     assert len(course_tab_list) == 4
Esempio n. 3
0
 def tabs(self):
     """
     Return course tab metadata.
     """
     tabs = []
     for priority, tab in enumerate(get_course_tab_list(self.effective_user, self.overview)):
         tabs.append({
             'title': tab.title or tab.get('name', ''),
             'slug': tab.tab_id,
             'priority': priority,
             'type': tab.type,
             'url': tab.link_func(self.overview, reverse),
         })
     return tabs
Esempio n. 4
0
    def get(self, request, *args, **kwargs):
        course_key_string = kwargs.get('course_key_string')
        course_key = CourseKey.from_string(course_key_string)
        original_user_is_staff = has_access(request.user, 'staff',
                                            course_key).has_access

        _, request.user = setup_masquerade(
            request,
            course_key,
            staff_access=has_access(request.user, 'staff', course_key),
            reset_masquerade_data=True,
        )

        username = request.user.username if request.user.username else None
        course = course_detail(request, request.user.username, course_key)
        enrollment = CourseEnrollment.get_enrollment(request.user,
                                                     course_key_string)
        user_is_enrolled = bool(enrollment and enrollment.is_active)

        courseware_meta = CoursewareMeta(course_key, request,
                                         request.user.username)
        can_load_courseware = courseware_meta.is_microfrontend_enabled_for_user(
        )

        browser_timezone = self.request.query_params.get(
            'browser_timezone', None)
        celebrations = get_celebrations_dict(request.user, enrollment, course,
                                             browser_timezone)

        data = {
            'course_id': course.id,
            'username': username,
            'is_staff': has_access(request.user, 'staff',
                                   course_key).has_access,
            'original_user_is_staff': original_user_is_staff,
            'number': course.display_number_with_default,
            'org': course.display_org_with_default,
            'tabs': get_course_tab_list(request.user, course),
            'title': course.display_name_with_default,
            'is_self_paced': getattr(course, 'self_paced', False),
            'is_enrolled': user_is_enrolled,
            'can_load_courseware': can_load_courseware,
            'celebrations': celebrations,
        }
        context = self.get_serializer_context()
        context['course'] = course
        context['course_overview'] = course
        context['enrollment'] = enrollment
        serializer = self.get_serializer_class()(data, context=context)
        return Response(serializer.data)
Esempio n. 5
0
 def tabs(self):
     """
     Return course tab metadata.
     """
     tabs = []
     for priority, tab in enumerate(get_course_tab_list(self.effective_user, self.overview)):
         title = tab.title or tab.get('name', '')
         tabs.append({
             'title': _(title),  # pylint: disable=translation-of-non-string
             'slug': tab.tab_id,
             'priority': priority,
             'type': tab.type,
             'url': tab.link_func(self.overview, reverse),
         })
     return tabs
Esempio n. 6
0
def _has_page_access(request, course_id):
    """
        Check if tab is enabled and user is enrolled
    """ 
    course_key = CourseKey.from_string(course_id)
    course = get_course_with_access(request.user, "load", course_key)
    tabs = get_course_tab_list(request.user, course)
    tabs_list = [tab.tab_id for tab in tabs]
    if 'eol_course_email' not in tabs_list:
        return False
    return User.objects.filter(
        courseenrollment__course_id=course_key,
        courseenrollment__is_active=1,
        pk = request.user.id
    ).exists()
Esempio n. 7
0
 def get_tabs(self, course_overview):
     """
     Return course tab metadata.
     """
     tabs = []
     for priority, tab in enumerate(
             get_course_tab_list(course_overview.effective_user,
                                 course_overview)):
         tabs.append({
             'title': tab.title,
             'slug': tab.tab_id,
             'priority': priority,
             'type': tab.type,
             'url': tab.link_func(course_overview, reverse),
         })
     return tabs
Esempio n. 8
0
    def get(self, request, *args, **kwargs):
        course_key_string = kwargs.get('course_key_string')
        course_key = CourseKey.from_string(course_key_string)
        course = course_detail(request, request.user.username, course_key)

        data = {
            'course_id': course.id,
            'is_staff': has_access(request.user, 'staff', course_key).has_access,
            'number': course.display_number_with_default,
            'org': course.display_org_with_default,
            'tabs': get_course_tab_list(request.user, course),
            'title': course.display_name_with_default,
        }
        context = self.get_serializer_context()
        context['course'] = course
        serializer = self.get_serializer_class()(data, context=context)
        return Response(serializer.data)
Esempio n. 9
0
    def test_singular_dates_tab(self):
        """Test cases for making sure no persisted dates tab is surfaced"""
        user = self.create_mock_user()
        self.course.tabs = self.all_valid_tab_list
        self.course.save()

        # Verify that there is a dates tab in the modulestore
        has_dates_tab = False
        for tab in self.course.tabs:
            if tab.type == 'dates':
                has_dates_tab = True
        assert has_dates_tab

        # Verify that there is only 1 'dates' tab in the returned result from get_course_tab_list()
        tabs = get_course_tab_list(user, self.course)
        num_dates_tabs = 0
        for tab in tabs:
            if tab.type == 'dates':
                num_dates_tabs += 1
        assert num_dates_tabs == 1
Esempio n. 10
0
 def test_pdf_textbook_tabs(self):
     """
     Test that all textbooks tab links generating correctly.
     """
     type_to_reverse_name = {'textbook': 'book', 'pdftextbook': 'pdf_book', 'htmltextbook': 'html_book'}
     self.addCleanup(set_current_request, None)
     course_tab_list = get_course_tab_list(self.user, self.course)
     num_of_textbooks_found = 0
     for tab in course_tab_list:
         # Verify links of all textbook type tabs.
         if tab.type == 'single_textbook':
             book_type, book_index = tab.tab_id.split("/", 1)
             expected_link = reverse(
                 type_to_reverse_name[book_type],
                 args=[str(self.course.id), book_index]
             )
             tab_link = tab.link_func(self.course, reverse)
             assert tab_link == expected_link
             num_of_textbooks_found += 1
     assert num_of_textbooks_found == self.num_textbooks
Esempio n. 11
0
def _has_page_access(user, course_id):
    """
        Check if tab is enabled and user is enrolled
    """ 
    course_key = CourseKey.from_string(course_id)
    course = get_course_with_access(user, "load", course_key)

    if bool(has_access(user, 'staff', course)):
        return True # Allow page access to staff
    
    tabs = get_course_tab_list(user, course)
    tabs_list = [tab.tab_id for tab in tabs]
    if 'eol_progress_tab' not in tabs_list:
        return False

    return User.objects.filter(
        courseenrollment__course_id=course_key,
        courseenrollment__is_active=1,
        pk = user.id
    ).exists()
Esempio n. 12
0
    def test_singular_dates_tab(self, mock_flag):
        """Test cases for making sure no persisted dates tab is surfaced"""
        mock_flag.is_enabled().return_value = True
        user = self.create_mock_user()
        self.course.tabs = self.all_valid_tab_list
        self.course.save()

        # Verify that there is a dates tab in the modulestore
        has_dates_tab = False
        for tab in self.course.tabs:
            if tab.type == 'dates':
                has_dates_tab = True
        self.assertTrue(has_dates_tab)

        # Verify that there is only 1 'dates' tab in the returned result from get_course_tab_list()
        tabs = get_course_tab_list(user, self.course)
        num_dates_tabs = 0
        for tab in tabs:
            if tab.type == 'dates':
                num_dates_tabs += 1
        self.assertEqual(num_dates_tabs, 1)
Esempio n. 13
0
    def test_get_course_tabs_list_skipped_entrance_exam(self):
        """
        Tests tab list is not limited if user is allowed to skip entrance exam.
        """
        #create a user
        student = UserFactory()
        # login as instructor hit skip entrance exam api in instructor app
        instructor = InstructorFactory(course_key=self.course.id)
        self.client.logout()
        self.client.login(username=instructor.username, password='******')

        url = reverse('mark_student_can_skip_entrance_exam', kwargs={'course_id': str(self.course.id)})
        response = self.client.post(url, {
            'unique_student_identifier': student.email,
        })
        assert response.status_code == 200

        # log in again as student
        self.client.logout()
        self.login(self.email, self.password)
        course_tab_list = get_course_tab_list(self.user, self.course)
        assert len(course_tab_list) == 4
Esempio n. 14
0
    def test_singular_dates_tab(self):
        user = self.create_mock_user()
        self.course.tabs = self.all_valid_tab_list
        self.course.save()

        # Verify that there is a dates tab in the modulestore
        has_dates_tab = False
        for tab in self.course.tabs:
            if tab.type == 'dates':
                has_dates_tab = True
        self.assertTrue(has_dates_tab)

        # Verify that there is only 1 'dates' tab in the returned result from get_course_tab_list()
        with patch('lms.djangoapps.courseware.tabs.RELATIVE_DATES_FLAG'
                   ) as mock_flag:
            mock_flag.is_enabled().return_value = True
            tabs = get_course_tab_list(user, self.course)
            num_dates_tabs = 0
            for tab in tabs:
                if tab.type == 'dates':
                    num_dates_tabs += 1
            self.assertEqual(num_dates_tabs, 1)
Esempio n. 15
0
 def test_get_course_tabs_list_entrance_exam_enabled(self):
     """
     Unit Test: test_get_course_tabs_list_entrance_exam_enabled
     """
     entrance_exam = ItemFactory.create(
         category="chapter",
         parent_location=self.course.location,
         data="Exam Data",
         display_name="Entrance Exam",
         is_entrance_exam=True
     )
     milestone = {
         'name': 'Test Milestone',
         'namespace': '{}.entrance_exams'.format(six.text_type(self.course.id)),
         'description': 'Testing Courseware Tabs'
     }
     self.user.is_staff = False
     request = get_mock_request(self.user)
     self.course.entrance_exam_enabled = True
     self.course.entrance_exam_id = six.text_type(entrance_exam.location)
     milestone = add_milestone(milestone)
     add_course_milestone(
         six.text_type(self.course.id),
         self.relationship_types['REQUIRES'],
         milestone
     )
     add_course_content_milestone(
         six.text_type(self.course.id),
         six.text_type(entrance_exam.location),
         self.relationship_types['FULFILLS'],
         milestone
     )
     course_tab_list = get_course_tab_list(request, self.course)
     self.assertEqual(len(course_tab_list), 1)
     self.assertEqual(course_tab_list[0]['tab_id'], 'courseware')
     self.assertEqual(course_tab_list[0]['name'], 'Entrance Exam')
Esempio n. 16
0
    def get(self, request, *args, **kwargs):
        course_key_string = kwargs.get('course_key_string')
        course_key = CourseKey.from_string(course_key_string)
        original_user_is_staff = has_access(request.user, 'staff', course_key).has_access

        _, request.user = setup_masquerade(
            request,
            course_key,
            staff_access=has_access(request.user, 'staff', course_key),
            reset_masquerade_data=True,
        )

        course = course_detail(request, request.user.username, course_key)
        user_is_enrolled = CourseEnrollment.is_enrolled(request.user, course_key_string)
        browser_timezone = request.query_params.get('browser_timezone', None)
        celebrations = {
            'streak_length_to_celebrate': UserCelebration.perform_streak_updates(
                request.user, course_key, browser_timezone
            )
        }
        data = {
            'course_id': course.id,
            'is_staff': has_access(request.user, 'staff', course_key).has_access,
            'original_user_is_staff': original_user_is_staff,
            'number': course.display_number_with_default,
            'org': course.display_org_with_default,
            'tabs': get_course_tab_list(request.user, course),
            'title': course.display_name_with_default,
            'is_self_paced': getattr(course, 'self_paced', False),
            'is_enrolled': user_is_enrolled,
            'celebrations': celebrations,
        }
        context = self.get_serializer_context()
        context['course'] = course
        serializer = self.get_serializer_class()(data, context=context)
        return Response(serializer.data)
Esempio n. 17
0
 def get_wiki_tab(self, user, course):
     """Returns true if the "Wiki" tab is shown."""
     request = RequestFactory().request()
     all_tabs = get_course_tab_list(user, course)
     wiki_tabs = [tab for tab in all_tabs if tab.name == 'Wiki']
     return wiki_tabs[0] if len(wiki_tabs) == 1 else None
Esempio n. 18
0
 def check_ccx_tab(self, course, user):
     """Helper function for verifying the ccx tab."""
     all_tabs = get_course_tab_list(user, course)
     return any(tab.type == 'ccx_coach' for tab in all_tabs)
Esempio n. 19
0
 def test_default_tab(self):
     # Verify that the course info tab is the first tab
     tabs = get_course_tab_list(self.request, self.course)
     self.assertEqual(tabs[0].type, 'course_info')
Esempio n. 20
0
    def get(self, request, *args, **kwargs):
        course_key_string = kwargs.get('course_key_string')
        course_key = CourseKey.from_string(course_key_string)
        original_user_is_global_staff = self.request.user.is_staff
        original_user_is_staff = has_access(request.user, 'staff',
                                            course_key).has_access

        course = course_detail(request, request.user.username, course_key)

        # We must compute course load access *before* setting up masquerading,
        # else course staff (who are not enrolled) will not be able view
        # their course from the perspective of a learner.
        load_access = check_course_access(
            course,
            request.user,
            'load',
            check_if_enrolled=True,
            check_if_authenticated=True,
        )

        _, request.user = setup_masquerade(
            request,
            course_key,
            staff_access=original_user_is_staff,
            reset_masquerade_data=True,
        )

        username = request.user.username if request.user.username else None
        enrollment = CourseEnrollment.get_enrollment(request.user,
                                                     course_key_string)
        user_is_enrolled = bool(enrollment and enrollment.is_active)

        can_load_courseware = courseware_mfe_is_visible(
            course_key=course_key,
            is_global_staff=original_user_is_global_staff,
            is_course_staff=original_user_is_staff)

        # User locale settings
        user_timezone_locale = user_timezone_locale_prefs(request)
        user_timezone = user_timezone_locale['user_timezone']

        browser_timezone = self.request.query_params.get(
            'browser_timezone', None)
        celebrations = get_celebrations_dict(
            request.user, enrollment, course,
            user_timezone if not None else browser_timezone)

        # Record course goals user activity for (web) learning mfe course tabs
        UserActivity.record_user_activity(request.user, course_key)

        data = {
            'course_id': course.id,
            'username': username,
            'is_staff': has_access(request.user, 'staff',
                                   course_key).has_access,
            'original_user_is_staff': original_user_is_staff,
            'number': course.display_number_with_default,
            'org': course.display_org_with_default,
            'start': course.start,
            'tabs': get_course_tab_list(request.user, course),
            'title': course.display_name_with_default,
            'is_self_paced': getattr(course, 'self_paced', False),
            'is_enrolled': user_is_enrolled,
            'course_access': load_access.to_json(),
            'can_load_courseware': can_load_courseware,
            'celebrations': celebrations,
            'user_timezone': user_timezone,
        }
        context = self.get_serializer_context()
        context['course'] = course
        context['course_overview'] = course
        context['enrollment'] = enrollment
        serializer = self.get_serializer_class()(data, context=context)
        return Response(serializer.data)
 def has_instructor_tab(user, course):
     """Returns true if the "Instructor" tab is shown."""
     request = RequestFactory().request()
     request.user = user
     tabs = get_course_tab_list(request, course)
     return len([tab for tab in tabs if tab.name == 'Instructor']) == 1
Esempio n. 22
0
 def test_default_tab_for_new_course_experience(self):
     # Verify that the unified course experience hides the course info tab
     tabs = get_course_tab_list(self.user, self.course)
     assert tabs[0].type == 'courseware'
Esempio n. 23
0
 def test_default_tab_for_new_course_experience(self):
     # Verify that the unified course experience hides the course info tab
     tabs = get_course_tab_list(self.request, self.course)
     self.assertEqual(tabs[0].type, 'courseware')
Esempio n. 24
0
 def get_wiki_tab(self, user, course):
     """Returns wiki tab if it is shown."""
     all_tabs = get_course_tab_list(user, course)
     return next((tab for tab in all_tabs if tab.type == 'wiki'), None)
Esempio n. 25
0
 def has_instructor_tab(user, course):
     """Returns true if the "Instructor" tab is shown."""
     tabs = get_course_tab_list(user, course)
     return len([tab for tab in tabs if tab.name == 'Instructor']) == 1
Esempio n. 26
0
 def test_default_tab(self):
     # Verify that the course info tab is the first tab
     tabs = get_course_tab_list(self.user, self.course)
     assert tabs[0].type == 'course_info'