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: add schedule queryset requested filter #235

Merged
merged 7 commits into from
Dec 12, 2024

Conversation

BryanttV
Copy link
Contributor

@BryanttV BryanttV commented Dec 6, 2024

Description: This PR adds a filter to modify the default schedule queryset of the automatic email messages in edx-platform.

The filter receives a single schedules argument of type QuerySet. An example of use is in this NAU pipeline that allows filtering the Schedules to only send emails to users who have the option to receive emails enabled in their profile (allow_newsletter=True)

JIRA: N/A

Dependencies:

Merge deadline: NO

Installation instructions:

  1. Create a Tutor environment.
  2. Install this plugin with the changes in this PR. ⚠️ Don't forget to run migrations.
  3. Install openedx-filters with the changes in this PR.
  4. Create a mount of edx-platform with the changes in this PR. Please use the changes in this branch (For testing purposes).

Testing instructions::

  1. Create a new Schedule config for your site in {lms_domain}/admin/schedules/scheduleconfig/

    image

  2. Create some users and enroll them in a course.

  3. Create an NAU user extended model for each user in {lms_domain}/admin/nau_openedx_extensions/nauuserextendedmodel/. Update the following field, depending on whether you want to receive the newsletter.

    image

  4. Create a Tutor inline plugin with the filter configuration:

    name: filter-settings
    version: 0.1.0
    patches:
      openedx-common-settings: |
        OPEN_EDX_FILTERS_CONFIG = {
          "org.openedx.learning.schedule.queryset.requested.v1": {
            "fail_silently": False,
            "pipeline": [
              "nau_openedx_extensions.filters.pipeline.FilterUsersWithAllowedNewsletter",
            ],
          },
        }
  5. Send a message of recurring nudge using the following command in the LMS container:

    python manage.py lms send_recurring_nudge {site} --date {enroll-date + 3 days}
    # Example
    python manage.py lms send_recurring_nudge local.edly.io:8000 --date 2024-12-07
  6. Depending on the value of each user's allow_newsletter field, you should see the filtered QuerySet of Schedules in the console. For example, here the Schedule was filtered because the user does not have the field set to True

    image

Reviewers:

Merge checklist:

  • All reviewers approved
  • CI build is green
  • Version bumped
  • Changelog record added
  • Documentation updated (not only docstrings)
  • Commits are squashed

Post merge:

  • Create a tag
  • Check new version is pushed to PyPI after tag-triggered build is finished.
  • Delete working branch (if not needed anymore)

Author concerns: N/A

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Dec 6, 2024
@openedx-webhooks
Copy link

openedx-webhooks commented Dec 6, 2024

Thanks for the pull request, @BryanttV!

What's next?

Please work through the following steps to get your changes ready for engineering review:

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.

🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads

🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

🔘 Let us know that your PR is ready for review:

Who will review my changes?

This repository is currently maintained by @openedx/hooks-extension-framework. Tag them in a comment and let them know that your changes are ready for review.

Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@mariajgrimaldi
Copy link
Member

Thanks for the contribution, @BryanttV! There's a PR against edx-platform@master, meaning this implementation should work with Tutor nightly. Is that correct? Can I use a nightly environment to test instead of Redwood? Let me know.

Copy link
Member

@mariajgrimaldi mariajgrimaldi left a comment

Choose a reason for hiding this comment

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

I haven't tested this proposal, I only did a static review. I'll be testing this once I get a reply to this comment. Thank you again!

Comment on lines 832 to 849
class PreventScheduleQuerySetRequest(OpenEdxFilterException):
"""
Custom class used to stop the schedule queryset request process.
"""

def __init__(self, message: str, schedules: QuerySet):
"""
Override init that defines specific arguments used in the schedule queryset request process.

Arguments:
message (str): error message for the exception.
schedules (QuerySet): Queryset of schedules to be sent
"""
super().__init__(message, schedules=schedules)
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 elaborate on which situations we would need to halt the filtering the queryset?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You might need to halt the filter when you get an error in the QuerySet filtering process. For example, here, the PreventScheduleQuerySetRequest exception is raised if the nauuserextendedmodel is not found as an attribute of the user model.

