1
- from __future__ import annotations
2
-
3
1
from collections import defaultdict
4
- from typing import Any , DefaultDict , List , Mapping
5
2
6
3
from rest_framework import status
7
4
from rest_framework .request import Request
12
9
from sentry .api .base import region_silo_endpoint
13
10
from sentry .api .bases .organization import OrganizationEndpoint
14
11
from sentry .api .exceptions import ResourceDoesNotExist
12
+ from sentry .constants import SentryAppStatus
15
13
from sentry .incidents .logic import (
16
14
get_available_action_integrations_for_org ,
17
15
get_opsgenie_teams ,
18
16
get_pagerduty_services ,
19
17
)
20
18
from sentry .incidents .models import AlertRuleTriggerAction
21
19
from sentry .incidents .serializers import ACTION_TARGET_TYPE_TO_STRING
22
- from sentry .models .organization import Organization
23
- from sentry .services .hybrid_cloud .app import RpcSentryAppInstallation , app_service
24
- from sentry .services .hybrid_cloud .integration import RpcIntegration
20
+ from sentry .models .integrations .sentry_app_installation import SentryAppInstallation
25
21
26
22
27
23
def build_action_response (
28
- registered_type ,
29
- integration : RpcIntegration | None = None ,
30
- organization : Organization | None = None ,
31
- sentry_app_installation : RpcSentryAppInstallation | None = None ,
32
- ) -> Mapping [str , Any ]:
24
+ registered_type , integration = None , organization = None , sentry_app_installation = None
25
+ ):
33
26
"""
34
27
Build the "available action" objects for the API. Each one can have different fields.
35
28
@@ -64,14 +57,14 @@ def build_action_response(
64
57
65
58
elif sentry_app_installation :
66
59
action_response ["sentryAppName" ] = sentry_app_installation .sentry_app .name
67
- action_response ["sentryAppId" ] = sentry_app_installation .sentry_app . id
60
+ action_response ["sentryAppId" ] = sentry_app_installation .sentry_app_id
68
61
action_response ["sentryAppInstallationUuid" ] = sentry_app_installation .uuid
69
- action_response ["status" ] = sentry_app_installation .sentry_app .status
62
+ action_response ["status" ] = SentryAppStatus .as_str (
63
+ sentry_app_installation .sentry_app .status
64
+ )
70
65
71
66
# Sentry Apps can be alertable but not have an Alert Rule UI Component
72
- component = app_service .prepare_sentry_app_components (
73
- installation_id = sentry_app_installation .id , component_type = "alert-rule-action"
74
- )
67
+ component = sentry_app_installation .prepare_sentry_app_components ("alert-rule-action" )
75
68
if component :
76
69
action_response ["settings" ] = component .schema .get ("settings" , {})
77
70
@@ -94,7 +87,7 @@ def get(self, request: Request, organization) -> Response:
94
87
actions = []
95
88
96
89
# Cache Integration objects in this data structure to save DB calls.
97
- provider_integrations : DefaultDict [ str , List [ RpcIntegration ]] = defaultdict (list )
90
+ provider_integrations = defaultdict (list )
98
91
for integration in get_available_action_integrations_for_org (organization ):
99
92
provider_integrations [integration .provider ].append (integration )
100
93
@@ -110,13 +103,13 @@ def get(self, request: Request, organization) -> Response:
110
103
111
104
# Add all alertable SentryApps to the list.
112
105
elif registered_type .type == AlertRuleTriggerAction .Type .SENTRY_APP :
113
- installs = app_service .get_installed_for_organization (
114
- organization_id = organization .id
115
- )
116
106
actions += [
117
107
build_action_response (registered_type , sentry_app_installation = install )
118
- for install in installs
119
- if install .sentry_app .is_alertable
108
+ for install in SentryAppInstallation .objects .get_installed_for_organization (
109
+ organization .id
110
+ ).filter (
111
+ sentry_app__is_alertable = True ,
112
+ )
120
113
]
121
114
122
115
else :
0 commit comments