Skip to content

Conversation

@mariajgrimaldi
Copy link
Member

@mariajgrimaldi mariajgrimaldi commented Feb 17, 2022

Description

As part of the Hooks Extension Framework implementation plan, this PR adds a filter before the unenrollment process starts.

Supporting information

Testing instructions

  1. Install openedx-filters library:
pip install openedx-filters==0.5.0
  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:
  • Un-enroll from a course org.openedx.learning.course.unenrollment.started.v1
OPEN_EDX_FILTERS_CONFIG = {
    "org.openedx.learning.course.unenrollment.started.v1": {
        "fail_silently": False,
        "pipeline": [
            "openedx_filters_samples.samples.pipeline.StopUnenrollment"
        ]
    },
}

And with this one, the user's profile will be modified before the unenrollment process starts

OPEN_EDX_FILTERS_CONFIG = {
    "org.openedx.learning.course.unenrollment.started.v1": {
        "fail_silently": False,
        "pipeline": [
            "openedx_filters_samples.samples.pipeline.ModifyUserProfileBeforeUnenrollment"
        ]
    },
}

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 needs triage labels Feb 17, 2022
@openedx-webhooks
Copy link

Thanks for the pull request, @mariajgrimaldi! I've created BLENDED-1101 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.

@mariajgrimaldi mariajgrimaldi force-pushed the MJG/unenrollment-filter branch 3 times, most recently from a3321f6 to 52955ad Compare February 22, 2022 18:12
@mariajgrimaldi mariajgrimaldi force-pushed the MJG/unenrollment-filter branch 3 times, most recently from 9c5a53e to 3a67223 Compare March 2, 2022 13:07
@ghassanmas
Copy link
Member

How exactly am I suppose to change the filter settings, should I create settings variable for both cases above?, should the OPEN_EDX_FILTERS_CONFIG exist before changing it?
Should the openedx-filters app in listed in the lms INSTALLED_APPS ?

@mariajgrimaldi
Copy link
Member Author

mariajgrimaldi commented Mar 7, 2022

Hi there @ghassanmas! Thank you for taking the time to review this. We appreciate it.

Well, openedx-filters is a python library that reads the filters information from OPEN_EDX_FILTERS_CONFIG. You should create the setting in your configuration file of choice, eg, I'm currently using the devstack so I put mine in devstack_docker:

# lms/envs/devstack_docker.py
 OPEN_EDX_FILTERS_CONFIG = {
    "org.openedx.learning.course.unenrollment.started.v1": {
        "fail_silently": False,
        "pipeline": [
            "openedx_filters_samples.samples.pipeline.ModifyModeBeforeUnenrollment"
        ]
    },
}

or

# lms/envs/devstack_docker.py
 OPEN_EDX_FILTERS_CONFIG = {
    "org.openedx.learning.course.unenrollment.started.v1": {
        "fail_silently": False,
        "pipeline": [
            "openedx_filters_samples.samples.pipeline.StopUnenrollment"
        ]
    },
}

@felipemontoya
Copy link
Member

Hey @mariajgrimaldi,

I reviewed this and I found that on the backend it works just as I would expect.

In your example, using "openedx_filters_samples.samples.pipeline.ModifyModeBeforeEnrollment" is actually not going to work, because the arguments are different, but I found ModifyUserProfileBeforeUnenrollment which is working nicely.

Using "openedx_filters_samples.samples.pipeline.StopUnenrollment" stops the unenrollment from happening and it raises the exception and all.

Now, what I think it could still be improved, is that StopUnenrollment raises an exception which is never catched and results in a 500 error that the UI never shows. Instead it says something about the refund which is likely to confuse the user.

image

We would need to catch the exception at https://github.com/openedx/edx-platform/blob/db32ff2cdf678fa8edd12c9da76a76eef0478614/common/djangoapps/student/views/management.py#L413 to pass the str as the response message and make the js view support it at https://github.com/openedx/edx-platform/blob/db32ff2cdf678fa8edd12c9da76a76eef0478614/lms/static/js/learner_dashboard/views/unenroll_view.js#L70

@mariajgrimaldi
Copy link
Member Author

Hi there, @felipemontoya. Well spotted! I already fixed the testing instructions 😄

I'll try adding the message to the UI, and let you know! Thank you again.

@mariajgrimaldi
Copy link
Member Author

Hello again @felipemontoya,

what do you think about this? 😎

image

