Ejemplo n.º 1
0
    def check(self, message):
        course_ids = message.context.get('course_ids')
        if not course_ids:
            return PolicyResult(deny=frozenset())

        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())
Ejemplo n.º 2
0
    def check(self, message):
        course_id = message.context.get('course_id')
        if not course_id:
            return PolicyResult(deny=frozenset())

        course_key = CourseKey.from_string(course_id)
        if Optout.objects.filter(user__username=message.recipient.username,
                                 course_id=course_key).exists():
            return PolicyResult(deny={ChannelType.EMAIL})

        return PolicyResult(deny=frozenset())
Ejemplo n.º 3
0
 def test_policy_no_course_id(self):
     """
     Make sure the policy denies ACE emails if there is no course id in the context.
     """
     message = self.create_test_message()
     message.context = {}
     channel_mods = self.policy.check(message)
     self.assertEqual(channel_mods, PolicyResult(deny=set()))
Ejemplo n.º 4
0
    def test_policy_optedout(self):
        """
        Make sure the policy prevents ACE emails if the user is opted-out.
        """
        self._set_email_optout(True)

        channel_mods = self.policy.check(self.create_test_message())
        self.assertEqual(channel_mods, PolicyResult(deny={ChannelType.EMAIL}))
Ejemplo n.º 5
0
 def test_policy_optedin(self):
     """
     Make sure the policy allows ACE emails if the user is opted-in.
     """
     channel_mods = self.policy.check(self.create_test_message())
     self.assertEqual(channel_mods, PolicyResult(deny=set()))