From a4ab6696d6bced152c35616cbdbb30c03039e9ea Mon Sep 17 00:00:00 2001 From: Chloe Date: Mon, 7 Aug 2023 16:48:03 -0700 Subject: [PATCH] adding webhook and cleaning up html --- src/sentry/integrations/notify_disable.py | 4 ++-- .../sentry-app-notify-disable.html | 4 ++-- .../sentry-app-notify-disable.txt | 13 ++++++++++++ src/sentry/utils/sentry_apps/webhooks.py | 2 +- .../frontend/debug/debug_notify_disable.py | 20 ++++++------------- 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/sentry/integrations/notify_disable.py b/src/sentry/integrations/notify_disable.py index 830015b37360c1..304637678110c8 100644 --- a/src/sentry/integrations/notify_disable.py +++ b/src/sentry/integrations/notify_disable.py @@ -40,6 +40,7 @@ def notify_disable( integration_name: str, redis_key: str, integration_slug: Union[str, None] = None, + webhook_url: Union[str, None] = None, project: Union[str, None] = None, ): @@ -56,8 +57,7 @@ def notify_disable( context={ "integration_name": integration_name.title(), "integration_link": integration_link, - "webhook_url": redis_key, - "dashboard_link": "hold", + "webhook_url": webhook_url if "sentry-app" in redis_key and webhook_url else "", }, html_template="sentry/integrations/sentry-app-notify-disable.html" if "sentry-app" in redis_key and integration_slug diff --git a/src/sentry/templates/sentry/integrations/sentry-app-notify-disable.html b/src/sentry/templates/sentry/integrations/sentry-app-notify-disable.html index aa2b89f9b3cab2..40d02db55129d4 100644 --- a/src/sentry/templates/sentry/integrations/sentry-app-notify-disable.html +++ b/src/sentry/templates/sentry/integrations/sentry-app-notify-disable.html @@ -6,9 +6,9 @@

Hi there,

- We’ve received multiple request errors {{ dashboard_link }} from your webhook: {{ webhook_url }} for the custom {{ integration_name }} integration, and have unsubscribed the webhook from receiving events. + We’ve received multiple request errors from your webhook: {{webhook_url}} for the custom {{ integration_name }} integration, and have unsubscribed the webhook from receiving events.

- To continue using your custom integration, please fix your webhook: {{ webhook_url }} and re-enable the webhook subscriptions here. + To continue using your custom integration, please fix your webhook: {{webhook_url}} and re-enable the webhook subscriptions here.

diff --git a/src/sentry/templates/sentry/integrations/sentry-app-notify-disable.txt b/src/sentry/templates/sentry/integrations/sentry-app-notify-disable.txt index e69de29bb2d1d6..4f48b0068d4b15 100644 --- a/src/sentry/templates/sentry/integrations/sentry-app-notify-disable.txt +++ b/src/sentry/templates/sentry/integrations/sentry-app-notify-disable.txt @@ -0,0 +1,13 @@ +Hi there, + + We’ve received multiple request errors from your webhook: {{webhook_url}} for the custom {{ integration_name }} integration, + and have unsubscribed the webhook from receiving events. + + To continue using your custom integration, please fix your webhook: {{webhook_url}} and re-enable the webhook subscriptions here. + +If you need additional assistance, you can reach out to our support team at help.sentry.io. + +Happy fixing, +Sentry + +You are receiving this email because you’re listed as an organization Owner or Manager. diff --git a/src/sentry/utils/sentry_apps/webhooks.py b/src/sentry/utils/sentry_apps/webhooks.py index 3081875f48c16e..604020593873e3 100644 --- a/src/sentry/utils/sentry_apps/webhooks.py +++ b/src/sentry/utils/sentry_apps/webhooks.py @@ -47,7 +47,7 @@ def check_broken(sentryapp: SentryApp, org_id: str): org = Organization.objects.get(id=org_id) if features.has("organizations:disable-sentryapps-on-broken", org): sentryapp._disable() - notify_disable(org, sentryapp.slug, redis_key) + notify_disable(org, sentryapp.name, redis_key, sentryapp.slug, sentryapp.webhook_url) buffer.clear() extra = { diff --git a/src/sentry/web/frontend/debug/debug_notify_disable.py b/src/sentry/web/frontend/debug/debug_notify_disable.py index 5b8e536d14c0bd..2e243a53780100 100644 --- a/src/sentry/web/frontend/debug/debug_notify_disable.py +++ b/src/sentry/web/frontend/debug/debug_notify_disable.py @@ -1,33 +1,21 @@ from django.http import HttpRequest, HttpResponse from django.views.generic import View -from sentry import integrations from sentry.constants import SentryAppStatus from sentry.integrations.notify_disable import get_provider_type, get_url -from sentry.models import Integration, Organization, SentryApp +from sentry.models import Organization, SentryApp from .mail import MailPreview class DebugNotifyDisableView(View): def get(self, request: HttpRequest) -> HttpResponse: - - self.integration = Integration.objects.create( - provider="slack", - name="Awesome Team", - external_id="TXXXXXXXZ", - metadata={ - "access_token": "xoxb-xxxxxxxxx-xxxxxxxxxx-xxxxxxxxxxxx", - "installation_type": "born_as_bot", - }, - ) - provider = integrations.get(self.integration.provider) - self.organization = Organization(id=1, slug="organization", name="My Company") self.sentry_app = SentryApp( name="Test App", events=["issue.resolved", "issue.ignored", "issue.assigned"], status=SentryAppStatus.INTERNAL, + webhook_url="https://broken-example.com/webhook", ) integration_name = self.sentry_app.name @@ -36,6 +24,7 @@ def get(self, request: HttpRequest) -> HttpResponse: get_provider_type(f"sentry-app-error:{self.sentry_app.uuid}"), self.sentry_app.slug, ) + redis_key = f"sentry-app-error:{self.sentry_app.uuid}" return MailPreview( html_template="sentry/integrations/sentry-app-notify-disable.html", @@ -43,5 +32,8 @@ def get(self, request: HttpRequest) -> HttpResponse: context={ "integration_name": integration_name, "integration_link": integration_link, + "webhook_url": self.sentry_app.webhook_url + if "sentry-app" in redis_key and self.sentry_app.webhook_url + else "", }, ).render(request)