diff --git a/eox_tenant/filters/README.rst b/eox_tenant/filters/README.rst index a095b5a8..b2a50da6 100644 --- a/eox_tenant/filters/README.rst +++ b/eox_tenant/filters/README.rst @@ -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: ----------------------------- diff --git a/eox_tenant/filters/pipeline.py b/eox_tenant/filters/pipeline.py index 3c8745b2..eeb7f9a0 100644 --- a/eox_tenant/filters/pipeline.py +++ b/eox_tenant/filters/pipeline.py @@ -2,6 +2,7 @@ The pipeline module defines custom Filters functions that are used in openedx-filters. """ from openedx_filters import PipelineStep +from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx_filters.learning.filters import CertificateRenderStarted from eox_tenant.organizations import get_organizations @@ -57,3 +58,26 @@ def run_filter(self, context, custom_template, *args, **kwargs): # pylint: disa raise CertificateRenderStarted.RenderAlternativeInvalidCertificate( "You can't generate a certificate from this site.", ) + + +class FilterTenantAwareLinksFromStudio(PipelineStep): + """ + Filter tenant aware links from Studio. + """ + + def run_filter(self, context, org, val_name, default): # pylint: disable=arguments-differ + """ + 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.learning.tenant_aware_link.render.started.v1": { + "fail_silently": false, + "pipeline": [ + "eox_tenant.filters.pipeline.FilterTenantAwareLinksFromStudio" + ] + } + } + """ + lms_root = configuration_helpers.get_value_for_org(org, val_name, default) + return {"context": lms_root} diff --git a/eox_tenant/filters/test/test_pipeline.py b/eox_tenant/filters/test/test_pipeline.py index c0b85f4a..84f38d7e 100644 --- a/eox_tenant/filters/test/test_pipeline.py +++ b/eox_tenant/filters/test/test_pipeline.py @@ -9,7 +9,7 @@ from openedx_filters.learning.filters import CertificateRenderStarted from openedx_filters.tooling import OpenEdxPublicFilter -from eox_tenant.filters.pipeline import FilterRenderCertificatesByOrg +from eox_tenant.filters.pipeline import FilterRenderCertificatesByOrg, FilterTenantAwareLinksFromStudio from eox_tenant.tenant_aware_functions.enrollments import filter_enrollments @@ -182,3 +182,47 @@ 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 FilterTenantAwareLinksFromStudioTestCase(TestCase): + """ + FilterTenantAwareLinksFromStudioTestCase test cases. + """ + + def setUp(self): + """This method creates Microsite objects in database""" + + # Creating mock to render tenant aware links + self.context = "https://lms-base" + self.org = "test" + self.val_name='LMS_ROOT_URL' + self.default = "https://lms-base" + + @override_settings( + OPEN_EDX_FILTERS_CONFIG= { + "org.openedx.learning.tenant_aware_link.render.started.v1": { + "fail_silently": False, + "pipeline": [ + "eox_tenant.filters.pipeline.TenantAwareLinksFromStudio" + ] + } + }, + LMS_ROOT_URL="https://test-tenant-aware-link" + ) + @mock.patch('openedx.core.djangoapps.site_configuration.helpers.get_value_for_org') + def test_tenant_aware_link_from_studio(self, get_value_for_org_mock): + """ + Test that filter tenant aware link get value for org. + """ + results_get_value = "https://test-tenant-aware-link" + + get_value_for_org_mock.return_value = results_get_value + + lms_root = FilterTenantAwareLinksFromStudio.run_filter( + context=self.context, + org=self.org, + val_name=self.val_name, + default=self.default + ) + + self.assertEqual(results_get_value, lms_root)