Skip to content

Commit

Permalink
fix: [AXIMST-10] Redirect unit page if flag MFE enabled (#2487)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruzniaievdm authored and monteri committed Jan 10, 2024
1 parent 0e200cc commit 5fbe4ee
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 21 deletions.
17 changes: 14 additions & 3 deletions cms/djangoapps/contentstore/rest_api/v1/views/vertical_block.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
""" API Views for unit page """

import edx_api_doc_tools as apidocs
from django.http import Http404
from django.http import Http404, HttpResponseBadRequest
from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import UsageKey
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.views import APIView

from cms.djangoapps.contentstore.utils import get_container_handler_context
from cms.djangoapps.contentstore.views.component import _get_item_in_course
from cms.djangoapps.contentstore.rest_api.v1.serializers import ContainerHandlerSerializer
from openedx.core.lib.api.view_utils import view_auth_classes
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.modulestore.exceptions import ItemNotFoundError # lint-amnesty, pylint: disable=wrong-import-order


@view_auth_classes(is_authenticated=True)
Expand Down Expand Up @@ -127,6 +129,15 @@ def get(self, request: Request, usage_key_string: str):
usage_key = self.get_object(usage_key_string)
course_key = usage_key.course_key
with modulestore().bulk_operations(course_key):
context = get_container_handler_context(request, usage_key)
try:
course, xblock, lms_link, preview_lms_link = _get_item_in_course(request, usage_key)
except ItemNotFoundError:
return HttpResponseBadRequest()

context = get_container_handler_context(request, usage_key, course, xblock)
context.update({
'draft_preview_link': preview_lms_link,
'published_preview_link': lms_link,
})
serializer = ContainerHandlerSerializer(context)
return Response(serializer.data)
15 changes: 1 addition & 14 deletions cms/djangoapps/contentstore/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

from django.conf import settings
from django.core.exceptions import ValidationError
from django.http import HttpResponseBadRequest
from django.shortcuts import redirect
from django.urls import reverse
from django.utils import translation
from django.utils.translation import gettext as _
Expand Down Expand Up @@ -1787,14 +1785,13 @@ def _get_course_index_context(request, course_key, course_block):
return course_index_context


def get_container_handler_context(request, usage_key):
def get_container_handler_context(request, usage_key, course, xblock):
"""
Utils is used to get context for container xblock requests.
It is used for both DRF and django views.
"""

from cms.djangoapps.contentstore.views.component import (
_get_item_in_course,
get_component_templates,
get_unit_tags,
CONTAINER_TEMPLATES,
Expand All @@ -1807,11 +1804,6 @@ def get_container_handler_context(request, usage_key):
)
from openedx.core.djangoapps.content_staging import api as content_staging_api

try:
course, xblock, lms_link, preview_lms_link = _get_item_in_course(request, usage_key)
except ItemNotFoundError:
return HttpResponseBadRequest()

component_templates = get_component_templates(course)
ancestor_xblocks = []
parent = get_parent_xblock(xblock)
Expand All @@ -1820,9 +1812,6 @@ def get_container_handler_context(request, usage_key):
is_unit_page = is_unit(xblock)
unit = xblock if is_unit_page else None

if is_unit_page and use_new_unit_page(course.id):
return redirect(get_unit_url(course.id, unit.location))

is_first = True
block = xblock

Expand Down Expand Up @@ -1910,8 +1899,6 @@ def get_container_handler_context(request, usage_key):
'ancestor_xblocks': ancestor_xblocks,
'component_templates': component_templates,
'xblock_info': xblock_info,
'draft_preview_link': preview_lms_link,
'published_preview_link': lms_link,
'templates': CONTAINER_TEMPLATES,
'show_unit_tags': show_unit_tags,
# Status of the user's clipboard, exactly as would be returned from the "GET clipboard" REST API.
Expand Down
26 changes: 22 additions & 4 deletions cms/djangoapps/contentstore/views/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.contrib.auth.decorators import login_required
from django.core.exceptions import PermissionDenied
from django.http import Http404, HttpResponseBadRequest
from django.shortcuts import redirect
from django.utils.translation import gettext as _
from django.views.decorators.http import require_GET
from opaque_keys import InvalidKeyError
Expand All @@ -23,12 +24,14 @@
from common.djangoapps.student.auth import has_course_author_access
from common.djangoapps.xblock_django.api import authorable_xblocks, disabled_xblocks
from common.djangoapps.xblock_django.models import XBlockStudioConfigurationFlag
from cms.djangoapps.contentstore.toggles import use_new_problem_editor
from cms.djangoapps.contentstore.helpers import is_unit
from cms.djangoapps.contentstore.toggles import use_new_problem_editor, use_new_unit_page
from cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers import load_services_for_studio
from openedx.core.lib.xblock_utils import get_aside_from_xblock, is_xblock_aside
from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration
from openedx.core.djangoapps.content_tagging.api import get_content_tags
from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order
from cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers import load_services_for_studio
from xmodule.modulestore.exceptions import ItemNotFoundError # lint-amnesty, pylint: disable=wrong-import-order

__all__ = [
'container_handler',
Expand Down Expand Up @@ -108,7 +111,7 @@ def container_handler(request, usage_key_string): # pylint: disable=too-many-st
json: not currently supported
"""

from ..utils import get_container_handler_context
from ..utils import get_container_handler_context, get_unit_url

if 'text/html' in request.META.get('HTTP_ACCEPT', 'text/html'):

Expand All @@ -117,7 +120,22 @@ def container_handler(request, usage_key_string): # pylint: disable=too-many-st
except InvalidKeyError: # Raise Http404 on invalid 'usage_key_string'
raise Http404 # lint-amnesty, pylint: disable=raise-missing-from
with modulestore().bulk_operations(usage_key.course_key):
container_handler_context = get_container_handler_context(request, usage_key)
try:
course, xblock, lms_link, preview_lms_link = _get_item_in_course(request, usage_key)
except ItemNotFoundError:
return HttpResponseBadRequest()

is_unit_page = is_unit(xblock)
unit = xblock if is_unit_page else None

if is_unit_page and use_new_unit_page(course.id):
return redirect(get_unit_url(course.id, unit.location))

container_handler_context = get_container_handler_context(request, usage_key, course, xblock)
container_handler_context.update({
'draft_preview_link': preview_lms_link,
'published_preview_link': lms_link,
})
return render_to_response('container.html', container_handler_context)
else:
return HttpResponseBadRequest("Only supports HTML requests")
Expand Down

0 comments on commit 5fbe4ee

Please sign in to comment.