Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(DS-451)feat: adds TenantAwareLinkRenderStarted filter #179

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 @@ -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


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