Skip to content

Commit

Permalink
feat: adds FilterTenantAwareLinksFromStudio in filters pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
JuanDavidBuitrago authored and jignaciopm committed Oct 3, 2024
1 parent 7b677d8 commit a9212d3
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 4 deletions.
2 changes: 1 addition & 1 deletion eox_tenant/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
Init for eox-tenant.
"""
__version__ = '11.7.0'
__version__ = '11.8.0'
6 changes: 5 additions & 1 deletion eox_tenant/filters/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ Filters steps list:
-------------------

* `FilterUserCourseEnrollmentsByTenant`_: Filters the course enrollments of a user from the tenant site where the request is made.
* `FilterRenderCertificatesByOrg`_: Stop certificate generation process raising a exception if course org is different to tenant orgs.
* `TenantAwareLinksFromStudio`_: Filter especific tenant aware link form Studio to the LMS.

.. _FilterUserCourseEnrollmentsByTenant: ./pipeline.py#L9
.. _FilterUserCourseEnrollmentsByTenant: ./pipeline.py#L12
.. _FilterRenderCertificatesByOrg: ./pipeline.py#L35
.. _TenantAwareLinksFromStudio: ./pipeline.py#L63

How to add a new Filter Step:
-----------------------------
Expand Down
61 changes: 61 additions & 0 deletions eox_tenant/filters/pipeline.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
"""
The pipeline module defines custom Filters functions that are used in openedx-filters.
"""
from django.conf import settings
from openedx_filters import PipelineStep
from openedx_filters.learning.filters import CertificateRenderStarted

from eox_tenant.edxapp_wrapper.site_configuration_module import get_configuration_helpers
from eox_tenant.organizations import get_organizations
from eox_tenant.tenant_aware_functions.enrollments import filter_enrollments

configuration_helpers = get_configuration_helpers()


class FilterUserCourseEnrollmentsByTenant(PipelineStep):
"""
Expand Down Expand Up @@ -57,3 +61,60 @@ def run_filter(self, context, custom_template, *args, **kwargs): # pylint: disa
raise CertificateRenderStarted.RenderAlternativeInvalidCertificate(
"You can't generate a certificate from this site.",
)


class OrgAwareLMSURLStudio(PipelineStep):
"""
Filter tenant aware links from Studio.
"""

def run_filter(self, url, org): # pylint: disable=arguments-differ,unused-argument
"""
Filter especific tenant aware link form Studio to the LMS.
Example Usage:
Add the following configurations to you configuration file
"OPEN_EDX_FILTERS_CONFIG": {
"org.openedx.course_authoring.lms.page.url.requested.v1": {
"fail_silently": false,
"pipeline": [
"eox_tenant.filters.pipeline.OrgAwareLMSURLStudio"
]
}
}
"""
lms_root = configuration_helpers.get_value_for_org(
org,
'LMS_ROOT_URL',
settings.LMS_ROOT_URL
)
return {"url": lms_root, "org": org}


class OrgAwareCourseAboutPageURL(PipelineStep):
"""
Filter tenant aware links from LMS.
"""

def run_filter(self, url, org): # pylint: disable=arguments-differ,unused-argument
"""
The url looks like this:
<LMS_ROOT>/courses/course-v1:org+course+number/about
This method will filter the url to be tenant aware.
Example Usage:
Add the following configurations to you configuration file
"OPEN_EDX_FILTERS_CONFIG": {
"org.openedx.learning.course_about.page.url.requested.v1": {
"fail_silently": false,
"pipeline": [
"eox_tenant.filters.pipeline.OrgAwareCourseAboutPageURL"
]
},
}
"""
lms_root = configuration_helpers.get_value_for_org(
org,
'LMS_ROOT_URL',
settings.LMS_ROOT_URL
)
return {"url": lms_root, "org": org}
86 changes: 85 additions & 1 deletion eox_tenant/filters/test/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.test import TestCase, override_settings
from openedx_filters.learning.filters import CertificateRenderStarted, CourseEnrollmentQuerysetRequested

from eox_tenant.filters.pipeline import FilterRenderCertificatesByOrg
from eox_tenant.filters.pipeline import FilterRenderCertificatesByOrg, OrgAwareCourseAboutPageURL, OrgAwareLMSURLStudio
from eox_tenant.tenant_aware_functions.enrollments import filter_enrollments


Expand Down Expand Up @@ -161,3 +161,87 @@ def test_filter_render_certificates_by_org(self, organizations, render, mock_get
else:
FilterRenderCertificatesByOrg.run_filter(self, context, {})
mock_get_organizations.assert_called_once()


class FilterOrgAwareLMSURLStudioTestCase(TestCase):
"""
FilterOrgAwareLMSURLStudioTestCase test cases.
"""

def setUp(self):
"""This method creates Microsite objects in database"""

# Creating mock to render tenant aware links
self.url = "https://lms-base"
self.org = "test"

@override_settings(
OPEN_EDX_FILTERS_CONFIG={
"org.openedx.learning.tenant_aware_link.render.started.v1": {
"fail_silently": False,
"pipeline": [
"eox_tenant.filters.pipeline.OrgAwareLMSURLStudio"
]
}
},
LMS_ROOT_URL="https://test-tenant-aware-link"
)
@mock.patch('eox_tenant.filters.pipeline.configuration_helpers')
def test_tenant_aware_link_from_studio(self, configuration_helpers_mock):
"""
Test that filter tenant aware link get value for org.
"""
results_get_value = "https://test-tenant-aware-link"

configuration_helpers_mock.get_value_for_org.return_value = results_get_value

result = OrgAwareLMSURLStudio.run_filter(
self,
url=self.url,
org=self.org,
)

self.assertEqual(results_get_value, result.get("url"))
self.assertEqual(result.get("org"), self.org)


class FilterOrgAwareCourseAboutPageURLTestCase(TestCase):
"""
FilterOrgAwareCourseAboutPageURLTestCase test cases.
"""

def setUp(self):
"""This method creates Microsite objects in database"""

# Creating mock to render tenant aware links
self.url = "https://lms-base"
self.org = "test"

@override_settings(
OPEN_EDX_FILTERS_CONFIG={
"org.openedx.learning.tenant_aware_link.render.started.v1": {
"fail_silently": False,
"pipeline": [
"eox_tenant.filters.pipeline.OrgAwareCourseAboutPageURL"
]
}
},
LMS_ROOT_URL="https://test-tenant-aware-link"
)
@mock.patch('eox_tenant.filters.pipeline.configuration_helpers')
def test_tenant_aware_link_from_studio(self, configuration_helpers_mock):
"""
Test that filter tenant aware link get value for org.
"""
results_get_value = "https://test-tenant-aware-link"

configuration_helpers_mock.get_value_for_org.return_value = results_get_value

result = OrgAwareCourseAboutPageURL.run_filter(
self,
url=self.url,
org=self.org,
)

self.assertEqual(results_get_value, result.get("url"))
self.assertEqual(result.get("org"), self.org)
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 11.7.0
current_version = 11.8.0
commit = False
tag = False

Expand Down

0 comments on commit a9212d3

Please sign in to comment.