Adds CouseModule.course_visibility and XBlock.public_view() for unenrolled users access to courses.

The course_visiblity field can have one of three values:
1. private (default): This keeps the standard access rules.
2. public_outline: Allows unenrolled and anonymous users access to the outline.
3. public: Allows unenrolled and anonymous users access to both outline and
   course content.

When an unenrolled user accesses course content, instead of student_view(),
public_view() is used. A default implementation is provided for XBlocks
which do not implement this view. The public_view() must not have any
functionality which assumes the presence of a valid User and should show
a readonly only interface for the XBlock content.
This commit is contained in:
Paulo Viadanna
2018-07-05 17:45:17 -03:00
committed by Usman Khalid
parent 63b43ce4e4
commit e6e0a02e0a
21 changed files with 371 additions and 142 deletions

View File

@@ -8,6 +8,7 @@ from django.conf import settings
from edx_proctoring.api import get_attempt_status_summary
from edx_proctoring.exceptions import ProctoredExamNotFoundException
from student.models import CourseEnrollment
from openedx.core.djangoapps.content.block_structure.transformer import (
BlockStructureTransformer,
)
@@ -144,7 +145,11 @@ class MilestonesAndSpecialExamsTransformer(BlockStructureTransformer):
"""
course_key = block_structure.root_block_usage_key.course_key
user_can_skip_entrance_exam = EntranceExamConfiguration.user_can_skip_entrance_exam(usage_info.user, course_key)
user_can_skip_entrance_exam = False
is_enrolled = CourseEnrollment.is_enrolled(usage_info.user, course_key)
if is_enrolled:
user_can_skip_entrance_exam = EntranceExamConfiguration.user_can_skip_entrance_exam(
usage_info.user, course_key)
required_content = milestones_helpers.get_required_content(course_key, usage_info.user)
if not required_content:

View File

@@ -162,7 +162,7 @@ class MilestonesTransformerTestCase(CourseStructureTestCase, MilestonesTestCaseM
self.course.enable_subsection_gating = True
self.setup_gated_section(self.blocks[gated_block_ref], self.blocks[gating_block_ref])
with self.assertNumQueries(6):
with self.assertNumQueries(7):
self.get_blocks_and_check_against_expected(self.user, expected_blocks_before_completion)
# clear the request cache to simulate a new request
@@ -175,7 +175,7 @@ class MilestonesTransformerTestCase(CourseStructureTestCase, MilestonesTestCaseM
self.user,
)
with self.assertNumQueries(6):
with self.assertNumQueries(7):
self.get_blocks_and_check_against_expected(self.user, self.ALL_BLOCKS_EXCEPT_SPECIAL)
def test_staff_access(self):