diff --git a/CHANGELOG.rst b/CHANGELOG.rst index c8439f1..eec3529 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -14,6 +14,15 @@ Change Log Unreleased ---------- +[1.7.0] - 2024-04-10 +-------------------- + +Added +~~~~~ + +* ORASubmissionViewRenderStarted filter added which can be used to modify the ORA submission view. + + [1.6.0] - 2023-08-18 -------------------- diff --git a/openedx_filters/__init__.py b/openedx_filters/__init__.py index f223944..b1b837b 100644 --- a/openedx_filters/__init__.py +++ b/openedx_filters/__init__.py @@ -3,4 +3,4 @@ """ from openedx_filters.filters import * -__version__ = "1.6.0" +__version__ = "1.7.0" diff --git a/openedx_filters/learning/filters.py b/openedx_filters/learning/filters.py index 3e968d8..ce28e2f 100644 --- a/openedx_filters/learning/filters.py +++ b/openedx_filters/learning/filters.py @@ -2,6 +2,8 @@ Package where filters related to the learning architectural subdomain are implemented. """ +from typing import Optional + from openedx_filters.exceptions import OpenEdxFilterException from openedx_filters.tooling import OpenEdxPublicFilter from openedx_filters.utils import SensitiveDataManagementMixin @@ -701,3 +703,39 @@ def run_filter(cls, context, template_name): """ data = super().run_pipeline(context=context, template_name=template_name) return data.get("context"), data.get("template_name") + + +class ORASubmissionViewRenderStarted(OpenEdxPublicFilter): + """ + Custom class used to create ORA submission view filters and its custom methods. + """ + + filter_type = "org.openedx.learning.ora.submission_view.render.started.v1" + + class RenderInvalidTemplate(OpenEdxFilterException): + """ + Custom class used to stop the submission view render process. + """ + + def __init__(self, message: str, context: Optional[dict] = None, template_name: str = ""): + """ + Override init that defines specific arguments used in the submission view render process. + + Arguments: + message (str): error message for the exception. + context (dict): context used to the submission view template. + template_name (str): template path rendered instead. + """ + super().__init__(message, context=context, template_name=template_name) + + @classmethod + def run_filter(cls, context: dict, template_name: str): + """ + Execute a filter with the signature specified. + + Arguments: + context (dict): context dictionary for submission view template. + template_name (str): template name to be rendered by the student's dashboard. + """ + data = super().run_pipeline(context=context, template_name=template_name, ) + return data.get("context"), data.get("template_name") diff --git a/openedx_filters/learning/tests/test_filters.py b/openedx_filters/learning/tests/test_filters.py index c8e8f91..f872d5d 100644 --- a/openedx_filters/learning/tests/test_filters.py +++ b/openedx_filters/learning/tests/test_filters.py @@ -21,6 +21,7 @@ CourseUnenrollmentStarted, DashboardRenderStarted, InstructorDashboardRenderStarted, + ORASubmissionViewRenderStarted, StudentLoginRequested, StudentRegistrationRequested, VerticalBlockChildRenderStarted, @@ -546,6 +547,36 @@ def test_halt_instructor_dashboard_render(self, dashboard_exception, attributes) self.assertDictContainsSubset(attributes, exception.__dict__) + def test_ora_submission_view_render_started(self): + """ + Test ORASubmissionViewRenderStarted filter behavior under normal conditions. + + Expected behavior: + - The filter must have the signature specified. + - The filter should return context and template_name in that order. + """ + result = ORASubmissionViewRenderStarted.run_filter(self.context, self.template_name) + + self.assertTupleEqual((self.context, self.template_name,), result) + + @data( + ( + ORASubmissionViewRenderStarted.RenderInvalidTemplate, + {"context": {"course": Mock()}, "template_name": "custom-template.html"}, + ), + ) + @unpack + def test_halt_ora_submission_view_render(self, dashboard_exception, attributes): + """ + Test for the ora submission view exceptions attributes. + + Expected behavior: + - The exception must have the attributes specified. + """ + exception = dashboard_exception(message="You can't access the view", **attributes) + + self.assertDictContainsSubset(attributes, exception.__dict__) + class TestCohortFilters(TestCase): """