diff --git a/lms/djangoapps/ccx/tests/test_views.py b/lms/djangoapps/ccx/tests/test_views.py index 27e9d89bb4..ec7373edc0 100644 --- a/lms/djangoapps/ccx/tests/test_views.py +++ b/lms/djangoapps/ccx/tests/test_views.py @@ -1156,9 +1156,7 @@ class CCXCoachTabTestCase(CcxTestCase): def check_ccx_tab(self, course, user): """Helper function for verifying the ccx tab.""" - request = RequestFactory().request() - request.user = user - all_tabs = get_course_tab_list(request, course) + all_tabs = get_course_tab_list(user, course) return any(tab.type == 'ccx_coach' for tab in all_tabs) @ddt.data( diff --git a/lms/djangoapps/course_api/api.py b/lms/djangoapps/course_api/api.py index 37406e2033..f86f6f5e0a 100644 --- a/lms/djangoapps/course_api/api.py +++ b/lms/djangoapps/course_api/api.py @@ -65,11 +65,13 @@ def course_detail(request, username, course_key): `CourseOverview` object representing the requested course """ user = get_effective_user(request.user, username) - return get_course_overview_with_access( + overview = get_course_overview_with_access( user, get_permission_for_course_about(), course_key, ) + overview.effective_user = user + return overview def _filter_by_role(course_queryset, user, roles): diff --git a/lms/djangoapps/course_api/views.py b/lms/djangoapps/course_api/views.py index 762727dd02..7320fea86e 100644 --- a/lms/djangoapps/course_api/views.py +++ b/lms/djangoapps/course_api/views.py @@ -5,6 +5,7 @@ Course API Views from django.core.exceptions import ValidationError from edx_django_utils.monitoring import set_custom_metric + from edx_rest_framework_extensions.paginators import NamespacedPageNumberPagination from rest_framework.generics import ListAPIView, RetrieveAPIView from rest_framework.throttling import UserRateThrottle diff --git a/lms/djangoapps/course_wiki/tests/test_tab.py b/lms/djangoapps/course_wiki/tests/test_tab.py index 1ece82e07e..4fb9b12e29 100644 --- a/lms/djangoapps/course_wiki/tests/test_tab.py +++ b/lms/djangoapps/course_wiki/tests/test_tab.py @@ -24,8 +24,7 @@ class WikiTabTestCase(ModuleStoreTestCase): def get_wiki_tab(self, user, course): """Returns true if the "Wiki" tab is shown.""" request = RequestFactory().request() - request.user = user - all_tabs = get_course_tab_list(request, course) + 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 diff --git a/lms/djangoapps/courseware/entrance_exams.py b/lms/djangoapps/courseware/entrance_exams.py index 381ab1708d..0f87090517 100644 --- a/lms/djangoapps/courseware/entrance_exams.py +++ b/lms/djangoapps/courseware/entrance_exams.py @@ -17,7 +17,8 @@ def course_has_entrance_exam(course): """ if not is_entrance_exams_enabled(): return False - if not course.entrance_exam_enabled: + entrance_exam_enabled = getattr(course, 'entrance_exam_enabled', None) + if not entrance_exam_enabled: return False if not course.entrance_exam_id: return False diff --git a/lms/djangoapps/courseware/tabs.py b/lms/djangoapps/courseware/tabs.py index 4d8704642a..0d075e5325 100644 --- a/lms/djangoapps/courseware/tabs.py +++ b/lms/djangoapps/courseware/tabs.py @@ -307,11 +307,10 @@ class SingleTextbookTab(CourseTab): raise NotImplementedError('SingleTextbookTab should not be serialized.') -def get_course_tab_list(request, course): +def get_course_tab_list(user, course): """ Retrieves the course tab list from xmodule.tabs and manipulates the set as necessary """ - user = request.user xmodule_tab_list = CourseTabList.iterate_displayable(course, user=user) # Now that we've loaded the tabs for this course, perform the Entrance Exam work. diff --git a/lms/djangoapps/courseware/tests/test_tabs.py b/lms/djangoapps/courseware/tests/test_tabs.py index 16e28c820b..0516ca00cc 100644 --- a/lms/djangoapps/courseware/tests/test_tabs.py +++ b/lms/djangoapps/courseware/tests/test_tabs.py @@ -385,7 +385,6 @@ class EntranceExamsTabsTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase, Mi '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) @@ -400,7 +399,7 @@ class EntranceExamsTabsTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase, Mi self.relationship_types['FULFILLS'], milestone ) - course_tab_list = get_course_tab_list(request, self.course) + course_tab_list = get_course_tab_list(self.user, 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') @@ -425,8 +424,7 @@ class EntranceExamsTabsTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase, Mi # log in again as student self.client.logout() self.login(self.email, self.password) - request = get_mock_request(self.user) - course_tab_list = get_course_tab_list(request, self.course) + course_tab_list = get_course_tab_list(self.user, self.course) self.assertEqual(len(course_tab_list), 4) def test_course_tabs_list_for_staff_members(self): @@ -438,8 +436,7 @@ class EntranceExamsTabsTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase, Mi self.client.logout() staff_user = StaffFactory(course_key=self.course.id) self.client.login(username=staff_user.username, password='test') - request = get_mock_request(staff_user) - course_tab_list = get_course_tab_list(request, self.course) + course_tab_list = get_course_tab_list(staff_user, self.course) self.assertEqual(len(course_tab_list), 4) @@ -480,8 +477,7 @@ class TextBookCourseViewsTestCase(LoginEnrollmentTestCase, SharedModuleStoreTest """ type_to_reverse_name = {'textbook': 'book', 'pdftextbook': 'pdf_book', 'htmltextbook': 'html_book'} self.addCleanup(set_current_request, None) - request = get_mock_request(self.user) - course_tab_list = get_course_tab_list(request, self.course) + 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. @@ -706,8 +702,7 @@ class CourseTabListTestCase(TabListTestCase): user = self.create_mock_user(is_staff=False, is_enrolled=True) self.addCleanup(set_current_request, None) - request = get_mock_request(user) - course_tab_list = get_course_tab_list(request, self.course) + course_tab_list = get_course_tab_list(user, self.course) name_list = [x.name for x in course_tab_list] self.assertIn('Static Tab Free', name_list) self.assertNotIn('Static Tab Instructors Only', name_list) @@ -716,8 +711,7 @@ class CourseTabListTestCase(TabListTestCase): self.client.logout() staff_user = StaffFactory(course_key=self.course.id) self.client.login(username=staff_user.username, password='test') - request = get_mock_request(staff_user) - course_tab_list_staff = get_course_tab_list(request, self.course) + course_tab_list_staff = get_course_tab_list(staff_user, self.course) name_list_staff = [x.name for x in course_tab_list_staff] self.assertIn('Static Tab Free', name_list_staff) self.assertIn('Static Tab Instructors Only', name_list_staff) @@ -775,18 +769,17 @@ class CourseInfoTabTestCase(TabTestCase): def setUp(self): self.user = self.create_mock_user() self.addCleanup(set_current_request, None) - self.request = get_mock_request(self.user) @override_waffle_flag(UNIFIED_COURSE_TAB_FLAG, active=False) def test_default_tab(self): # Verify that the course info tab is the first tab - tabs = get_course_tab_list(self.request, self.course) + tabs = get_course_tab_list(self.user, self.course) self.assertEqual(tabs[0].type, 'course_info') @override_waffle_flag(UNIFIED_COURSE_TAB_FLAG, active=True) 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) + tabs = get_course_tab_list(self.user, self.course) self.assertEqual(tabs[0].type, 'courseware') # TODO: LEARNER-611 - remove once course_info is removed. diff --git a/lms/djangoapps/discussion/django_comment_client/tests/test_utils.py b/lms/djangoapps/discussion/django_comment_client/tests/test_utils.py index 960f7997ff..762e5d070a 100644 --- a/lms/djangoapps/discussion/django_comment_client/tests/test_utils.py +++ b/lms/djangoapps/discussion/django_comment_client/tests/test_utils.py @@ -1248,8 +1248,7 @@ class DiscussionTabTestCase(ModuleStoreTestCase): def discussion_tab_present(self, user): """ Returns true if the user has access to the discussion tab. """ request = RequestFactory().request() - request.user = user - all_tabs = get_course_tab_list(request, self.course) + all_tabs = get_course_tab_list(user, self.course) return any(tab.type == 'discussion' for tab in all_tabs) def test_tab_access(self): diff --git a/lms/djangoapps/edxnotes/tests.py b/lms/djangoapps/edxnotes/tests.py index de11662ddd..8fce8bc8d7 100644 --- a/lms/djangoapps/edxnotes/tests.py +++ b/lms/djangoapps/edxnotes/tests.py @@ -1003,9 +1003,7 @@ class EdxNotesViewsTest(ModuleStoreTestCase): """ def has_notes_tab(user, course): """Returns true if the "Notes" tab is shown.""" - request = RequestFactory().request() - request.user = user - tabs = get_course_tab_list(request, course) + tabs = get_course_tab_list(user, course) return len([tab for tab in tabs if tab.type == 'edxnotes']) == 1 self.assertFalse(has_notes_tab(self.user, self.course)) diff --git a/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py b/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py index f3ee5954e5..ecf76df5ee 100644 --- a/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py +++ b/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py @@ -107,9 +107,7 @@ class TestInstructorDashboard(ModuleStoreTestCase, LoginEnrollmentTestCase, XssT """ 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) + tabs = get_course_tab_list(user, course) return len([tab for tab in tabs if tab.name == 'Instructor']) == 1 self.assertTrue(has_instructor_tab(self.instructor, self.course)) diff --git a/lms/templates/courseware/course_navigation.html b/lms/templates/courseware/course_navigation.html index 5946d7319b..16257629c7 100644 --- a/lms/templates/courseware/course_navigation.html +++ b/lms/templates/courseware/course_navigation.html @@ -35,7 +35,7 @@ if course is not None: % if disable_tabs is UNDEFINED or not disable_tabs: <% - tab_list = get_course_tab_list(request, course) + tab_list = get_course_tab_list(request.user, course) %> % if uses_bootstrap: