Files
edx-platform/lms/djangoapps/bulk_email/policies.py
Feanil Patel 9cf2f9f298 Run 2to3 -f future . -w
This will remove imports from __future__ that are no longer needed.

https://docs.python.org/3.5/library/2to3.html#2to3fixer-future
2019-12-30 10:35:30 -05:00

24 lines
765 B
Python

"""Course Email optOut Policy"""
from edx_ace.channel import ChannelType
from edx_ace.policy import Policy, PolicyResult
from opaque_keys.edx.keys import CourseKey
from bulk_email.models import Optout
class CourseEmailOptout(Policy):
def check(self, message):
course_ids = message.context.get('course_ids')
if not course_ids:
return PolicyResult(deny=frozenset())
# pylint: disable=line-too-long
course_keys = [CourseKey.from_string(course_id) for course_id in course_ids]
if Optout.objects.filter(user__username=message.recipient.username, course_id__in=course_keys).count() == len(course_keys):
return PolicyResult(deny={ChannelType.EMAIL})
return PolicyResult(deny=frozenset())