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

[BD-32] feat: add 2nd batch of Open edX Filters #29840

Closed
wants to merge 6 commits into from

Conversation

mariajgrimaldi
Copy link
Member

@mariajgrimaldi mariajgrimaldi commented Jan 28, 2022

Description

This PR adds the 2nd Open edX Filters batch as part of the implementation plan of Hooks Extension Framework:

  • CourseUnenrollmentStarted: intended to be executed before the un-enrollment process starts.
  • CertificateCreationRequested: intended to be executed before the certificate creation process starts.
  • CertificateRenderStarted: intended to be executed before the certificate template rendering process starts.
  • CohortChangeRequested: intended to be executed before the cohort change process starts.
  • CourseAboutRenderStarted: intended to be executed before course about template render starts.
  • CourseHomeRenderStarted: intended to be executed before course home template render starts.
  • DashboardRenderStarted: intended to be executed before the student's dashboard render starts.

Supporting information

Testing instructions

  1. Install openedx-filters library:
pip install git+https://github.com/eduNEXT/openedx-filters.git@MJG/2nd_filters_batch#egg=openedx_filters==0.5.0_alpha
  1. Implement your pipeline steps in your favorite plugin. We created some as illustration in openedx-filters-samples. We'll be using those in this example.
  2. Install openedx-filters-samples
pip install git+https://github.com/eduNEXT/openedx-filters-samples.git@master#egg=openedx_filters_samples
  1. Configure your filters:
    With this configuration, you won't be able to:
  • Generate a certificate with org.openedx.learning.certificate.creation.requested.v1
  • Render certificate for org.openedx.learning.certificate.render.started.v1
  • Un-enroll from a course org.openedx.learning.course.unenrollment.started.v1
  • Rendering course about page (courses/COURSE_ID/about) org.openedx.learning.course_about.render.started.v1
  • Rendering course home page (courses/COURSE_ID/course) org.openedx.learning.course_home.render.started.v1
  • Rendering student's dashboard page (/dashboard) org.openedx.learning.course_home.render.started.v1
  • Change a student from cohort A to cohort B with org.openedx.learning.cohort.change.requested.v1
    To change the behavior you can replace Stop<process> with NoopFilter or remove it completely.
OPEN_EDX_FILTERS_CONFIG = {
    "org.openedx.learning.certificate.creation.requested.v1": {
        "fail_silently": False,
        "pipeline": [
            "openedx_filters_samples.samples.pipeline.StopCertificateCreation"
        ]
    },
    "org.openedx.learning.course.unenrollment.started.v1": {
        "fail_silently": False,
        "pipeline": [
            "openedx_filters_samples.samples.pipeline.StopUnenrollment"
        ]
    },
    "org.openedx.learning.course_about.render.started.v1": {
        "fail_silently": False,
        "pipeline": [
            "openedx_filters_samples.samples.pipeline.StopCourseAboutRendering",
        ]
    },
    "org.openedx.learning.course_home.render.started.v1": {
        "fail_silently": False,
        "pipeline": [
            "openedx_filters_samples.samples.pipeline.StopCourseHomeRendering",
        ]
    },
    "org.openedx.learning.dashboard.render.started.v1": {
        "fail_silently": False,
        "pipeline": [
            "openedx_filters_samples.samples.pipeline.StopDashboardRender",
        ]
    },
     "org.openedx.learning.certificate.render.started.v1": {
            "fail_silently": False,
            "pipeline": [
                "openedx_filters_samples.samples.pipeline.StopCertificateRender",
            ]
    },
     "org.openedx.learning.cohort.change.requested.v1": {
            "fail_silently": False,
            "pipeline": [
                "openedx_filters_samples.samples.pipeline.StopCohortChange",
            ]
    },
}

Notes about the filters steps:

  • ModifyContextBeforeRender: changes context before rendering. As it is right now just adds a new variable.
    The other ones halt the app execution.

Simple and straightforward implementations as a way of illustrating how they work. More complex steps are coming.

@openedx-webhooks openedx-webhooks added blended PR is managed through 2U's blended developmnt program waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. labels Jan 28, 2022
@openedx-webhooks
Copy link

openedx-webhooks commented Jan 28, 2022

Thanks for the pull request, @mariajgrimaldi! I've created BLENDED-1080 to keep track of it in Jira. More details are on the BD-32 project page.

When this pull request is ready, tag your edX technical lead.

try:
context = DashboardRenderStarted.run_filter(context=context)
except DashboardRenderStarted.PreventDashboardRender as exc:
raise DashboardRenderNotAllowed(reverse(exc.redirect_to or 'account_settings')) from exc
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should happen when interacting with templates?

As it is right now, when filters that interact with templates (i.e they interact with template contexts) fail they raise an exception with the intent to redirect to some constant view (e.g if course about filter fails, then redirect to dashboard). If there's a handler that interprets this kind of exception, then the redirection occurs (as it happens when using CourseAccessRedirect here where this handler catches the exception and manages the redirection). If not, like in this case, then error 500 is thrown. So we can replicate this behavior we should implement a handler that manages exceptions in the student's dashboard, but that's probably out of the scope of this PR.

Either way, should be this way the standard when interacting with templates?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea that we should have a consistent way of interacting with templates when filters are involved. Having the ability to redirect somewhere and changing the template_name that should be rendered and naturally updating the context before rendering are the three that come to my mind now.

@mariajgrimaldi mariajgrimaldi marked this pull request as ready for review January 28, 2022 22:16
@openedx-webhooks openedx-webhooks added needs triage and removed waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. labels Jan 28, 2022
@mariajgrimaldi
Copy link
Member Author

FYI 🥳 @felipemontoya @ormsbee @shadinaif @giovannicimolin

@giovannicimolin
Copy link
Contributor

Awesome! 🚀

@JuanDavidBuitrago
Copy link
Contributor

I tested some filters and make the BD-32 Open edx Filters document with the results of the testing from description. I hope it can help!!

@mariajgrimaldi
Copy link
Member Author

Knowing that we are modifying multiple applications and this can be difficult to review all at once, I'll be dividing this PR into smaller chunks!

@mariajgrimaldi
Copy link
Member Author

PR closed in favor of:

PR 29948:
CourseUnenrollmentStarted: intended to be executed before the un-enrollment process starts.

PR 29949:
CertificateCreationRequested: intended to be executed before the certificate creation process starts.

PR 29976:
CertificateRenderStarted: intended to be executed before the certificate template rendering process starts.

PR 29964:
CohortChangeRequested: intended to be executed before the cohort change process starts.

PR 29996:
CourseAboutRenderStarted: intended to be executed before course about template render starts.

PR 29995:
CourseHomeRenderStarted: intended to be executed before course home template render starts.

PR 29994:
DashboardRenderStarted: intended to be executed before the student's dashboard render starts.

@openedx-webhooks
Copy link

@mariajgrimaldi Even though your pull request wasn’t merged, please take a moment to answer a two question survey so we can improve your experience in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blended PR is managed through 2U's blended developmnt program rejected
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants