Skip to content

Commit

Permalink
feat: adds TenantAwareLinkRenderStarted filter
Browse files Browse the repository at this point in the history
  • Loading branch information
JuanDavidBuitrago committed Apr 3, 2023
1 parent af2357a commit 2bf1172
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
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
24 changes: 24 additions & 0 deletions eox_tenant/filters/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
46 changes: 45 additions & 1 deletion eox_tenant/filters/test/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)

0 comments on commit 2bf1172

Please sign in to comment.