Skip to content

Commit

Permalink
ref(slack): Indicate recipient in referrer (#29235)
Browse files Browse the repository at this point in the history
* ref(slack): Indicate recipient in referrer
  • Loading branch information
ceorourke authored Oct 11, 2021
1 parent a8f7dd3 commit 5aedd9f
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 29 deletions.
18 changes: 12 additions & 6 deletions src/sentry/integrations/slack/utils/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,19 @@ def send_confirmation(
)


def get_referrer_qstring(notification: BaseNotification) -> str:
return "?referrer=" + re.sub("Notification$", "Slack", notification.__class__.__name__)
def get_referrer_qstring(notification: BaseNotification, recipient: Union["Team", "User"]) -> str:
return (
"?referrer="
+ re.sub("Notification$", "Slack", notification.__class__.__name__)
+ str(recipient.__class__.__name__)
)


def get_settings_url(notification: BaseNotification) -> str:
def get_settings_url(notification: BaseNotification, recipient: Union["Team", "User"]) -> str:
url_str = "/settings/account/notifications/"
if notification.fine_tuning_key:
url_str += f"{notification.fine_tuning_key}/"
return str(urljoin(absolute_uri(url_str), get_referrer_qstring(notification)))
return str(urljoin(absolute_uri(url_str), get_referrer_qstring(notification, recipient)))


def build_notification_footer(
Expand All @@ -105,9 +109,11 @@ def build_notification_footer(
if isinstance(recipient, Team):
team = Team.objects.get(id=recipient.id)
url_str = f"/settings/{notification.organization.slug}/teams/{team.slug}/notifications/"
settings_url = str(urljoin(absolute_uri(url_str), get_referrer_qstring(notification)))
settings_url = str(
urljoin(absolute_uri(url_str), get_referrer_qstring(notification, recipient))
)
else:
settings_url = get_settings_url(notification)
settings_url = get_settings_url(notification, recipient)

if isinstance(notification, ReleaseActivityNotification):
# no environment related to a deploy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,5 @@ def test_assignment(self, mock_func):
assert attachment["title"] == self.group.title
assert (
attachment["footer"]
== f"{self.project.slug} | <http://testserver/settings/account/notifications/workflow/?referrer=AssignedActivitySlack|Notification Settings>"
== f"{self.project.slug} | <http://testserver/settings/account/notifications/workflow/?referrer=AssignedActivitySlackUser|Notification Settings>"
)
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ def test_deploy(self, mock_func):
)
assert (
attachment["footer"]
== f"{self.project.slug} | <http://testserver/settings/account/notifications/deploy/?referrer=ReleaseActivitySlack|Notification Settings>"
== f"{self.project.slug} | <http://testserver/settings/account/notifications/deploy/?referrer=ReleaseActivitySlackUser|Notification Settings>"
)
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_issue_alert_user(self, mock_func):
assert attachment["title"] == "Hello world"
assert (
attachment["footer"]
== f"{self.project.slug} | <http://testserver/settings/account/notifications/alerts/?referrer=AlertRuleSlack|Notification Settings>"
== f"{self.project.slug} | <http://testserver/settings/account/notifications/alerts/?referrer=AlertRuleSlackUser|Notification Settings>"
)

@responses.activate
Expand Down Expand Up @@ -105,7 +105,7 @@ def test_issue_alert_issue_owners(self, mock_func):
assert attachment["title"] == "Hello world"
assert (
attachment["footer"]
== f"{self.project.slug} | <http://testserver/settings/account/notifications/alerts/?referrer=AlertRuleSlack|Notification Settings>"
== f"{self.project.slug} | <http://testserver/settings/account/notifications/alerts/?referrer=AlertRuleSlackUser|Notification Settings>"
)

@responses.activate
Expand Down Expand Up @@ -195,7 +195,7 @@ def test_issue_alert_team_issue_owners(self, mock_func):
assert attachments[0]["title"] == "Hello world"
assert (
attachments[0]["footer"]
== f"{self.project.slug} | <http://testserver/settings/{self.organization.slug}/teams/{self.team.slug}/notifications/?referrer=AlertRuleSlack|Notification Settings>"
== f"{self.project.slug} | <http://testserver/settings/{self.organization.slug}/teams/{self.team.slug}/notifications/?referrer=AlertRuleSlackTeam|Notification Settings>"
)

@responses.activate
Expand Down Expand Up @@ -271,7 +271,7 @@ def test_issue_alert_team(self, mock_func):
assert attachments[0]["title"] == "Hello world"
assert (
attachments[0]["footer"]
== f"{self.project.slug} | <http://example.com/settings/{self.organization.slug}/teams/{self.team.slug}/notifications/?referrer=AlertRuleSlack|Notification Settings>"
== f"{self.project.slug} | <http://example.com/settings/{self.organization.slug}/teams/{self.team.slug}/notifications/?referrer=AlertRuleSlackTeam|Notification Settings>"
)

@responses.activate
Expand Down Expand Up @@ -351,7 +351,7 @@ def test_issue_alert_team_new_project(self, mock_func):
assert attachments[0]["title"] == "Hello world"
assert (
attachments[0]["footer"]
== f"{project2.slug} | <http://example.com/settings/{self.organization.slug}/teams/{self.team.slug}/notifications/?referrer=AlertRuleSlack|Notification Settings>"
== f"{project2.slug} | <http://example.com/settings/{self.organization.slug}/teams/{self.team.slug}/notifications/?referrer=AlertRuleSlackTeam|Notification Settings>"
)

@responses.activate
Expand Down Expand Up @@ -453,7 +453,7 @@ def test_issue_alert_team_fallback(self, mock_func):
assert attachments[0]["title"] == "Hello world"
assert (
attachments[0]["footer"]
== f"{self.project.slug} | <http://example.com/settings/account/notifications/alerts/?referrer=AlertRuleSlack|Notification Settings>"
== f"{self.project.slug} | <http://example.com/settings/account/notifications/alerts/?referrer=AlertRuleSlackUser|Notification Settings>"
)

# check that user2 got a notification as well
Expand All @@ -465,7 +465,7 @@ def test_issue_alert_team_fallback(self, mock_func):
assert attachments[0]["title"] == "Hello world"
assert (
attachments[0]["footer"]
== f"{self.project.slug} | <http://example.com/settings/account/notifications/alerts/?referrer=AlertRuleSlack|Notification Settings>"
== f"{self.project.slug} | <http://example.com/settings/account/notifications/alerts/?referrer=AlertRuleSlackUser|Notification Settings>"
)

@responses.activate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ def test_new_processing_issue(self, mock_func):
)
assert (
attachment["footer"]
== f"{self.project.slug} | <http://testserver/settings/account/notifications/workflow/?referrer=NewProcessingIssuesActivitySlack|Notification Settings>"
== f"{self.project.slug} | <http://testserver/settings/account/notifications/workflow/?referrer=NewProcessingIssuesActivitySlackUser|Notification Settings>"
)
2 changes: 1 addition & 1 deletion tests/sentry/integrations/slack/notifications/test_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ def test_note(self, mock_func):
assert attachment["text"] == notification.activity.data["text"]
assert (
attachment["footer"]
== f"{self.project.slug} | <http://testserver/settings/account/notifications/workflow/?referrer=NoteActivitySlack|Notification Settings>"
== f"{self.project.slug} | <http://testserver/settings/account/notifications/workflow/?referrer=NoteActivitySlackUser|Notification Settings>"
)
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ def test_regression(self, mock_func):
assert text == "Issue marked as regression"
assert (
attachment["footer"]
== f"{self.project.slug} | <http://testserver/settings/account/notifications/workflow/?referrer=RegressionActivitySlack|Notification Settings>"
== f"{self.project.slug} | <http://testserver/settings/account/notifications/workflow/?referrer=RegressionActivitySlackUser|Notification Settings>"
)
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ def test_resolved(self, mock_func):
)
assert (
attachment["footer"]
== f"{self.project.slug} | <http://testserver/settings/account/notifications/workflow/?referrer=ResolvedActivitySlack|Notification Settings>"
== f"{self.project.slug} | <http://testserver/settings/account/notifications/workflow/?referrer=ResolvedActivitySlackUser|Notification Settings>"
)
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ def test_resolved_in_release(self, mock_func):
assert text == f"Issue marked as resolved in {release_name} by {self.name}"
assert (
attachment["footer"]
== f"{self.project.slug} | <http://testserver/settings/account/notifications/workflow/?referrer=ResolvedInReleaseActivitySlack|Notification Settings>"
== f"{self.project.slug} | <http://testserver/settings/account/notifications/workflow/?referrer=ResolvedInReleaseActivitySlackUser|Notification Settings>"
)
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ def test_unassignment(self, mock_func):
assert attachment["title"] == self.group.title
assert (
attachment["footer"]
== f"{self.project.slug} | <http://testserver/settings/account/notifications/workflow/?referrer=UnassignedActivitySlack|Notification Settings>"
== f"{self.project.slug} | <http://testserver/settings/account/notifications/workflow/?referrer=UnassignedActivitySlackUser|Notification Settings>"
)
16 changes: 8 additions & 8 deletions tests/sentry/notifications/test_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def test_sends_note_notification(self):
assert attachment["text"] == "blah blah"
assert (
attachment["footer"]
== f"{self.project.slug} | <http://testserver/settings/account/notifications/workflow/?referrer=NoteActivitySlack|Notification Settings>"
== f"{self.project.slug} | <http://testserver/settings/account/notifications/workflow/?referrer=NoteActivitySlackUser|Notification Settings>"
)

