refactor: deprecates replace url related properties from ModuleSystem

Deprecates the following attributes from ModuleSystem:
 * replace_urls
 * replace_course_urls
 * replace_jump_to_id_urls

A new ReplaceURLService is created as replacement with a unified replace_urls method
This commit is contained in:
Kaustav Banerjee
2022-02-06 16:57:42 +05:30
committed by Julia Eskew
parent a5e51d0662
commit c48c655998
22 changed files with 389 additions and 255 deletions

View File

@@ -28,7 +28,8 @@ from xmodule.util.xmodule_django import add_webpack_to_fragment
from xmodule.x_module import AUTHOR_VIEW, PREVIEW_VIEWS, STUDENT_VIEW, ModuleSystem, XModule, XModuleDescriptor
from cms.djangoapps.xblock_config.models import StudioConfig
from cms.lib.xblock.field_data import CmsFieldData
from common.djangoapps import static_replace
from common.djangoapps.static_replace.services import ReplaceURLService
from common.djangoapps.static_replace.wrapper import replace_urls_wrapper
from common.djangoapps.edxmako.shortcuts import render_to_string
from common.djangoapps.edxmako.services import MakoService
from common.djangoapps.xblock_django.user_service import DjangoXBlockUserService
@@ -36,7 +37,6 @@ from lms.djangoapps.lms_xblock.field_data import LmsFieldData
from openedx.core.lib.license import wrap_with_license
from openedx.core.lib.cache_utils import CacheService
from openedx.core.lib.xblock_utils import (
replace_static_urls,
request_token,
wrap_fragment,
wrap_xblock,
@@ -162,6 +162,8 @@ def _preview_module_system(request, descriptor, field_data):
course_id = descriptor.location.course_key
display_name_only = (descriptor.category == 'static_tab')
replace_url_service = ReplaceURLService(course_id=course_id)
wrappers = [
# This wrapper wraps the module in the template specified above
partial(
@@ -174,7 +176,7 @@ def _preview_module_system(request, descriptor, field_data):
# This wrapper replaces urls in the output that start with /static
# with the correct course-specific url for the static content
partial(replace_static_urls, None, course_id=course_id),
partial(replace_urls_wrapper, replace_url_service=replace_url_service, static_replace_only=True),
_studio_wrap_xblock,
]
@@ -199,7 +201,6 @@ def _preview_module_system(request, descriptor, field_data):
filestore=descriptor.runtime.resources_fs,
get_module=partial(_load_preview_module, request),
debug=True,
replace_urls=partial(static_replace.replace_static_urls, data_directory=None, course_id=course_id),
mixins=settings.XBLOCK_MIXINS,
course_id=course_id,
@@ -223,6 +224,7 @@ def _preview_module_system(request, descriptor, field_data):
"teams_configuration": TeamsConfigurationService(),
"sandbox": SandboxService(contentstore=contentstore, course_id=course_id),
"cache": CacheService(cache),
'replace_urls': replace_url_service
},
)

View File

@@ -22,6 +22,7 @@ from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from xmodule.modulestore.tests.test_asides import AsideTestType
from cms.djangoapps.contentstore.utils import reverse_usage_url
from cms.djangoapps.xblock_config.models import StudioConfig
from common.djangoapps import static_replace
from common.djangoapps.student.tests.factories import UserFactory
from ..preview import _preview_module_system, get_preview_fragment
@@ -174,6 +175,7 @@ class GetPreviewHtmlTestCase(ModuleStoreTestCase):
@XBlock.needs("field-data")
@XBlock.needs("i18n")
@XBlock.needs("mako")
@XBlock.needs("replace_urls")
@XBlock.needs("user")
@XBlock.needs("teams_configuration")
class PureXBlock(XBlock):
@@ -205,7 +207,7 @@ class StudioXBlockServiceBindingTest(ModuleStoreTestCase):
self.field_data = mock.Mock()
@XBlock.register_temp_plugin(PureXBlock, identifier='pure')
@ddt.data("user", "i18n", "field-data", "teams_configuration")
@ddt.data("user", "i18n", "field-data", "teams_configuration", "replace_urls")
def test_expected_services_exist(self, expected_service):
"""
Tests that the 'user' and 'i18n' services are provided by the Studio runtime.
@@ -287,3 +289,8 @@ class CmsModuleSystemShimTest(ModuleStoreTestCase):
def test_cache(self):
assert hasattr(self.runtime.cache, 'get')
assert hasattr(self.runtime.cache, 'set')
def test_replace_urls(self):
html = '<a href="/static/id">'
assert self.runtime.replace_urls(html) == \
static_replace.replace_static_urls(html, course_id=self.runtime.course_id)