Copy link
Member

Choose a reason for hiding this comment

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

I understand. But what would the management command's behavior be when the exception is raised? Would it change in any way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it doesn't change. If the exception is raised, the same QuerySet is returned and the command execution continues.

Copy link
Member

Choose a reason for hiding this comment

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

I'm trying to figure out whether we need an exception in this case. For instance, see https://github.com/openedx/openedx-filters/blob/main/openedx_filters/learning/filters.py#L784-L800 which is used to replace the IDV URL with another URL; there's no different behavior when a condition is met. In contrast, when an enrollment is forbidden for X or Y, then an exception can be raised and the application handles the new behavior differently. Do you think we'd need an exception here?

Copy link

@MaferMazu MaferMazu Dec 11, 2024

Choose a reason for hiding this comment

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

We can use that exception if we want to prevent the schedules, but if not, I think it's better if we handle the default flow ("the same QuerySet is returned and the command execution continues") from the pipeline.

Comment related: openedx/edx-platform#35982 (comment).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your comments! In that case, the exception is not necessary. If you agree, I will remove it.

Comment on lines 826 to 828
"""
Custom class used to create schedule queryset filters filters and its custom methods.
"""
Copy link
Member

@mariajgrimaldi mariajgrimaldi Dec 10, 2024

Choose a reason for hiding this comment

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

I understand that these docstrings are kind of a template for these filters, but I admit that they don't say much, and I'd like that to change. Can we be more explicit about the filter's usage here and in the other docstrings? That would be very valuable.

Copy link
Contributor Author

@BryanttV BryanttV Dec 11, 2024

Choose a reason for hiding this comment

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

I agree. I updated the docstring: d12254d

@BryanttV
Copy link
Contributor Author

Thanks for the contribution, @BryanttV! There's a PR against edx-platform@master, meaning this implementation should work with Tutor nightly. Is that correct? Can I use a nightly environment to test instead of Redwood? Let me know.

Yes, You can also use a nightly environment.

@mariajgrimaldi
Copy link
Member

I'll be reviewing openedx/edx-platform#35982 as well to verify the proposal. Thank you.

@mariajgrimaldi
Copy link
Member

mariajgrimaldi commented Dec 10, 2024

@BryanttV: Thanks for the thorough explanation in both this PR and edx-platform's. We really appreciate it! Can you add a bit more info in the cover letter about what needs to be configured in the NAU extended profile model? Also, what exactly should I look for in the command line to check that this works? I added a log in the pipeline, that way I knew it was being called when running the command.

@BryanttV
Copy link
Contributor Author

Hi @mariajgrimaldi, thanks for the review! I updated the cover letter with more detailed instructions. Let me know if you need anything else.

@BryanttV BryanttV force-pushed the bav/add-schedule-queryset-filter branch from 22bf9d0 to d12254d Compare December 11, 2024 17:35
@BryanttV BryanttV force-pushed the bav/add-schedule-queryset-filter branch from d12254d to 1e3738f Compare December 12, 2024 12:15
@BryanttV BryanttV requested a review from MaferMazu December 12, 2024 14:43
@mariajgrimaldi
Copy link
Member

Can you also document this use case here? https://docs.openedx.org/projects/openedx-filters/en/latest/reference/real-life-use-cases.html. Thanks!

Copy link
Member

@mariajgrimaldi mariajgrimaldi left a comment

Choose a reason for hiding this comment

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

LGTM!

@BryanttV
Copy link
Contributor Author

Hi @mariajgrimaldi, I added the use case: 362768f

@mariajgrimaldi mariajgrimaldi merged commit f234354 into openedx:main Dec 12, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants