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: reactive schedules nudge emails filter #56

Open
wants to merge 18 commits into
base: nau/redwood.master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions nau_openedx_extensions/filters/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from fnmatch import fnmatch

from django.conf import settings
from django.db.models.query import QuerySet
from django.utils.translation import gettext as _
from openedx_filters import PipelineStep
from openedx_filters.learning.filters import CourseEnrollmentStarted
Expand Down Expand Up @@ -77,3 +78,39 @@ def _is_user_email_allowed(user, domains_allowed):
if user_domain == domain or fnmatch(user_domain, f"*.{domain}"):
return True
return False


class FilterUsersWithAllowedNewsletter(PipelineStep):
"""
Filter the Schedules QuerySet to only keep those whose associated user has
the `allow_newsletter` field set to `True`. If the user does not have the
`allow_newsletter` field set to `True`, or if the field does not exist, the
Schedule will be filtered out.

Example usage:

Add the following configurations to your configuration file:

```
OPEN_EDX_FILTERS_CONFIG = {
"org.openedx.learning.schedule.queryset.requested.v1": {
"fail_silently": False,
"pipeline": [
"nau_openedx_extensions.filters.pipeline.FilterUsersWithAllowedNewsletter",
],
},
}
```
"""

def run_filter(self, schedules: QuerySet) -> dict: # pylint: disable=arguments-differ
"""
Execute filter that filters users with allowed newsletter.

Arguments:
schedules (QuerySet): Queryset of schedules to be sent.

Returns:
dict: Dictionary with the filtered schedules.
"""
return {"schedules": schedules.filter(enrollment__user__nauuserextendedmodel__allow_newsletter=True)}
Binary file modified nau_openedx_extensions/locale/en/LC_MESSAGES/django.mo
Binary file not shown.
8 changes: 4 additions & 4 deletions nau_openedx_extensions/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2024-10-02 13:56+0100\n"
"POT-Creation-Date: 2024-12-12 12:58-0500\n"
"PO-Revision-Date: 2021-02-15 15:56+0000\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: en\n"
Expand Down Expand Up @@ -108,18 +108,18 @@ msgstr ""
"href='https://www.nau.edu.pt/legal/consentimento-para-o-envio-de-"
"newsletters/'>consent to the sending of newsletters</a>"

#: nau_openedx_extensions/filters/pipeline.py:50
#: nau_openedx_extensions/filters/pipeline.py:51
msgid ""
"You need to activate your account before you can enroll in the course. "
"Check your {email} inbox for an account activation link from "
"{platform_name}."
msgstr ""

#: nau_openedx_extensions/filters/pipeline.py:62
#: nau_openedx_extensions/filters/pipeline.py:63
msgid "If you think this is an error, contact the course support."
msgstr ""

#: nau_openedx_extensions/filters/pipeline.py:63
#: nau_openedx_extensions/filters/pipeline.py:64
#, python-format
msgid ""
"You can't enroll on this course because your email domain is not allowed."
Expand Down
Binary file modified nau_openedx_extensions/locale/pt_PT/LC_MESSAGES/django.mo
Binary file not shown.
8 changes: 4 additions & 4 deletions nau_openedx_extensions/locale/pt_PT/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2024-10-02 13:56+0100\n"
"POT-Creation-Date: 2024-12-12 12:58-0500\n"
"PO-Revision-Date: 2021-02-15 15:56+0000\n"
"Last-Translator: Ivo Branco <[email protected]>\n"
"Language: pt_PT\n"
Expand Down Expand Up @@ -110,7 +110,7 @@ msgstr ""
"href='https://www.nau.edu.pt/legal/consentimento-para-o-envio-de-"
"newsletters/'>consentimento para o envio de newsletters</a>"

#: nau_openedx_extensions/filters/pipeline.py:50
#: nau_openedx_extensions/filters/pipeline.py:51
msgid ""
"You need to activate your account before you can enroll in the course. "
"Check your {email} inbox for an account activation link from "
Expand All @@ -120,11 +120,11 @@ msgstr ""
"Verifique no seu e-mail {email} o link de ativação da conta "
"{platform_name}."

#: nau_openedx_extensions/filters/pipeline.py:62
#: nau_openedx_extensions/filters/pipeline.py:63
msgid "If you think this is an error, contact the course support."
msgstr "Se achar que se trata de um erro, contacte o suporte."

