diff --git a/engine/apps/email/models.py b/engine/apps/email/models.py index 9118002ffb..946113199f 100644 --- a/engine/apps/email/models.py +++ b/engine/apps/email/models.py @@ -1,13 +1,7 @@ -import typing import uuid from django.db import models -if typing.TYPE_CHECKING: - from apps.alerts.models import Alert, AlertGroup - from apps.base.models import UserNotificationPolicy - from apps.user_management.models import User - class EmailMessageQuerySet(models.QuerySet): def create(self, **kwargs): @@ -20,12 +14,7 @@ def create(self, **kwargs): class EmailMessage(models.Model): - represents_alert: "Alert" - represents_alert_group: "AlertGroup" - notification_policy: typing.Optional["UserNotificationPolicy"] - receiver: typing.Optional["User"] - - objects: models.Manager["EmailMessage"] = EmailMessageQuerySet.as_manager() + objects = EmailMessageQuerySet.as_manager() message_uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) diff --git a/engine/apps/email/tests/test_notify_user.py b/engine/apps/email/tests/test_notify_user.py index 9625786c7f..0fd01b67d6 100644 --- a/engine/apps/email/tests/test_notify_user.py +++ b/engine/apps/email/tests/test_notify_user.py @@ -7,6 +7,7 @@ from apps.base.models import UserNotificationPolicy, UserNotificationPolicyLogRecord from apps.email.alert_rendering import build_subject_and_message +from apps.email.models import EmailMessage from apps.email.tasks import get_from_email, notify_user_async from apps.user_management.subscription_strategy.free_public_beta_subscription_strategy import ( FreePublicBetaSubscriptionStrategy, @@ -239,5 +240,7 @@ def test_notify_user_fallback_default_policy( notify_user_async(user.pk, alert_group.pk, None) assert len(mail.outbox) == 1 - log_record = UserNotificationPolicyLogRecord.objects.filter(author=user, alert_group=alert_group).last() + log_record = UserNotificationPolicyLogRecord.objects.filter(author=user, alert_group=alert_group).first() assert log_record.type == UserNotificationPolicyLogRecord.TYPE_PERSONAL_NOTIFICATION_SUCCESS + + EmailMessage.objects.get(receiver=user, represents_alert_group=alert_group, notification_policy=None)