Skip to content

Commit

Permalink
feat(api): Create query param to show disabled ticket integrations (#…
Browse files Browse the repository at this point in the history
…58058)

We want to show disabled integrations on the alert rule action dropdown.
Each disabled integration would have a button on the right linking to
respective integration setup page.

This change allows us to pass a query parameter that will then include
all disabled ticket actions in the response.

### Mockup
<img width="1156" alt="Untitled"
src="https://github.com/getsentry/sentry/assets/67301797/78890684-409c-4305-91a5-a34603360717">
  • Loading branch information
schew2381 authored Oct 16, 2023
1 parent bd40d02 commit c23f143
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/sentry/api/endpoints/project_rules_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ def get(self, request: Request, project) -> Response:
"""
Retrieve the list of configuration options for a given project.
"""

action_list = []
condition_list = []
filter_list = []

available_ticket_actions = set()

project_has_filters = features.has("projects:alert-filters", project)
can_create_tickets = features.has(
"organizations:integrations-ticket-rules", project.organization
Expand Down Expand Up @@ -57,6 +58,7 @@ def get(self, request: Request, project) -> Response:
context["actionType"] = "ticket"
context["ticketType"] = node.ticket_type
context["link"] = node.link
available_ticket_actions.add(node.id)

# It is possible for a project to have no services. In that scenario we do
# not want the front end to render the action as the action does not have
Expand All @@ -81,4 +83,9 @@ def get(self, request: Request, project) -> Response:

context = {"actions": action_list, "conditions": condition_list, "filters": filter_list}

if can_create_tickets and request.GET.get("includeAllTickets") is not None:
# Add disabled ticket integrations to response
disabled_actions = TICKET_ACTIONS - available_ticket_actions
context["disabledTicketActions"] = sorted(list(disabled_actions))

return Response(context)
21 changes: 19 additions & 2 deletions tests/sentry/api/endpoints/test_project_rules_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
EMAIL_ACTION = "sentry.mail.actions.NotifyEmailAction"
APP_ACTION = "sentry.rules.actions.notify_event_service.NotifyEventServiceAction"
JIRA_ACTION = "sentry.integrations.jira.notify_action.JiraCreateTicketAction"
AZURE_DEV_OPS_ACTION = "sentry.integrations.vsts.notify_action.AzureDevopsCreateTicketAction"
SENTRY_APP_ALERT_ACTION = "sentry.rules.actions.notify_event_sentry_app.NotifyEventSentryAppAction"


Expand All @@ -18,6 +19,7 @@ class ProjectRuleConfigurationTest(APITestCase):
def setUp(self):
super().setUp()
self.login_as(user=self.user)
self.ticket_actions = [JIRA_ACTION, AZURE_DEV_OPS_ACTION]

def test_simple(self):
team = self.create_team()
Expand Down Expand Up @@ -97,10 +99,25 @@ def test_available_actions(self):

def test_ticket_rules_not_in_available_actions(self):
with self.feature({"organizations:integrations-ticket-rules": False}):
response = self.get_success_response(self.organization.slug, self.project.slug)
response = self.get_success_response(
self.organization.slug, self.project.slug, includeAllTickets=True
)

action_ids = [action["id"] for action in response.data["actions"]]
assert EMAIL_ACTION in action_ids
assert JIRA_ACTION not in action_ids
for action in self.ticket_actions:
assert action not in action_ids
assert "disabledTicketActions" not in response.data

@patch("sentry.api.endpoints.project_rules_configuration.rules", new=[])
def test_show_disabled_ticket_actions(self):
response = self.get_success_response(
self.organization.slug, self.project.slug, includeAllTickets=True
)
disabled_ticket_actions = response.data["disabledTicketActions"]
assert len(disabled_ticket_actions) == 2
for ticket in self.ticket_actions:
assert ticket in disabled_ticket_actions

def test_sentry_app_alertable_webhook(self):
team = self.create_team()
Expand Down

0 comments on commit c23f143

Please sign in to comment.