#: nau_openedx_extensions/filters/pipeline.py:63
#: nau_openedx_extensions/filters/pipeline.py:64
#, python-format
msgid ""
"You can't enroll on this course because your email domain is not allowed."
Expand Down
4 changes: 2 additions & 2 deletions requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ edx-opaque-keys[django]
six
future; python_version < "3.0"
web-fragments
openedx-filters==1.8.1
openedx-events==9.10.0
openedx-filters==1.12.0
openedx-events==9.15.0
14 changes: 7 additions & 7 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
#
# make upgrade
#
amqp==2.6.1 # via kombu
billiard==3.6.4.0 # via celery
celery==4.4.7 # via -c requirements/constraints.txt, -r requirements/base.in
amqp==5.2.0 # via kombu
billiard==4.2.0 # via celery
celery==5.4.0 # via -c requirements/constraints.txt, -r requirements/base.in
django==2.2.25 # via -c requirements/constraints.txt, edx-opaque-keys, openedx-filters
edx-opaque-keys[django]==2.2.0 # via -c requirements/constraints.txt, -r requirements/base.in
kombu==4.6.11 # via celery
openedx-filters==1.8.1 # via -c requirements/constraints.txt, -r requirements/base.in
openedx-events==9.10.0
kombu==5.3.4 # via celery
openedx-filters==1.12.0 # via -c requirements/constraints.txt, -r requirements/base.in
openedx-events==9.15.0
pbr==5.10.0 # via stevedore
pymongo==4.2.0 # via edx-opaque-keys
pytz==2022.2.1 # via celery, django
six==1.16.0 # via -r requirements/base.in
sqlparse==0.4.2 # via django
stevedore==4.0.0 # via edx-opaque-keys
vine==1.3.0 # via amqp, celery
vine==5.1.0 # via amqp, celery
web-fragments==2.0.0 # via -r requirements/base.in
4 changes: 2 additions & 2 deletions requirements/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
celery<5.0
Django==2.2.25
edx-opaque-keys[django]==2.2.0
openedx-filters==1.8.1
openedx-events==9.10.0
openedx-filters==1.12.0
openedx-events==9.15.0
pip-tools<5.4
click==7.1.2
2 changes: 1 addition & 1 deletion requirements/django.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
celery==4.4.7 # via -c requirements/constraints.txt, -r requirements/base.txt
celery==5.4.0 # via -c requirements/constraints.txt, -r requirements/base.txt
django==2.2.25 # via -c requirements/constraints.txt, -r requirements/base.txt, edx-opaque-keys, openedx-filters
12 changes: 6 additions & 6 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#
# make upgrade
#
amqp==2.6.1 # via -r requirements/base.txt, kombu
amqp==5.2.0 # via -r requirements/base.txt, kombu
astroid==2.12.9 # via pylint, pylint-celery
attrs==22.1.0 # via pytest
billiard==3.6.4.0 # via -r requirements/base.txt, celery
billiard==4.2.0 # via -r requirements/base.txt, celery
click-log==0.4.0 # via edx-lint
click==7.1.2 # via -c requirements/constraints.txt, click-log, code-annotations, edx-lint
code-annotations==1.3.0 # via edx-lint
Expand All @@ -18,12 +18,12 @@ edx-opaque-keys[django]==2.2.0 # via -c requirements/constraints.txt, -r requir
iniconfig==1.1.1 # via pytest
isort==5.10.1 # via pylint
jinja2==3.1.2 # via code-annotations
kombu==4.6.11 # via -r requirements/base.txt, celery
kombu==5.3.4 # via -r requirements/base.txt, celery
lazy-object-proxy==1.7.1 # via astroid
markupsafe==2.1.1 # via jinja2
mccabe==0.7.0 # via pylint
openedx-filters==1.8.1 # via -c requirements/constraints.txt, -r requirements/base.txt
openedx-events==9.10.0
openedx-filters==1.12.0 # via -c requirements/constraints.txt, -r requirements/base.txt
openedx-events==9.15.0
packaging==21.3 # via pytest
pbr==5.10.0 # via -r requirements/base.txt, stevedore
platformdirs==2.5.2 # via pylint
Expand All @@ -47,6 +47,6 @@ text-unidecode==1.3 # via python-slugify
tomli==2.0.1 # via pylint, pytest
tomlkit==0.11.4 # via pylint
typing-extensions==4.3.0 # via astroid, pylint
vine==1.3.0 # via -r requirements/base.txt, amqp, celery
vine==5.1.0 # via -r requirements/base.txt, amqp, celery
web-fragments==2.0.0 # via -r requirements/base.txt
wrapt==1.14.1 # via astroid
Loading