From d43c9a9fa7263bcfcbc33411df5d1b5778026e15 Mon Sep 17 00:00:00 2001 From: Zacharis278 Date: Tue, 17 Sep 2024 12:41:55 -0400 Subject: [PATCH 1/3] feat: pluggable url for idv location --- lms/djangoapps/verify_student/services.py | 4 ++- .../verify_student/tests/test_services.py | 33 ++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/lms/djangoapps/verify_student/services.py b/lms/djangoapps/verify_student/services.py index f1c5543e8536..34b9ed91ce95 100644 --- a/lms/djangoapps/verify_student/services.py +++ b/lms/djangoapps/verify_student/services.py @@ -11,6 +11,7 @@ from django.core.exceptions import ObjectDoesNotExist from django.utils.timezone import now from django.utils.translation import gettext as _ +from openedx_filters.learning.filters import IDVPageURLRequested from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.models import User @@ -244,7 +245,8 @@ def get_verify_location(cls, course_id=None): location = f'{settings.ACCOUNT_MICROFRONTEND_URL}/id-verification' if course_id: location += f'?course_id={quote(str(course_id))}' - return location + + return IDVPageURLRequested.run_filter(location) @classmethod def get_verification_details_by_id(cls, attempt_id): diff --git a/lms/djangoapps/verify_student/tests/test_services.py b/lms/djangoapps/verify_student/tests/test_services.py index 5351e3ede699..d57993d368af 100644 --- a/lms/djangoapps/verify_student/tests/test_services.py +++ b/lms/djangoapps/verify_student/tests/test_services.py @@ -9,10 +9,11 @@ import ddt from django.conf import settings -from django.test import TestCase +from django.test import TestCase, override_settings from django.utils.timezone import now from django.utils.translation import gettext as _ from freezegun import freeze_time +from openedx_filters import PipelineStep from pytz import utc from common.djangoapps.student.tests.factories import UserFactory @@ -33,6 +34,16 @@ } +class TestIdvPageUrlRequestedPipelineStep(PipelineStep): + """ Utility function to test a configured pipeline step """ + TEST_URL = 'example.com/verify' + + def run_filter(self, url): # pylint: disable=arguments-differ + return { + "url": self.TEST_URL + } + + @patch.dict(settings.VERIFY_STUDENT, FAKE_SETTINGS) @ddt.ddt class TestIDVerificationService(ModuleStoreTestCase): @@ -167,6 +178,26 @@ def test_get_verify_location_from_string(self): expected_path = f'{settings.ACCOUNT_MICROFRONTEND_URL}/id-verification' assert path == (expected_path + '?course_id=course-v1%3AedX%2BDemoX%2BDemo_Course') + @override_settings( + OPEN_EDX_FILTERS_CONFIG={ + "org.openedx.learning.idv.page.url.requested.v1": { + "pipeline": [ + "lms.djangoapps.verify_student.tests.test_services.TestIdvPageUrlRequestedPipelineStep", + ], + "fail_silently": False, + }, + }, + ) + def test_get_verify_location_with_filter_step(self): + """ + Test IDV flow location can be customized with an openedx filter + """ + url = IDVerificationService.get_verify_location() + assert url == TestIdvPageUrlRequestedPipelineStep.TEST_URL + + url = IDVerificationService.get_verify_location('course-v1:edX+DemoX+Demo_Course') + assert url == TestIdvPageUrlRequestedPipelineStep.TEST_URL + def test_get_expiration_datetime(self): """ Test that the latest expiration datetime is returned if there are multiple records From 3ff5c31aee12996889cdb796ed061a92bb3975fc Mon Sep 17 00:00:00 2001 From: Zacharis278 Date: Wed, 25 Sep 2024 13:45:51 -0400 Subject: [PATCH 2/3] docs: annotate filter --- lms/djangoapps/verify_student/services.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lms/djangoapps/verify_student/services.py b/lms/djangoapps/verify_student/services.py index 34b9ed91ce95..1a2d145e892a 100644 --- a/lms/djangoapps/verify_student/services.py +++ b/lms/djangoapps/verify_student/services.py @@ -246,6 +246,8 @@ def get_verify_location(cls, course_id=None): if course_id: location += f'?course_id={quote(str(course_id))}' + # .. filter_implemented_name: IDVPageURLRequested + # .. filter_type: org.openedx.learning.idv.page.url.requested.v1 return IDVPageURLRequested.run_filter(location) @classmethod From 8d8565845b0c3ed7bb0408eba870c6e304294f1b Mon Sep 17 00:00:00 2001 From: Zacharis278 Date: Wed, 25 Sep 2024 14:27:02 -0400 Subject: [PATCH 3/3] chore: update openedx-filters --- requirements/edx/base.txt | 2 +- requirements/edx/development.txt | 2 +- requirements/edx/doc.txt | 2 +- requirements/edx/testing.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/requirements/edx/base.txt b/requirements/edx/base.txt index 097d21524190..f71d7f1fce54 100644 --- a/requirements/edx/base.txt +++ b/requirements/edx/base.txt @@ -819,7 +819,7 @@ openedx-events==9.14.0 # edx-event-bus-redis # event-tracking # ora2 -openedx-filters==1.9.0 +openedx-filters==1.10.0 # via # -r requirements/edx/kernel.in # lti-consumer-xblock diff --git a/requirements/edx/development.txt b/requirements/edx/development.txt index 3fa131288294..b1767004d863 100644 --- a/requirements/edx/development.txt +++ b/requirements/edx/development.txt @@ -1367,7 +1367,7 @@ openedx-events==9.14.0 # edx-event-bus-redis # event-tracking # ora2 -openedx-filters==1.9.0 +openedx-filters==1.10.0 # via # -r requirements/edx/doc.txt # -r requirements/edx/testing.txt diff --git a/requirements/edx/doc.txt b/requirements/edx/doc.txt index 1c12d28955c6..25872d4737e3 100644 --- a/requirements/edx/doc.txt +++ b/requirements/edx/doc.txt @@ -978,7 +978,7 @@ openedx-events==9.14.0 # edx-event-bus-redis # event-tracking # ora2 -openedx-filters==1.9.0 +openedx-filters==1.10.0 # via # -r requirements/edx/base.txt # lti-consumer-xblock diff --git a/requirements/edx/testing.txt b/requirements/edx/testing.txt index 6e36d98f04d8..bf4bf9c6a4dc 100644 --- a/requirements/edx/testing.txt +++ b/requirements/edx/testing.txt @@ -1029,7 +1029,7 @@ openedx-events==9.14.0 # edx-event-bus-redis # event-tracking # ora2 -openedx-filters==1.9.0 +openedx-filters==1.10.0 # via # -r requirements/edx/base.txt # lti-consumer-xblock