Skip to content

feat(sentryapps)-email-on-disable #54348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/sentry/integrations/notify_disable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
):

Expand All @@ -56,8 +57,13 @@ def notify_disable(
context={
"integration_name": integration_name.title(),
"integration_link": integration_link,
"webhook_url": webhook_url if "sentry-app" in redis_key and webhook_url else "",
},
html_template="sentry/integrations/notify-disable.html",
template="sentry/integrations/notify-disable.txt",
html_template="sentry/integrations/sentry-app-notify-disable.html"
if "sentry-app" in redis_key and integration_slug
else "sentry/integrations/notify-disable.html",
template="sentry/integrations/sentry-app-notify-disable.txt"
if "sentry-app" in redis_key and integration_slug
else "sentry/integrations/notify-disable.txt",
)
msg.send_async([user.email])
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% extends "sentry/emails/base.html" %}

{% load i18n %}

{% block main %}
<p>
Hi there,
</p><p>
We’ve received multiple <a href={{integration_link}}dashboard/>request errors</a> from your webhook: <a href={{webhook_url}}>{{webhook_url}}</a> for the custom {{ integration_name }} integration, and have unsubscribed the webhook from receiving events.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to add a referrer to the URL for analytics and as this is set up, it'll be http://dev.getsentry.net:8000/settings/sentry/developer-settings/internal-35e455/?referrer=notify_disable_emaildashboard/ (missing the /). We could add the slash to the referrer query string but that seems odd, probably better to pass the dashboard URL to context.

</p><p>
To continue using your custom integration, please fix your webhook: <a href={{webhook_url}}>{{webhook_url}}</a> and re-enable the webhook subscriptions <a href={{integration_link}}>here</a>.
</p><p>
</p>
<p>
</p>
<p>If you need additional assistance, you can reach out to our support team at <a href=https://help.sentry.io/>help.sentry.io</a>.</p>
<p>Happy fixing,</p><p>
Sentry
</p>
<p class="via">
You are receiving this email because you’re listed as an organization Owner or Manager.</a>
</p>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Hi there,

We’ve received multiple <a href={{integration_link}}dashboard/>request errors</a> from your webhook: <a href={{webhook_url}}>{{webhook_url}}</a> for the custom {{ integration_name }} integration,
and have unsubscribed the webhook from receiving events.

To continue using your custom integration, please fix your webhook: <a href={{webhook_url}}>{{webhook_url}}</a> and re-enable the webhook subscriptions <a href={{integration_link}}>here</a>.

If you need additional assistance, you can reach out to our support team at <a href=https://help.sentry.io/>help.sentry.io</a>.

Happy fixing,
Sentry

You are receiving this email because you’re listed as an organization Owner or Manager.
2 changes: 1 addition & 1 deletion src/sentry/utils/sentry_apps/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
35 changes: 17 additions & 18 deletions src/sentry/web/frontend/debug/debug_notify_disable.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
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
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",
},
)

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",
)

provider = integrations.get(self.integration.provider)
integration_name = provider.name
integration_name = self.sentry_app.name
integration_link = get_url(
self.organization,
get_provider_type(f"sentry-integration-error:{self.integration.external_id}"),
provider.name,
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/notify-disable.html",
text_template="sentry/integrations/notify-disable.txt",
html_template="sentry/integrations/sentry-app-notify-disable.html",
text_template="sentry/integrations/sentry-app-notify-disable.txt",
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)