Skip to content

Commit

Permalink
feat: adds CourseAboutPageURLRequested and LMSPageURLRequested filters
Browse files Browse the repository at this point in the history
  • Loading branch information
jignaciopm committed Oct 1, 2024
1 parent 3b93bfb commit f4570a3
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 6 deletions.
11 changes: 10 additions & 1 deletion cms/djangoapps/contentstore/asset_storage_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from common.djangoapps.util.json_request import JsonResponse
from openedx.core.djangoapps.contentserver.caching import del_cached_content
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
from openedx_filters.course_authoring.filters import LMSPageURLRequested
from xmodule.contentstore.content import StaticContent # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.contentstore.django import contentstore # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.exceptions import NotFoundError # lint-amnesty, pylint: disable=wrong-import-order
Expand Down Expand Up @@ -714,7 +715,15 @@ def get_asset_json(display_name, content_type, date, location, thumbnail_locatio
Helper method for formatting the asset information to send to client.
'''
asset_url = StaticContent.serialize_asset_key_with_slash(location)
external_url = urljoin(configuration_helpers.get_value('LMS_ROOT_URL', settings.LMS_ROOT_URL), asset_url)

## .. filter_implemented_name: LMSPageURLRequested
## .. filter_type: org.openedx.course_authoring.lms.page.url.requested.v1
lms_root, _ = LMSPageURLRequested.run_filter(
url=configuration_helpers.get_value('LMS_ROOT_URL', settings.LMS_ROOT_URL),
org=location.org,
)

external_url = urljoin(lms_root, asset_url)
portable_url = StaticContent.get_static_path_from_location(location)
usage_locations = [] if usage is None else usage
return {
Expand Down
10 changes: 9 additions & 1 deletion common/djangoapps/util/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from opaque_keys.edx.keys import CourseKey, UsageKey

from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
from openedx_filters.learning.filters import CourseAboutPageURLRequested

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -54,8 +55,15 @@ def get_link_for_about_page(course):
elif settings.FEATURES.get('ENABLE_MKTG_SITE') and getattr(course, 'marketing_url', None):
course_about_url = course.marketing_url
else:
## .. filter_implemented_name: CourseAboutPageURLRequested
## .. filter_type: org.openedx.learning.course_about.page.url.requested.v1
about_base, _ = CourseAboutPageURLRequested.run_filter(
url=configuration_helpers.get_value('LMS_ROOT_URL', settings.LMS_ROOT_URL),
org=course.id.org,
)

course_about_url = '{about_base_url}/courses/{course_key}/about'.format(
about_base_url=configuration_helpers.get_value('LMS_ROOT_URL', settings.LMS_ROOT_URL),
about_base_url=about_base,
course_key=str(course.id),
)

Expand Down
86 changes: 86 additions & 0 deletions common/djangoapps/util/tests/test_filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
"""
Test that various filters are fired for models/views in the student app.
"""
from django.test import override_settings
from common.djangoapps.util import course
from openedx_filters import PipelineStep
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory

from openedx.core.djangolib.testing.utils import skip_unless_lms


class TestPageURLRequestedPipelineStep(PipelineStep):
"""
Utility class used when getting steps for pipeline.
"""

def run_filter(self, url, org): # pylint: disable=arguments-differ
"""Pipeline step that modifies lms url creation."""
url = "https://lms-url-creation"
org = "org"
return {
"url": url,
"org": org,
}


@skip_unless_lms
class CourseAboutPageURLRequestedFiltersTest(ModuleStoreTestCase):
"""
Tests for the Open edX Filters associated with the lms url creation process.
This class guarantees that the following filters are triggered during the microsite render:
- CourseAboutPageURLRequested
"""

def setUp(self): # pylint: disable=arguments-differ
super().setUp()
self.course = CourseFactory.create()
self.org = "test"
self.val_name = 'LMS_ROOT_URL'
self.default = "https://lms-base"

@override_settings(
OPEN_EDX_FILTERS_CONFIG={
"org.openedx.learning.course_about.page.url.requested.v1": {
"pipeline": [
"common.djangoapps.util.tests.test_filters.TestPageURLRequestedPipelineStep",
],
"fail_silently": False,
},
},
)
def test_lms_url_creation_filter_executed(self):
"""
Test whether the lms url creation filter is triggered before the user's
render site process.
Expected result:
- CourseAboutPageURLRequested is triggered and executes TestPageURLRequestedPipelineStep.
- The arguments that the receiver gets are the arguments used by the filter.
"""
course_about_url = course.get_link_for_about_page(self.course)

expected_course_about = '{about_base_url}/courses/{course_key}/about'.format(
about_base_url='https://lms-url-creation',
course_key=str(self.course.id),
)

self.assertEqual(expected_course_about, course_about_url)

@override_settings(OPEN_EDX_FILTERS_CONFIG={}, LMS_ROOT_URL="https://lms-base")
def test_enrollment_without_filter_configuration(self):
"""
Test usual get link for about page process, without filter's intervention.
Expected result:
- Returns the course sharing url, this can be one of course's social sharing url, marketing url, or
lms course about url.
- The get process ends successfully.
"""
course_about_url = course.get_link_for_about_page(self.course)

expected_course_about = '{about_base_url}/courses/{course_key}/about'.format(
about_base_url='https://lms-base',
course_key=str(self.course.id),
)

self.assertEqual(expected_course_about, course_about_url)
2 changes: 1 addition & 1 deletion requirements/edx/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ openedx-events==9.14.1
# edx-event-bus-redis
# event-tracking
# ora2
openedx-filters==1.10.0
openedx-filters==1.11.0
# via
# -r requirements/edx/kernel.in
# lti-consumer-xblock
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,7 @@ openedx-events==9.14.1
# edx-event-bus-redis
# event-tracking
# ora2
openedx-filters==1.10.0
openedx-filters==1.11.0
# via
# -r requirements/edx/doc.txt
# -r requirements/edx/testing.txt
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ openedx-events==9.14.1
# edx-event-bus-redis
# event-tracking
# ora2
openedx-filters==1.10.0
openedx-filters==1.11.0
# via
# -r requirements/edx/base.txt
# lti-consumer-xblock
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ openedx-events==9.14.1
# edx-event-bus-redis
# event-tracking
# ora2
openedx-filters==1.10.0
openedx-filters==1.11.0
# via
# -r requirements/edx/base.txt
# lti-consumer-xblock
Expand Down

0 comments on commit f4570a3

Please sign in to comment.