diff --git a/promgen/notification/user.py b/promgen/notification/user.py index c68634fb4..940785a0c 100644 --- a/promgen/notification/user.py +++ b/promgen/notification/user.py @@ -37,13 +37,13 @@ class NotificationUser(NotificationBase): form = FormUser - def splay(self, address): + def splay(self, address, **kwargs): try: user = User.objects.get(username=address) except User.DoesNotExist: logger.error("Missing user %s", address) else: - yield from models.Sender.objects.filter(obj=user) + yield from models.Sender.objects.filter(obj=user, **kwargs) def _send(self, address, data): user = User.objects.get(username=address) diff --git a/promgen/signals.py b/promgen/signals.py index d21947cbf..2116035fa 100644 --- a/promgen/signals.py +++ b/promgen/signals.py @@ -312,6 +312,7 @@ def check_user_subscription(sender, instance, created, request): @receiver(post_save, sender=models.Service) +@skip_raw def add_default_service_subscription(instance, created, **kwargs): if created and instance.owner: sender, new_notifier = models.Sender.objects.get_or_create( @@ -323,6 +324,7 @@ def add_default_service_subscription(instance, created, **kwargs): @receiver(post_save, sender=models.Project) +@skip_raw def add_default_project_subscription(instance, created, **kwargs): if created and instance.owner: sender, new_notifier = models.Sender.objects.get_or_create( diff --git a/promgen/tasks.py b/promgen/tasks.py index 9c03f4709..6bcc68dc1 100644 --- a/promgen/tasks.py +++ b/promgen/tasks.py @@ -60,7 +60,7 @@ def process_alert(alert_pk): logger.debug("Filtered out sender %s", sender) continue if hasattr(sender.driver, "splay"): - for splay in sender.driver.splay(sender.value): + for splay in sender.driver.splay(sender.value, enabled=True): senders[splay.sender].add(splay.value) else: senders[sender.sender].add(sender.value) diff --git a/promgen/tests/notification/test_user_email.py b/promgen/tests/notification/test_user_email.py index 1016499df..e2cef0cc8 100644 --- a/promgen/tests/notification/test_user_email.py +++ b/promgen/tests/notification/test_user_email.py @@ -50,3 +50,23 @@ def test_failed_user(self, mock_email): self.assertCount(models.AlertError, 0, "No failed alerts") self.assertEqual(mock_email.call_count, 1, "Still called email") + + @override_settings(PROMGEN=tests.SETTINGS) + @override_settings(CELERY_TASK_ALWAYS_EAGER=True) + @mock.patch("promgen.notification.email.send_mail") + def test_enabled(self, mock_email): + one = models.Service.objects.get(pk=1) + + # This notification is direct and disabled + NotificationEmail.create(obj=one, value="disabled.example@example.com", enabled=False) + # Our parent notification is enabled + NotificationUser.create(obj=one, value=one.owner.username) + # But the child notifier is disabled and shouldn't fire + NotificationEmail.create(obj=one.owner, value="enabled.example@example.com", enabled=False) + + response = self.fireAlert() + self.assertRoute(response, rest.AlertReceiver, 202) + self.assertCount(models.Alert, 1, "Alert Queued") + self.assertCount(models.AlertError, 0, "No failed alerts") + + self.assertEqual(mock_email.call_count, 0, "Should not call email")