Skip to content

Commit

Permalink
feat: add ORA filter for student_view rendering intervention
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanttV committed Apr 11, 2024
1 parent 8f7d94f commit 6c0e69c
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------------

Expand Down
2 changes: 1 addition & 1 deletion openedx_filters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"""
from openedx_filters.filters import *

__version__ = "1.6.0"
__version__ = "1.7.0"
38 changes: 38 additions & 0 deletions openedx_filters/learning/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
31 changes: 31 additions & 0 deletions openedx_filters/learning/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
CourseUnenrollmentStarted,
DashboardRenderStarted,
InstructorDashboardRenderStarted,
ORASubmissionViewRenderStarted,
StudentLoginRequested,
StudentRegistrationRequested,
VerticalBlockChildRenderStarted,
Expand Down Expand Up @@ -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):
"""
Expand Down

0 comments on commit 6c0e69c

Please sign in to comment.