I'm currently implementing some unit tests for the new changes. Stay tuned!

@mariajgrimaldi mariajgrimaldi force-pushed the MJG/unenrollment-filter branch from b452bbe to b33e1a6 Compare March 9, 2022 19:02
@felipemontoya
Copy link
Member

It looks great @mariajgrimaldi. Thanks!

For anyone reviewing this, the message "You can't un-enroll from this site" is returned by the plugin, so the actual message will vary depending on the filter that is implemented.

From my end this looks good and ready to be merged.

Based on your previous work on this files, I think that the most likely reviewers for this would be:

  • @ormsbee you know the models and the filters framework.
  • @mikix you know the UI that allows the user to unregister/shows the message.
  • @bmedx you know the API and the view that is called to actually perform the unernollment.

Your comments here would be priceless. Thanks

@felipemontoya felipemontoya requested review from mikix and ormsbee March 9, 2022 20:31
@ghassanmas
Copy link
Member

ghassanmas commented Mar 9, 2022

I got same result as what @felipemontoya had metioned above:
Before applying config settings I could unroll, after applying the config settings I got the fund message along with an exception in the logs

lms_1                        | 2022-03-09 21:49:34,108 INFO 8 [tracking] [user 8] [ip xx.xx.xx.xx] logger.py:41 - {"name": "/change_enrollment", "context": {"user_id": 8, "path": "/change_enrollment", "course_id": "", "org_id": "", "enterprise_uuid": ""}, "username": "ghassanmas", "session": "7b1594cf5e5031e2b17ee7c43fe60b42", "ip": "xx.xx.xx.xx", "agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36", "host": "edx.gsgapp.io", "referer": "http://edx.gsgapp.io/dashboard", "accept_language": "en-US,en;q=0.9,ar-IL;q=0.8,ar;q=0.7,en-IL;q=0.6", "event": "{\"GET\": {}, \"POST\": {\"course_id\": [\"course-v1:serser+DemoX+20020\"], \"enrollment_action\": [\"unenroll\"]}}", "time": "2022-03-09T21:49:34.107980+00:00", "event_type": "/change_enrollment", "event_source": "server", "page": null}
lms_1                        | 2022-03-09 21:49:34,125 ERROR 8 [openedx_filters.tooling] [user 8] [ip xx.x.xx.xx] tooling.py:227 - Exception raised while running 'StopUnenrollment':
lms_1                        |  You can't un-enroll from this site.
lms_1                        | Traceback (most recent call last):
lms_1                        |   File "/openedx/venv/lib/python3.8/site-packages/openedx_filters/tooling.py", line 217, in run_pipeline
lms_1                        |     result = step_runner.run_filter(**accumulated_output)
lms_1                        |   File "/openedx/venv/lib/python3.8/site-packages/openedx_filters_samples/samples/pipeline.py", line 301, in run_filter
lms_1                        |     raise CourseUnenrollmentStarted.PreventUnenrollment(
lms_1                        | openedx_filters.learning.filters.CourseUnenrollmentStarted.PreventUnenrollment: You can't un-enroll from this site.

Anyone can try that at http://edx.gsgapp.io the settings to cancel or stop unrollment is active

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe the dashboard is the only spot you can unenroll from, yeah?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I believe so! At least using this view

@mariajgrimaldi mariajgrimaldi force-pushed the MJG/unenrollment-filter branch from a4517ea to 6e408f0 Compare March 15, 2022 17:56
@mariajgrimaldi mariajgrimaldi force-pushed the MJG/unenrollment-filter branch from 6e408f0 to 73533f0 Compare March 15, 2022 18:51
@felipemontoya
Copy link
Member

@mariajgrimaldi can we go ahead and merge this? we have 2 approvals now.

@mariajgrimaldi
Copy link
Member Author

mariajgrimaldi commented Mar 17, 2022

@mariajgrimaldi can we go ahead and merge this? we have 2 approvals now.

Yes @felipemontoya, I'll do it first thing in the morning. Thanks for the reminder.

@mikix mikix merged commit 15e6250 into openedx:master Mar 17, 2022
@openedx-webhooks
Copy link

@mariajgrimaldi 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future.

@edx-pipeline-bot
Copy link
Contributor

EdX Release Notice: This PR has been deployed to the production environment.

1 similar comment
@edx-pipeline-bot
Copy link
Contributor

EdX Release Notice: This PR has been deployed to the production environment.

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 merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants