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

feat: adds openedx-filter hook to the course enrollments site #31331

Conversation

JuanDavidBuitrago
Copy link
Contributor

@JuanDavidBuitrago JuanDavidBuitrago commented Nov 23, 2022

Description

This PR introduces a new openedx-filters event org.openedx.learning.course_enrollment_queryset.requested.v1. This is implemented to guaranty multi tenancy in eox-tenant in course enrollments request, but eox-tenant is only an example would consider use.

Impact by the change on GET request:

  • http://{lms_custom_site}/api/enrollment/v1/enrollment
  • http://{lms_custom_site}/api/mobile/v1/users/{username}/course_enrollments/

Supporting information

There are not openedx related tickets. The related PR are:

Testing instructions

The change can be tested with testing instructions in eox-tenant plugin.

Deadline

"None"

Other information

Warning: Once accepted this PR, it has to be merged only after openedx/openedx-filters#47 is merged and the requirements in this PR are updated.

Settings

EDXAPP_EXTRA_REQUIREMENTS:
  - name: git+https://github.com/eduNEXT/eox-tenant.git@v3.6.0

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Nov 23, 2022
@openedx-webhooks
Copy link

openedx-webhooks commented Nov 23, 2022

Thanks for the pull request, @JuanDavidBuitrago! Please note that it may take us up to several weeks or months to complete a review and merge your PR.

Feel free to add as much of the following information to the ticket as you can:

  • supporting documentation
  • Open edX discussion forum threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here.

This is currently a draft pull request. When it is ready for our review and all tests are green, click "Ready for Review", or remove "WIP" from the title, as appropriate.

@JuanDavidBuitrago
Copy link
Contributor Author

Hi @mariajgrimaldi and @felipemontoya, could you help me review this?

@mphilbrick211
Copy link

Hi @JuanDavidBuitrago! Just checking in on this. Are you planning to pursue this pull request? It looks like some failing tests need to be re-run.

@mphilbrick211 mphilbrick211 added the waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. label Dec 16, 2022
@JuanDavidBuitrago
Copy link
Contributor Author

Hi @JuanDavidBuitrago! Just checking in on this. Are you planning to pursue this pull request? It looks like some failing tests need to be re-run.

Hi @mphilbrick211! Yes, I'm planning to pursue this. I just need to make changes in openedx/openedx-filters#47 to update some requirements and solve tests in this PR.

@openedx-webhooks openedx-webhooks removed the waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. label Dec 20, 2022
@mphilbrick211
Copy link

Hi @JuanDavidBuitrago! Just checking in on this. Are you planning to pursue this pull request? It looks like some failing tests need to be re-run.

Hi @mphilbrick211! Yes, I'm planning to pursue this. I just need to make changes in openedx/openedx-filters#47 to update some requirements and solve tests in this PR.

Hi @JuanDavidBuitrago! Just checking in on this!

Comment on lines +344 to +350
try:
## .. filter_implemented_name: CourseEnrollmentQuerysetRequested
## .. filter_type: org.openedx.learning.course_enrollment_queryset.requested.v1
enrollments = CourseEnrollmentQuerysetRequested.run_filter(enrollments=enrollments)
except CourseEnrollmentQuerysetRequested.PreventEnrollmentQuerysetRequest as exc:
raise EnrollmentRequestNotAllowed(str(exc)) from exc
Copy link
Member

Choose a reason for hiding this comment

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

Remember to add tests for this implementation. You could use these tests as guidance.

Copy link
Member

Choose a reason for hiding this comment

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

Can you add a test testing this line?

Copy link
Member

Choose a reason for hiding this comment

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

^ I second this comment again

@mphilbrick211 mphilbrick211 added the waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. label Jan 23, 2023
@mphilbrick211
Copy link

Hi @JuanDavidBuitrago - just checking in to see if you have an update?

@JuanDavidBuitrago
Copy link
Contributor Author

Hi @mphilbrick211 and @mariajgrimaldi

I need to do some tests with everything integrated to verify that everything continues to work well, I need a little more time.

@JuanDavidBuitrago JuanDavidBuitrago force-pushed the JDB/add_filter_hook_to_enrollment_site branch from de032b6 to 54866f8 Compare March 3, 2023 04:23
@JuanDavidBuitrago
Copy link
Contributor Author

Hi, we are studying where else we should add the filter to make it as complete as possible

@mariajgrimaldi
Copy link
Member

mariajgrimaldi commented Mar 13, 2023

Addressing @JuanDavidBuitrago comment:

IMO, we have two options for this implementation:

  1. Use the filter in the CourseEnrollment model manager (example), so every time the course enrollments' queryset is requested, the filter is executed. Now, we'll have to keep in mind that this approach might be too aggressive (overriding the models' manager). All operations related to the course enrollment queryset will pass through the filter. Even though the filter acts as a noop when not configured, it executes a piece of code before returning. So a delay will be added to the operation.

  2. Identify relevant places where the enrollment queryset is used so we can apply the filter -as you're currently doing-. I say relevant since I don't think covering all cases is possible.

I like option one, I'm just hesitant about how aggressive it is and how much it affects the whole service. It's not just getting the queryset when making an API call, it's related to all the models queries. Option two is good as well, but we must clarify the cases we cover.

I'd like to know what you both think, including @felipemontoya.

@JuanDavidBuitrago
Copy link
Contributor Author

At the moment, we only have included the use of the filter when we make a request with a user without staff permissions.
http://{lms_custom_site}/api/enrollment/v1/enrollment from desktop and http://{lms_custom_site}/api/mobile/v1/users/{username}/course_enrollments from mobile

@mariajgrimaldi have you identified another connection point?

@mariajgrimaldi
Copy link
Member

@JuanDavidBuitrago: there are many places where this could go.
/api/enrollment/v1/enrollment -> for browsers
/api/enrollment/v1/enrollments -> for browsers
/api/mobile/v1/users/{username}/course_enrollments -> mobile
... and so on. There's also the implementation detail I mentioned above. What do you think about that? I'm okay If this is the implementation we're going for, but let me know.

@JuanDavidBuitrago
Copy link
Contributor Author

With option two that you put above, I think we can cover what is necessary to obtain the course enrollments that we want, we have already tested it in the edx-platform fork that we manage eduNEXT/edunext-platform#696
I'm not sure if we can cover other cases without problems. @felipemontoya's opinion here would be very useful

@mphilbrick211 mphilbrick211 removed the waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. label Mar 15, 2023
@mphilbrick211
Copy link

Hi @JuanDavidBuitrago - just following up on this :)

CC: @mariajgrimaldi & @felipemontoya

@mphilbrick211
Copy link

Hi @JuanDavidBuitrago! Looks like some tests are failing and need to be re-run.

@JuanDavidBuitrago JuanDavidBuitrago force-pushed the JDB/add_filter_hook_to_enrollment_site branch 6 times, most recently from 7477128 to 14df646 Compare August 10, 2023 16:42
@JuanDavidBuitrago JuanDavidBuitrago force-pushed the JDB/add_filter_hook_to_enrollment_site branch from 14df646 to 11e386d Compare August 10, 2023 17:17
@JuanDavidBuitrago JuanDavidBuitrago force-pushed the JDB/add_filter_hook_to_enrollment_site branch 4 times, most recently from dd5deb0 to c470e52 Compare August 28, 2023 02:36
Comment on lines +220 to +228
Test filter enrollment queryset when a request is made.

Expected result:
- CourseEnrollmentQuerysetRequested is triggered and executes TestCourseEnrollmentsPipelineStep.
- The result is a list of course enrollments queryset filter by org
"""
enrollments = get_course_enrollments(self.user)

self.assertListEqual(self.enrollment, enrollments)
Copy link
Member

Choose a reason for hiding this comment

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

This is not true, is it? This tests that when the filter is not turned on, then the filtering doesn't occur. Or am I missing something?

Comment on lines +254 to +255
self.assertEqual(expected_enrollment, enrollments)
self.assertAlmostEqual(len(enrollments), len(expected_enrollment), 1)
Copy link
Member

Choose a reason for hiding this comment

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

Please, check that all the courses associated with the enrollment have the demo org

Comment on lines +67 to +69
Expected result:
- CourseEnrollmentQuerysetRequested is triggered and executes TestCourseEnrollmentsPipelineStep.
- The result is a list of course enrollments queryset filter by org
Copy link
Member

Choose a reason for hiding this comment

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

You'll need to update the docstring here too.

view.request = self.mock_request
enrollments = view.get_queryset()

self.assertEqual(self.enrollment, enrollments)
Copy link
Member

Choose a reason for hiding this comment

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

can we check that both orgs demo and test are included here?

enrollments = view.get_queryset()

self.assertAlmostEqual(len(enrollments), len(expected_enrollment), 1)
self.assertEqual(expected_enrollment.course.org, "helo")
Copy link
Member

Choose a reason for hiding this comment

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

Not sure what's this. Isn't the org supposed to be demo?

@mariajgrimaldi
Copy link
Member

I left a few more comments. Also, can we make the tests pass?

@mariajgrimaldi
Copy link
Member

@mphilbrick211: I spoke internally with @JuanDavidBuitrago's team, and they told me they didn't have the capacity to take this on right now. I'll move this PR to draft to give them time to work on it. Thanks!

@mariajgrimaldi mariajgrimaldi marked this pull request as draft September 7, 2023 14:43
@JuanDavidBuitrago
Copy link
Contributor Author

Hi @mphilbrick211 @mariajgrimaldi, thank you for your patience.

@mphilbrick211 mphilbrick211 removed the waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. label Oct 24, 2023
@mphilbrick211
Copy link

Closing this for now. We can reopen in the future if needed. Thanks!

@openedx-webhooks
Copy link

@JuanDavidBuitrago 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.

@mphilbrick211 mphilbrick211 added the closed inactivity PR was closed because the author abandoned it label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed inactivity PR was closed because the author abandoned it open-source-contribution PR author is not from Axim or 2U
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants