Merge pull request #19452 from edx/REVE-132
Ensure masquerade works in courses that haven't started yet
This commit is contained in:
@@ -240,7 +240,7 @@ class TestFieldOverrideMongoPerformance(FieldOverridePerformanceTestCase):
|
||||
__test__ = True
|
||||
|
||||
# TODO: decrease query count as part of REVO-28
|
||||
QUERY_COUNT = 38
|
||||
QUERY_COUNT = 36
|
||||
TEST_DATA = {
|
||||
# (providers, course_width, enable_ccx, view_as_ccx): (
|
||||
# # of sql queries to default,
|
||||
@@ -269,7 +269,7 @@ class TestFieldOverrideSplitPerformance(FieldOverridePerformanceTestCase):
|
||||
__test__ = True
|
||||
|
||||
# TODO: decrease query count as part of REVO-28
|
||||
QUERY_COUNT = 38
|
||||
QUERY_COUNT = 36
|
||||
TEST_DATA = {
|
||||
('no_overrides', 1, True, False): (QUERY_COUNT, 3),
|
||||
('no_overrides', 2, True, False): (QUERY_COUNT, 3),
|
||||
|
||||
@@ -10,7 +10,7 @@ from django.conf import settings
|
||||
from pytz import UTC
|
||||
|
||||
from courseware.access_response import AccessResponse, StartDateError
|
||||
from courseware.masquerade import is_masquerading_as_student
|
||||
from courseware.masquerade import get_course_masquerade, is_masquerading_as_student
|
||||
from openedx.features.course_experience import COURSE_PRE_START_ACCESS_FLAG
|
||||
from student.roles import CourseBetaTesterRole
|
||||
from xmodule.util.xmodule_django import get_current_request_hostname
|
||||
@@ -65,7 +65,7 @@ def check_start_date(user, days_early_for_beta, start, course_key):
|
||||
return ACCESS_GRANTED
|
||||
else:
|
||||
now = datetime.now(UTC)
|
||||
if start is None or in_preview_mode():
|
||||
if start is None or in_preview_mode() or get_course_masquerade(user, course_key):
|
||||
return ACCESS_GRANTED
|
||||
|
||||
effective_start = adjust_start_date(user, days_early_for_beta, start, course_key)
|
||||
|
||||
@@ -1441,8 +1441,8 @@ class ProgressPageTests(ProgressPageBaseTests):
|
||||
self.assertContains(resp, u"Download Your Certificate")
|
||||
|
||||
@ddt.data(
|
||||
(True, 58),
|
||||
(False, 57)
|
||||
(True, 56),
|
||||
(False, 55)
|
||||
)
|
||||
@ddt.unpack
|
||||
def test_progress_queries_paced_courses(self, self_paced, query_count):
|
||||
@@ -1455,8 +1455,8 @@ class ProgressPageTests(ProgressPageBaseTests):
|
||||
|
||||
@patch.dict(settings.FEATURES, {'ASSUME_ZERO_GRADE_IF_ABSENT_FOR_ALL_TESTS': False})
|
||||
@ddt.data(
|
||||
(False, 65, 45),
|
||||
(True, 57, 41)
|
||||
(False, 63, 43),
|
||||
(True, 55, 39)
|
||||
)
|
||||
@ddt.unpack
|
||||
def test_progress_queries(self, enable_waffle, initial, subsequent):
|
||||
|
||||
@@ -49,7 +49,6 @@ from xmodule.course_module import COURSE_VISIBILITY_PUBLIC
|
||||
from xmodule.x_module import PUBLIC_VIEW, STUDENT_VIEW
|
||||
from .views import CourseTabView
|
||||
from ..access import has_access
|
||||
from ..access_utils import check_course_open_for_learner
|
||||
from ..courses import check_course_access, get_course_with_access, get_current_child, get_studio_url
|
||||
from ..entrance_exams import (
|
||||
course_has_entrance_exam,
|
||||
@@ -438,13 +437,6 @@ class CoursewareIndex(View):
|
||||
# entrance exam data
|
||||
self._add_entrance_exam_to_context(courseware_context)
|
||||
|
||||
# staff masquerading data
|
||||
if not check_course_open_for_learner(self.effective_user, self.course):
|
||||
# Disable student view button if user is staff and
|
||||
# course is not yet visible to students.
|
||||
courseware_context['disable_student_access'] = True
|
||||
courseware_context['supports_preview_menu'] = False
|
||||
|
||||
if self.section:
|
||||
# chromeless data
|
||||
if self.section.chrome:
|
||||
|
||||
@@ -13,7 +13,7 @@ from django.contrib.auth.models import AnonymousUser, User
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.urls import reverse
|
||||
from django.db import transaction
|
||||
from django.db.models import Q
|
||||
from django.db.models import prefetch_related_objects, Q
|
||||
from django.http import Http404, HttpResponse, HttpResponseBadRequest, HttpResponseForbidden
|
||||
from django.shortcuts import redirect
|
||||
from django.template.context_processors import csrf
|
||||
@@ -613,11 +613,6 @@ class CourseTabView(EdxFragmentView):
|
||||
else:
|
||||
masquerade = None
|
||||
|
||||
if course and not check_course_open_for_learner(request.user, course):
|
||||
# Disable student view button if user is staff and
|
||||
# course is not yet visible to students.
|
||||
supports_preview_menu = False
|
||||
|
||||
context = {
|
||||
'course': course,
|
||||
'tab': tab,
|
||||
@@ -974,7 +969,7 @@ def _progress(request, course_key, student_id):
|
||||
|
||||
# The pre-fetching of groups is done to make auth checks not require an
|
||||
# additional DB lookup (this kills the Progress page in particular).
|
||||
student = User.objects.prefetch_related("groups").get(id=student.id)
|
||||
prefetch_related_objects([student], 'groups')
|
||||
if request.user.id != student.id:
|
||||
# refetch the course as the assumed student
|
||||
course = get_course_with_access(student, 'load', course_key, check_if_enrolled=True)
|
||||
|
||||
@@ -5,7 +5,6 @@ and course access based on these limits.
|
||||
"""
|
||||
from datetime import timedelta
|
||||
|
||||
from django.apps import apps
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import get_language, ugettext as _
|
||||
|
||||
|
||||
@@ -641,8 +641,8 @@ class TestCourseOutlinePreview(SharedModuleStoreTestCase):
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, 'Future Chapter')
|
||||
|
||||
# Verify that staff masquerading as a learner does not see the future chapter.
|
||||
# Verify that staff masquerading as a learner see the future chapter.
|
||||
self.update_masquerade(course, role='student')
|
||||
response = self.client.get(url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertNotContains(response, 'Future Chapter')
|
||||
self.assertContains(response, 'Future Chapter')
|
||||
|
||||
Reference in New Issue
Block a user