@responses.activate
Expand All @@ -151,7 +151,7 @@ def test_sends_assignment_notification(self):
assert attachment["title"] == self.group.title
assert (
attachment["footer"]
== f"{self.project.slug} | <http://testserver/settings/account/notifications/workflow/?referrer=AssignedActivitySlack|Notification Settings>"
== f"{self.project.slug} | <http://testserver/settings/account/notifications/workflow/?referrer=AssignedActivitySlackUser|Notification Settings>"
)

@responses.activate
Expand Down Expand Up @@ -180,7 +180,7 @@ def test_sends_unassignment_notification(self):
assert attachment["title"] == self.group.title
assert (
attachment["footer"]
== f"{self.project.slug} | <http://testserver/settings/account/notifications/workflow/?referrer=UnassignedActivitySlack|Notification Settings>"
== f"{self.project.slug} | <http://testserver/settings/account/notifications/workflow/?referrer=UnassignedActivitySlackUser|Notification Settings>"
)

@responses.activate
Expand Down Expand Up @@ -209,7 +209,7 @@ def test_sends_resolution_notification(self):
assert attachment["title"] == self.group.title
assert (
attachment["footer"]
== f"{self.project.slug} | <http://testserver/settings/account/notifications/workflow/?referrer=ResolvedActivitySlack|Notification Settings>"
== f"{self.project.slug} | <http://testserver/settings/account/notifications/workflow/?referrer=ResolvedActivitySlackUser|Notification Settings>"
)

