|
@@ -1,21 +1,26 @@
|
|
|
import logging
|
|
|
|
|
|
+import sentry_sdk
|
|
|
+from django.db import transaction
|
|
|
+from requests import RequestException
|
|
|
from rest_framework.request import Request
|
|
|
from rest_framework.response import Response
|
|
|
|
|
|
-from sentry import analytics, features
|
|
|
-from sentry.api.base import pending_silo_endpoint
|
|
|
+from sentry import analytics, audit_log, deletions, features
|
|
|
+from sentry.api.base import control_silo_endpoint
|
|
|
from sentry.api.bases.sentryapps import SentryAppBaseEndpoint, catch_raised_errors
|
|
|
from sentry.api.serializers import serialize
|
|
|
from sentry.api.serializers.rest_framework import SentryAppSerializer
|
|
|
from sentry.constants import SentryAppStatus
|
|
|
-from sentry.mediators.sentry_apps import Destroyer, Updater
|
|
|
+from sentry.mediators import InstallationNotifier
|
|
|
+from sentry.mediators.sentry_apps import Updater
|
|
|
from sentry.utils import json
|
|
|
+from sentry.utils.audit import create_audit_entry
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
-@pending_silo_endpoint
|
|
|
+@control_silo_endpoint
|
|
|
class SentryAppDetailsEndpoint(SentryAppBaseEndpoint):
|
|
|
def get(self, request: Request, sentry_app) -> Response:
|
|
|
return Response(serialize(sentry_app, request.user, access=request.access))
|
|
@@ -82,7 +87,32 @@ class SentryAppDetailsEndpoint(SentryAppBaseEndpoint):
|
|
|
|
|
|
def delete(self, request: Request, sentry_app) -> Response:
|
|
|
if sentry_app.is_unpublished or sentry_app.is_internal:
|
|
|
- Destroyer.run(user=request.user, sentry_app=sentry_app, request=request)
|
|
|
+ if not sentry_app.is_internal:
|
|
|
+ for install in sentry_app.installations.all():
|
|
|
+ try:
|
|
|
+ with transaction.atomic():
|
|
|
+ InstallationNotifier.run(
|
|
|
+ install=install, user=request.user, action="deleted"
|
|
|
+ )
|
|
|
+ deletions.exec_sync(install)
|
|
|
+ except RequestException as exc:
|
|
|
+ sentry_sdk.capture_exception(exc)
|
|
|
+
|
|
|
+ with transaction.atomic():
|
|
|
+ deletions.exec_sync(sentry_app)
|
|
|
+ create_audit_entry(
|
|
|
+ request=request,
|
|
|
+ organization_id=sentry_app.owner_id,
|
|
|
+ target_object=sentry_app.owner_id,
|
|
|
+ event=audit_log.get_event_id("SENTRY_APP_REMOVE"),
|
|
|
+ data={"sentry_app": sentry_app.name},
|
|
|
+ )
|
|
|
+ analytics.record(
|
|
|
+ "sentry_app.deleted",
|
|
|
+ user_id=request.user.id,
|
|
|
+ organization_id=sentry_app.owner_id,
|
|
|
+ sentry_app=sentry_app.slug,
|
|
|
+ )
|
|
|
return Response(status=204)
|
|
|
|
|
|
return Response({"detail": ["Published apps cannot be removed."]}, status=403)
|