Files
edx-platform/lms/djangoapps/bulk_email/signals.py
bmedx 65147386c0 PLAT-2028 - Create mailing list retirement API endpoint
- Removes "email-optin" UserOrgTags for the user
- Creates and uses a new "UserRetireMailingsSignal" signal
- Creates and uses a new "CanRetireUser" permission
- Creates and uses a new setting "RETIREMENT_SERVICE_WORKER_USERNAME"
- Creates a signal handler to globally opt-out the user from Sailthru
2018-04-05 15:52:26 -04:00

26 lines
763 B
Python

"""
Signal handlers for the bulk_email app
"""
from django.dispatch import receiver
from student.models import CourseEnrollment
from openedx.core.djangoapps.user_api.accounts.signals import USER_RETIRE_MAILINGS
from .models import Optout
@receiver(USER_RETIRE_MAILINGS)
def force_optout_all(sender, **kwargs): # pylint: disable=unused-argument
"""
When a user is retired from all mailings this method will create an Optout
row for any courses they may be enrolled in.
"""
user = kwargs.get('user', None)
if not user:
raise TypeError('Expected a User type, but received None.')
for enrollment in CourseEnrollment.objects.filter(user=user):
Optout.objects.get_or_create(user=user, course_id=enrollment.course.id)