edx-platform icon indicating copy to clipboard operation
edx-platform copied to clipboard

feat: show exception message from filters in the user interface

Open felipemontoya opened this issue 5 months ago • 1 comments

Description

This PR connects the output from the org.openedx.learning.course.enrollment.started.v1 or CourseEnrollmentStarted into the API that responds to the user action in the UI.

Useful information to include:

  • This impacts developers that are using open edX filters to create their own rules for enrollment.

Testing instructions

In tutor:

  • Use a tutor environment with edx-platform with this branch
  • create a filter in your_package.pipeline with this code:
from openedx_filters import PipelineStep
from openedx_filters.learning.filters import CourseEnrollmentStarted

class MyFilterToStopEnrollment(PipelineStep):   # pylint: disable=too-few-public-methods
    """
    Stop enrollment process raising PreventEnrollment exception
    """

    def run_filter(self, user, course_key, mode):
        """Filter."""
        raise CourseEnrollmentStarted.PreventEnrollment(_("You can't enroll on this course as there is custom code preventing it"))
  • You need to add the following settings to your settings
OPEN_EDX_FILTERS_CONFIG = {
        "org.openedx.learning.course.enrollment.started.v1": {
            "fail_silently": False,
            "pipeline": [
                "your_package.pipeline.MyFilterToStopEnrollment",
            ],
        },
    }
  • Go to any course-about page in the platform and try to enroll. The message "you can't enroll on this course as there is custom code preventing it" should be visible.

Deadline

Ideally soon, but there is no great rush as this has been present for a while.

felipemontoya avatar Aug 30 '24 21:08 felipemontoya