diff --git a/CHANGELOG.md b/CHANGELOG.md index 868b6262..5deaff07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## v1.0.49 (2022-11-01) + +- Enable SMTP email backend by default +- Fix Grafana sidebar frontend bug + ## v1.0.48 (2022-11-01) - verify_number management command diff --git a/engine/apps/email/tasks.py b/engine/apps/email/tasks.py index 3fdf4d4e..d9054745 100644 --- a/engine/apps/email/tasks.py +++ b/engine/apps/email/tasks.py @@ -39,6 +39,20 @@ def notify_user_async(user_pk, alert_group_pk, notification_policy_pk): logger.warning(f"User notification policy {notification_policy_pk} does not exist") return + # create an error log in case EMAIL_HOST is not specified + if not live_settings.EMAIL_HOST: + UserNotificationPolicyLogRecord.objects.create( + author=user, + type=UserNotificationPolicyLogRecord.TYPE_PERSONAL_NOTIFICATION_FAILED, + notification_policy=notification_policy, + alert_group=alert_group, + reason="Error while sending email", + notification_step=notification_policy.step, + notification_channel=notification_policy.notify_by, + ) + logger.error(f"Error while sending email: empty EMAIL_HOST env variable") + return + emails_left = user.organization.emails_left(user) if emails_left <= 0: UserNotificationPolicyLogRecord.objects.create( diff --git a/engine/apps/email/tests/test_notify_user.py b/engine/apps/email/tests/test_notify_user.py index a6b1c356..f5a10601 100644 --- a/engine/apps/email/tests/test_notify_user.py +++ b/engine/apps/email/tests/test_notify_user.py @@ -24,6 +24,7 @@ def test_notify_user( make_user_notification_policy, ): settings.EMAIL_BACKEND = "django.core.mail.backends.locmem.EmailBackend" + settings.EMAIL_HOST = "test" organization = make_organization() user = make_user_for_organization(organization) @@ -44,6 +45,42 @@ def test_notify_user( assert len(mail.outbox) == 1 +@pytest.mark.django_db +def test_notify_empty_email_host( + settings, + make_organization, + make_user_for_organization, + make_token_for_organization, + make_alert_receive_channel, + make_alert_group, + make_alert, + make_user_notification_policy, +): + settings.EMAIL_BACKEND = "django.core.mail.backends.locmem.EmailBackend" + settings.EMAIL_HOST = None + + organization = make_organization() + user = make_user_for_organization(organization) + + alert_receive_channel = make_alert_receive_channel(organization) + alert_group = make_alert_group(alert_receive_channel) + + make_alert(alert_group=alert_group, raw_request_data=alert_receive_channel.config.example_payload) + + notification_policy = make_user_notification_policy( + user, + UserNotificationPolicy.Step.NOTIFY, + notify_by=8, + important=False, + ) + + notify_user_async(user.pk, alert_group.pk, notification_policy.pk) + assert len(mail.outbox) == 0 + + log_record = notification_policy.personal_log_records.last() + assert log_record.type == UserNotificationPolicyLogRecord.TYPE_PERSONAL_NOTIFICATION_FAILED + + @pytest.mark.django_db def test_notify_user_bad_smtp_host( settings, @@ -56,6 +93,7 @@ def test_notify_user_bad_smtp_host( make_user_notification_policy, ): settings.EMAIL_BACKEND = "django.core.mail.backends.locmem.EmailBackend" + settings.EMAIL_HOST = "test" organization = make_organization() user = make_user_for_organization(organization) @@ -93,6 +131,7 @@ def test_notify_user_no_emails_left( make_user_notification_policy, ): settings.EMAIL_BACKEND = "django.core.mail.backends.locmem.EmailBackend" + settings.EMAIL_HOST = "test" organization = make_organization() user = make_user_for_organization(organization) diff --git a/engine/settings/base.py b/engine/settings/base.py index 6235c3e3..e701ea24 100644 --- a/engine/settings/base.py +++ b/engine/settings/base.py @@ -50,7 +50,7 @@ BASE_URL = os.environ.get("BASE_URL") # Root URL of OnCall backend # Feature toggles FEATURE_LIVE_SETTINGS_ENABLED = getenv_boolean("FEATURE_LIVE_SETTINGS_ENABLED", default=True) FEATURE_TELEGRAM_INTEGRATION_ENABLED = getenv_boolean("FEATURE_TELEGRAM_INTEGRATION_ENABLED", default=True) -FEATURE_EMAIL_INTEGRATION_ENABLED = getenv_boolean("FEATURE_EMAIL_INTEGRATION_ENABLED", default=False) +FEATURE_EMAIL_INTEGRATION_ENABLED = getenv_boolean("FEATURE_EMAIL_INTEGRATION_ENABLED", default=True) FEATURE_SLACK_INTEGRATION_ENABLED = getenv_boolean("FEATURE_SLACK_INTEGRATION_ENABLED", default=True) FEATURE_WEB_SCHEDULES_ENABLED = getenv_boolean("FEATURE_WEB_SCHEDULES_ENABLED", default=False) GRAFANA_CLOUD_ONCALL_HEARTBEAT_ENABLED = getenv_boolean("GRAFANA_CLOUD_ONCALL_HEARTBEAT_ENABLED", default=True) diff --git a/grafana-plugin/src/pages/chat-ops/parts/tabs/TelegramSettings/TelegramSettings.module.css b/grafana-plugin/src/pages/chat-ops/parts/tabs/TelegramSettings/TelegramSettings.module.css index ecd192db..158c14a2 100644 --- a/grafana-plugin/src/pages/chat-ops/parts/tabs/TelegramSettings/TelegramSettings.module.css +++ b/grafana-plugin/src/pages/chat-ops/parts/tabs/TelegramSettings/TelegramSettings.module.css @@ -12,7 +12,7 @@ width: 725px; } -ul { +.features-list > ul { margin: 20px 30px; } diff --git a/grafana-plugin/src/pages/chat-ops/parts/tabs/TelegramSettings/TelegramSettings.tsx b/grafana-plugin/src/pages/chat-ops/parts/tabs/TelegramSettings/TelegramSettings.tsx index 79db0f35..c6eb5dc5 100644 --- a/grafana-plugin/src/pages/chat-ops/parts/tabs/TelegramSettings/TelegramSettings.tsx +++ b/grafana-plugin/src/pages/chat-ops/parts/tabs/TelegramSettings/TelegramSettings.tsx @@ -102,11 +102,13 @@ class TelegramSettings extends Component { Features - +
+
    +
  • perform actions (acknowledge, resolve, silence)
  • +
  • discuss alerts in comments
  • +
  • notifications to users accounts will be served as links to the main channel
  • +
+
Make sure your team connects Telegram in their OnCall user profiles too or they cannot manage alert groups.