@responses.activate
Expand Down Expand Up @@ -249,7 +249,7 @@ def test_sends_deployment_notification(self):
)
assert (
attachment["footer"]
== f"{self.project.slug} | <http://testserver/settings/account/notifications/deploy/?referrer=ReleaseActivitySlack|Notification Settings>"
== f"{self.project.slug} | <http://testserver/settings/account/notifications/deploy/?referrer=ReleaseActivitySlackUser|Notification Settings>"
)

@responses.activate
Expand Down Expand Up @@ -288,7 +288,7 @@ def test_sends_regression_notification(self):
assert text == "Issue marked as regression"
assert (
attachment["footer"]
== f"{self.project.slug} | <http://testserver/settings/account/notifications/workflow/?referrer=RegressionActivitySlack|Notification Settings>"
== f"{self.project.slug} | <http://testserver/settings/account/notifications/workflow/?referrer=RegressionActivitySlackUser|Notification Settings>"
)

@responses.activate
Expand Down Expand Up @@ -323,7 +323,7 @@ def test_sends_resolved_in_release_notification(self):
assert attachment["title"] == self.group.title
assert (
attachment["footer"]
== f"{self.project.slug} | <http://testserver/settings/account/notifications/workflow/?referrer=ResolvedInReleaseActivitySlack|Notification Settings>"
== f"{self.project.slug} | <http://testserver/settings/account/notifications/workflow/?referrer=ResolvedInReleaseActivitySlackUser|Notification Settings>"
)

@responses.activate
Expand Down Expand Up @@ -383,5 +383,5 @@ def test_sends_issue_notification(self):
assert attachment["title"] == "Hello world"
assert (
attachment["footer"]
== f"{self.project.slug} | <http://testserver/settings/account/notifications/alerts/?referrer=AlertRuleSlack|Notification Settings>"
== f"{self.project.slug} | <http://testserver/settings/account/notifications/alerts/?referrer=AlertRuleSlackUser|Notification Settings>"
)

0 comments on commit 5aedd9f

Please sign in to comment.