Merge pull request #25661 from edx/ciduarte/AA-131

AA-131: Allow anonymous users through course home MFE
This commit is contained in:
Carla Duarte
2020-12-16 15:49:20 -05:00
committed by GitHub
12 changed files with 122 additions and 91 deletions

View File

@@ -47,6 +47,7 @@ from common.djangoapps.student.models import (
)
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.search import path_to_location
from xmodule.x_module import PUBLIC_VIEW, STUDENT_VIEW
from .serializers import CourseInfoSerializer
from .utils import serialize_upgrade_info
@@ -483,7 +484,12 @@ class SequenceMetadata(DeveloperErrorViewMixin, APIView):
str(usage_key.course_key),
str(usage_key),
disable_staff_debug_info=True)
return Response(json.loads(sequence.handle_ajax('metadata', None)))
view = STUDENT_VIEW
if request.user.is_anonymous:
view = PUBLIC_VIEW
return Response(json.loads(sequence.handle_ajax('metadata', None, view=view)))
class Resume(DeveloperErrorViewMixin, APIView):

View File

@@ -12,7 +12,6 @@ from django.utils.translation import get_language_bidi
from opaque_keys.edx.keys import CourseKey
from web_fragments.fragment import Fragment
from lms.djangoapps.courseware.access import has_access
from lms.djangoapps.courseware.courses import get_course_date_blocks, get_course_with_access
from lms.djangoapps.courseware.tabs import DatesTab
from lms.djangoapps.course_home_api.toggles import course_home_mfe_dates_tab_is_active

View File

@@ -14,16 +14,17 @@ from django.views.decorators.csrf import ensure_csrf_cookie
from opaque_keys.edx.keys import CourseKey
from web_fragments.fragment import Fragment
from lms.djangoapps.course_home_api.toggles import course_home_mfe_outline_tab_is_active
from lms.djangoapps.course_home_api.utils import get_microfrontend_url
from lms.djangoapps.courseware.access import has_access
from lms.djangoapps.courseware.courses import can_self_enroll_in_course, get_course_info_section, get_course_with_access
from lms.djangoapps.commerce.utils import EcommerceService
from lms.djangoapps.course_goals.api import (
get_course_goal,
get_course_goal_options,
get_goal_api_url,
has_course_goal_permission
)
from lms.djangoapps.courseware.exceptions import CourseAccessRedirect
from lms.djangoapps.courseware.exceptions import CourseAccessRedirect, Redirect
from lms.djangoapps.courseware.utils import can_show_verified_upgrade, verified_upgrade_deadline_link
from lms.djangoapps.courseware.views.views import CourseTabView
from lms.djangoapps.courseware.toggles import COURSEWARE_PROCTORING_IMPROVEMENTS
@@ -70,6 +71,9 @@ class CourseHomeView(CourseTabView):
def render_to_fragment(self, request, course=None, tab=None, **kwargs):
course_id = six.text_type(course.id)
if course_home_mfe_outline_tab_is_active(course.id) and not request.user.is_staff:
microfrontend_url = get_microfrontend_url(course_key=course_id, view_name="home")
raise Redirect(microfrontend_url)
home_fragment_view = CourseHomeFragmentView()
return home_fragment_view.render_to_fragment(request, course_id=course_id, **kwargs)

View File

@@ -150,7 +150,7 @@ def _is_in_holdback_and_bucket(user):
return False
# Holdback is 10%
bucket = stable_bucketing_hash_group(DISCOUNT_APPLICABILITY_HOLDBACK, 10, user.username)
bucket = stable_bucketing_hash_group(DISCOUNT_APPLICABILITY_HOLDBACK, 10, user)
request = get_current_request()
if hasattr(request, 'session') and DISCOUNT_APPLICABILITY_HOLDBACK not in request.session: