From 291fbfec0b9b9d7571d00b7b96fbac7dc05a7d82 Mon Sep 17 00:00:00 2001 From: Juan David Buitrago Date: Fri, 31 Mar 2023 15:05:03 +0200 Subject: [PATCH 1/2] feat: adds TenantAwareLinkRenderStarted filter --- eox_tenant/filters/README.rst | 6 +++- eox_tenant/filters/pipeline.py | 24 +++++++++++++ eox_tenant/filters/test/test_pipeline.py | 46 +++++++++++++++++++++++- 3 files changed, 74 insertions(+), 2 deletions(-) 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 c38ad7d5..4ac4a521 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 1f9580be..9094c28a 100644 --- a/eox_tenant/filters/test/test_pipeline.py +++ b/eox_tenant/filters/test/test_pipeline.py @@ -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, FilterTenantAwareLinksFromStudio from eox_tenant.tenant_aware_functions.enrollments import filter_enrollments @@ -161,3 +161,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) From 39926246637d464dbb79b7d599ea4f68812c7e4b Mon Sep 17 00:00:00 2001 From: Maria Grimaldi Date: Tue, 23 Jul 2024 15:24:36 -0400 Subject: [PATCH 2/2] docs: bump version to latest release --- eox_tenant/__init__.py | 2 +- setup.cfg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/eox_tenant/__init__.py b/eox_tenant/__init__.py index 4faa7681..985b5e0e 100644 --- a/eox_tenant/__init__.py +++ b/eox_tenant/__init__.py @@ -1,4 +1,4 @@ """ Init for eox-tenant. """ -__version__ = '11.7.0' +__version__ = '11.8.0' diff --git a/setup.cfg b/setup.cfg index 75b003ba..1968d903 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 11.7.0 +current_version = 11.8.0 commit = False tag = False