|
@@ -1,7 +1,4 @@
|
|
|
-from __future__ import annotations
|
|
|
-
|
|
|
from collections import defaultdict
|
|
|
-from typing import Any, DefaultDict, List, Mapping
|
|
|
|
|
|
from rest_framework import status
|
|
|
from rest_framework.request import Request
|
|
@@ -12,6 +9,7 @@ from sentry.api.api_publish_status import ApiPublishStatus
|
|
|
from sentry.api.base import region_silo_endpoint
|
|
|
from sentry.api.bases.organization import OrganizationEndpoint
|
|
|
from sentry.api.exceptions import ResourceDoesNotExist
|
|
|
+from sentry.constants import SentryAppStatus
|
|
|
from sentry.incidents.logic import (
|
|
|
get_available_action_integrations_for_org,
|
|
|
get_opsgenie_teams,
|
|
@@ -19,17 +17,12 @@ from sentry.incidents.logic import (
|
|
|
)
|
|
|
from sentry.incidents.models import AlertRuleTriggerAction
|
|
|
from sentry.incidents.serializers import ACTION_TARGET_TYPE_TO_STRING
|
|
|
-from sentry.models.organization import Organization
|
|
|
-from sentry.services.hybrid_cloud.app import RpcSentryAppInstallation, app_service
|
|
|
-from sentry.services.hybrid_cloud.integration import RpcIntegration
|
|
|
+from sentry.models.integrations.sentry_app_installation import SentryAppInstallation
|
|
|
|
|
|
|
|
|
def build_action_response(
|
|
|
- registered_type,
|
|
|
- integration: RpcIntegration | None = None,
|
|
|
- organization: Organization | None = None,
|
|
|
- sentry_app_installation: RpcSentryAppInstallation | None = None,
|
|
|
-) -> Mapping[str, Any]:
|
|
|
+ registered_type, integration=None, organization=None, sentry_app_installation=None
|
|
|
+):
|
|
|
"""
|
|
|
Build the "available action" objects for the API. Each one can have different fields.
|
|
|
|
|
@@ -64,14 +57,14 @@ def build_action_response(
|
|
|
|
|
|
elif sentry_app_installation:
|
|
|
action_response["sentryAppName"] = sentry_app_installation.sentry_app.name
|
|
|
- action_response["sentryAppId"] = sentry_app_installation.sentry_app.id
|
|
|
+ action_response["sentryAppId"] = sentry_app_installation.sentry_app_id
|
|
|
action_response["sentryAppInstallationUuid"] = sentry_app_installation.uuid
|
|
|
- action_response["status"] = sentry_app_installation.sentry_app.status
|
|
|
+ action_response["status"] = SentryAppStatus.as_str(
|
|
|
+ sentry_app_installation.sentry_app.status
|
|
|
+ )
|
|
|
|
|
|
# Sentry Apps can be alertable but not have an Alert Rule UI Component
|
|
|
- component = app_service.prepare_sentry_app_components(
|
|
|
- installation_id=sentry_app_installation.id, component_type="alert-rule-action"
|
|
|
- )
|
|
|
+ component = sentry_app_installation.prepare_sentry_app_components("alert-rule-action")
|
|
|
if component:
|
|
|
action_response["settings"] = component.schema.get("settings", {})
|
|
|
|
|
@@ -94,7 +87,7 @@ class OrganizationAlertRuleAvailableActionIndexEndpoint(OrganizationEndpoint):
|
|
|
actions = []
|
|
|
|
|
|
# Cache Integration objects in this data structure to save DB calls.
|
|
|
- provider_integrations: DefaultDict[str, List[RpcIntegration]] = defaultdict(list)
|
|
|
+ provider_integrations = defaultdict(list)
|
|
|
for integration in get_available_action_integrations_for_org(organization):
|
|
|
provider_integrations[integration.provider].append(integration)
|
|
|
|
|
@@ -110,13 +103,13 @@ class OrganizationAlertRuleAvailableActionIndexEndpoint(OrganizationEndpoint):
|
|
|
|
|
|
# Add all alertable SentryApps to the list.
|
|
|
elif registered_type.type == AlertRuleTriggerAction.Type.SENTRY_APP:
|
|
|
- installs = app_service.get_installed_for_organization(
|
|
|
- organization_id=organization.id
|
|
|
- )
|
|
|
actions += [
|
|
|
build_action_response(registered_type, sentry_app_installation=install)
|
|
|
- for install in installs
|
|
|
- if install.sentry_app.is_alertable
|
|
|
+ for install in SentryAppInstallation.objects.get_installed_for_organization(
|
|
|
+ organization.id
|
|
|
+ ).filter(
|
|
|
+ sentry_app__is_alertable=True,
|
|
|
+ )
|
|
|
]
|
|
|
|
|
|
else:
|