We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Change Slack Linked Team Message
Right now when we link a team to a Slack channel we get the message "<Team> will now receive issue alert notifications ...".
Change it to "<Team> will now receive issue alert and workflow notifications ..." (behind the feature flag)

<img width="746" alt="Screenshot 2023-10-25 at 8 55 42 AM" src="https://github.com/getsentry/sentry/assets/116035587/5f81ab16-b889-43aa-ab82-f74f00cc157f">
<img width="606" alt="Screenshot 2023-10-26 at 10 02 18 AM" src="https://github.com/getsentry/sentry/assets/116035587/c8819e04-062f-443a-b4f8-5c597240b7b4">


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/sentry/integrations/slack/views/link_team.py`
Content:
```
1 from __future__ import annotations
2 
3 from typing import Any, Sequence
4 
5 from django import forms
6 from django.core.signing import BadSignature, SignatureExpired
7 from django.http import Http404, HttpResponse
8 from django.utils.decorators import method_decorator
9 from rest_framework.request import Request
10 
11 from sentry import analytics
12 from sentry.models.integrations.external_actor import ExternalActor
13 from sentry.models.integrations.integration import Integration
14 from sentry.models.organizationmember import OrganizationMember
15 from sentry.models.team import Team
16 from sentry.notifications.types import NotificationSettingOptionValues, NotificationSettingTypes
17 from sentry.services.hybrid_cloud.actor import ActorType, RpcActor
18 from sentry.services.hybrid_cloud.identity import identity_service
19 from sentry.services.hybrid_cloud.integration import RpcIntegration, integration_service
20 from sentry.services.hybrid_cloud.notifications import notifications_service
21 from sentry.types.integrations import ExternalProviders
22 from sentry.utils.signing import unsign
23 from sentry.web.decorators import transaction_start
24 from sentry.web.frontend.base import BaseView, region_silo_view
25 from sentry.web.helpers import render_to_response
26 
27 from ..utils import is_valid_role, logger
28 from . import build_linking_url as base_build_linking_url
29 from . import never_cache, render_error_page
30 
31 ALLOWED_METHODS = ["GET", "POST"]
32 
33 ALREADY_LINKED_TITLE = "Already linked"
34 ALREADY_LINKED_MESSAGE = "The {slug} team has already been linked to a Slack channel."
35 SUCCESS_LINKED_TITLE = "Team linked"
36 SUCCESS_LINKED_MESSAGE = (
37     "The {slug} team will now receive issue alert notifications in the {channel_name} channel."
38 )
39 
40 
41 def build_team_linking_url(
42     integration: Integration | RpcIntegration,
43     slack_id: str,
44     channel_id: str,
45     channel_name: str,
46     response_url: str,
47 ) -> str:
48     return base_build_linking_url(
49         "sentry-integration-slack-link-team",
50         integration_id=integration.id,
51         slack_id=slack_id,
52         channel_id=channel_id,
53         channel_name=channel_name,
54         response_url=response_url,
55     )
56 
57 
58 class SelectTeamForm(forms.Form):
59     team = forms.ChoiceField(label="Team")
60 
61     def __init__(self, teams: Sequence[Team], *args: Any, **kwargs: Any):
62         super().__init__(*args, **kwargs)
63 
64         self.fields["team"].choices = [(team.id, team.slug) for team in teams]
65         self.fields["team"].widget.choices = self.fields["team"].choices
66 
67 
68 @region_silo_view
69 class SlackLinkTeamView(BaseView):
70     """
71     Django view for linking team to slack channel. Creates an entry on ExternalActor table.
72     """
73 
74     @transaction_start("SlackLinkTeamView")
75     @method_decorator(never_cache)
76     def handle(self, request: Request, signed_params: str) -> HttpResponse:
77         if request.method not in ALLOWED_METHODS:
78             return render_error_page(request, status=405, body_text="HTTP 405: Method not allowed")
79 
80         try:
81             params = unsign(signed_params)
82         except (SignatureExpired, BadSignature):
83             return render_to_response(
84                 "sentry/integrations/slack/expired-link.html",
85                 status=400,
86                 request=request,
87             )
88 
89         integration = integration_service.get_integration(integration_id=params["integration_id"])
90         if integration is None:
91             raise Http404
92 
93         organization_memberships = OrganizationMember.objects.get_for_integration(
94             integration, request.user
95         )
96         # Filter to teams where we have write access to, either through having a sufficient
97         # organization role (owner/manager/admin) or by being a team admin on at least one team.
98         teams_by_id = {}
99         for org_membership in organization_memberships:
100             for team in Team.objects.get_for_user(
101                 org_membership.organization,
102                 request.user,
103                 # Setting is_team_admin to True only returns teams that member is team admin on.
104                 # We only want to filter for this when the user does not have a sufficient
105                 # role in the org, which is checked using is_valid_role.
106                 is_team_admin=not is_valid_role(org_membership),
107             ):
108                 teams_by_id[team.id] = team
109 
110         if not teams_by_id:
111             return render_error_page(
112                 request,
113                 status=404,
114                 body_text="HTTP 404: No teams found in your organizations to link. You must be a Sentry organization admin/manager/owner or a team admin to link a team in your respective organization.",
115             )
116 
117         channel_name = params["channel_name"]
118         channel_id = params["channel_id"]
119         form = SelectTeamForm(list(teams_by_id.values()), request.POST or None)
120 
121         if request.method == "GET":
122             return self.respond(
123                 "sentry/integrations/slack/link-team.html",
124                 {
125                     "form": form,
126                     "teams": teams_by_id.values(),
127                     "channel_name": channel_name,
128                     "provider": integration.get_provider(),
129                 },
130             )
131 
132         if not form.is_valid():
133             return render_error_page(request, status=400, body_text="HTTP 400: Bad request")
134 
135         team_id = int(form.cleaned_data["team"])
136         team = teams_by_id.get(team_id)
137         if not team:
138             return render_error_page(
139                 request,
140                 status=404,
141                 body_text="HTTP 404: Team does not exist or you do not have sufficient permission to link a team",
142             )
143 
144         idp = identity_service.get_provider(
145             provider_type="slack", provider_ext_id=integration.external_id
146         )
147         if idp is None:
148             logger.info("slack.action.invalid-team-id", extra={"slack_id": integration.external_id})
149             return render_error_page(request, status=403, body_text="HTTP 403: Invalid team ID")
150 
151         ident = identity_service.get_identity(
152             filter={"provider_id": idp.id, "identity_ext_id": params["slack_id"]}
153         )
154         if not ident:
155             return render_error_page(
156                 request, status=403, body_text="HTTP 403: User identity does not exist"
157             )
158 
159         external_team, created = ExternalActor.objects.get_or_create(
160             team_id=team.id,
161             organization=team.organization,
162             integration_id=integration.id,
163             provider=ExternalProviders.SLACK.value,
164             defaults=dict(
165                 external_name=channel_name,
166                 external_id=channel_id,
167             ),
168         )
169 
170         analytics.record(
171             "integrations.identity_linked",
172             provider="slack",
173             actor_id=team.actor_id,
174             actor_type="team",
175         )
176 
177         if not created:
178             message = ALREADY_LINKED_MESSAGE.format(slug=team.slug)
179 
180             integration_service.send_message(
181                 integration_id=integration.id,
182                 organization_id=team.organization_id,
183                 channel=channel_id,
184                 message=message,
185             )
186             return render_to_response(
187                 "sentry/integrations/slack/post-linked-team.html",
188                 request=request,
189                 context={
190                     "heading_text": ALREADY_LINKED_TITLE,
191                     "body_text": message,
192                     "channel_id": channel_id,
193                     "team_id": integration.external_id,
194                 },
195             )
196 
197         # Turn on notifications for all of a team's projects.
198         notifications_service.update_settings(
199             external_provider=ExternalProviders.SLACK,
200             notification_type=NotificationSettingTypes.ISSUE_ALERTS,
201             setting_option=NotificationSettingOptionValues.ALWAYS,
202             actor=RpcActor(id=team.id, actor_type=ActorType.TEAM),
203             organization_id_for_team=team.organization_id,
204         )
205         message = SUCCESS_LINKED_MESSAGE.format(slug=team.slug, channel_name=channel_name)
206         integration_service.send_message(
207             integration_id=integration.id,
208             organization_id=team.organization_id,
209             channel=channel_id,
210             message=message,
211         )
212         return render_to_response(
213             "sentry/integrations/slack/post-linked-team.html",
214             request=request,
215             context={
216                 "heading_text": SUCCESS_LINKED_TITLE,
217                 "body_text": message,
218                 "channel_id": channel_id,
219                 "team_id": integration.external_id,
220             },
221         )
222
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/sentry/integrations/slack/views/link_team.py b/src/sentry/integrations/slack/views/link_team.py
--- a/src/sentry/integrations/slack/views/link_team.py
+++ b/src/sentry/integrations/slack/views/link_team.py
@@ -8,7 +8,7 @@
 from django.utils.decorators import method_decorator
 from rest_framework.request import Request
 
-from sentry import analytics
+from sentry import analytics, features
 from sentry.models.integrations.external_actor import ExternalActor
 from sentry.models.integrations.integration import Integration
 from sentry.models.organizationmember import OrganizationMember
@@ -33,9 +33,7 @@
 ALREADY_LINKED_TITLE = "Already linked"
 ALREADY_LINKED_MESSAGE = "The {slug} team has already been linked to a Slack channel."
 SUCCESS_LINKED_TITLE = "Team linked"
-SUCCESS_LINKED_MESSAGE = (
-    "The {slug} team will now receive issue alert notifications in the {channel_name} channel."
-)
+SUCCESS_LINKED_MESSAGE = "The {slug} team will now receive issue alert{workflow_addon} notifications in the {channel_name} channel."
 
 
 def build_team_linking_url(
@@ -202,7 +200,13 @@
             actor=RpcActor(id=team.id, actor_type=ActorType.TEAM),
             organization_id_for_team=team.organization_id,
         )
-        message = SUCCESS_LINKED_MESSAGE.format(slug=team.slug, channel_name=channel_name)
+        message = SUCCESS_LINKED_MESSAGE.format(
+            slug=team.slug,
+            workflow_addon=" and workflow"
+            if features.has("organizations:team-workflow-notifications", team.organization)
+            else "",
+            channel_name=channel_name,
+        )
         integration_service.send_message(
             integration_id=integration.id,
             organization_id=team.organization_id,

{"golden_diff": "diff --git a/src/sentry/integrations/slack/views/link_team.py b/src/sentry/integrations/slack/views/link_team.py\n--- a/src/sentry/integrations/slack/views/link_team.py\n+++ b/src/sentry/integrations/slack/views/link_team.py\n@@ -8,7 +8,7 @@\n from django.utils.decorators import method_decorator\n from rest_framework.request import Request\n \n-from sentry import analytics\n+from sentry import analytics, features\n from sentry.models.integrations.external_actor import ExternalActor\n from sentry.models.integrations.integration import Integration\n from sentry.models.organizationmember import OrganizationMember\n@@ -33,9 +33,7 @@\n ALREADY_LINKED_TITLE = \"Already linked\"\n ALREADY_LINKED_MESSAGE = \"The {slug} team has already been linked to a Slack channel.\"\n SUCCESS_LINKED_TITLE = \"Team linked\"\n-SUCCESS_LINKED_MESSAGE = (\n-    \"The {slug} team will now receive issue alert notifications in the {channel_name} channel.\"\n-)\n+SUCCESS_LINKED_MESSAGE = \"The {slug} team will now receive issue alert{workflow_addon} notifications in the {channel_name} channel.\"\n \n \n def build_team_linking_url(\n@@ -202,7 +200,13 @@\n             actor=RpcActor(id=team.id, actor_type=ActorType.TEAM),\n             organization_id_for_team=team.organization_id,\n         )\n-        message = SUCCESS_LINKED_MESSAGE.format(slug=team.slug, channel_name=channel_name)\n+        message = SUCCESS_LINKED_MESSAGE.format(\n+            slug=team.slug,\n+            workflow_addon=\" and workflow\"\n+            if features.has(\"organizations:team-workflow-notifications\", team.organization)\n+            else \"\",\n+            channel_name=channel_name,\n+        )\n         integration_service.send_message(\n             integration_id=integration.id,\n             organization_id=team.organization_id,\n", "issue": "Change Slack Linked Team Message\nRight now when we link a team to a Slack channel we get the message \"<Team> will now receive issue alert notifications ...\".\r\nChange it to \"<Team> will now receive issue alert and workflow notifications ...\" (behind the feature flag)\r\n\r\n<img width=\"746\" alt=\"Screenshot 2023-10-25 at 8 55 42 AM\" src=\"https://github.com/getsentry/sentry/assets/116035587/5f81ab16-b889-43aa-ab82-f74f00cc157f\">\r\n<img width=\"606\" alt=\"Screenshot 2023-10-26 at 10 02 18 AM\" src=\"https://github.com/getsentry/sentry/assets/116035587/c8819e04-062f-443a-b4f8-5c597240b7b4\">\r\n\n", "before_files": [{"content": "from __future__ import annotations\n\nfrom typing import Any, Sequence\n\nfrom django import forms\nfrom django.core.signing import BadSignature, SignatureExpired\nfrom django.http import Http404, HttpResponse\nfrom django.utils.decorators import method_decorator\nfrom rest_framework.request import Request\n\nfrom sentry import analytics\nfrom sentry.models.integrations.external_actor import ExternalActor\nfrom sentry.models.integrations.integration import Integration\nfrom sentry.models.organizationmember import OrganizationMember\nfrom sentry.models.team import Team\nfrom sentry.notifications.types import NotificationSettingOptionValues, NotificationSettingTypes\nfrom sentry.services.hybrid_cloud.actor import ActorType, RpcActor\nfrom sentry.services.hybrid_cloud.identity import identity_service\nfrom sentry.services.hybrid_cloud.integration import RpcIntegration, integration_service\nfrom sentry.services.hybrid_cloud.notifications import notifications_service\nfrom sentry.types.integrations import ExternalProviders\nfrom sentry.utils.signing import unsign\nfrom sentry.web.decorators import transaction_start\nfrom sentry.web.frontend.base import BaseView, region_silo_view\nfrom sentry.web.helpers import render_to_response\n\nfrom ..utils import is_valid_role, logger\nfrom . import build_linking_url as base_build_linking_url\nfrom . import never_cache, render_error_page\n\nALLOWED_METHODS = [\"GET\", \"POST\"]\n\nALREADY_LINKED_TITLE = \"Already linked\"\nALREADY_LINKED_MESSAGE = \"The {slug} team has already been linked to a Slack channel.\"\nSUCCESS_LINKED_TITLE = \"Team linked\"\nSUCCESS_LINKED_MESSAGE = (\n    \"The {slug} team will now receive issue alert notifications in the {channel_name} channel.\"\n)\n\n\ndef build_team_linking_url(\n    integration: Integration | RpcIntegration,\n    slack_id: str,\n    channel_id: str,\n    channel_name: str,\n    response_url: str,\n) -> str:\n    return base_build_linking_url(\n        \"sentry-integration-slack-link-team\",\n        integration_id=integration.id,\n        slack_id=slack_id,\n        channel_id=channel_id,\n        channel_name=channel_name,\n        response_url=response_url,\n    )\n\n\nclass SelectTeamForm(forms.Form):\n    team = forms.ChoiceField(label=\"Team\")\n\n    def __init__(self, teams: Sequence[Team], *args: Any, **kwargs: Any):\n        super().__init__(*args, **kwargs)\n\n        self.fields[\"team\"].choices = [(team.id, team.slug) for team in teams]\n        self.fields[\"team\"].widget.choices = self.fields[\"team\"].choices\n\n\n@region_silo_view\nclass SlackLinkTeamView(BaseView):\n    \"\"\"\n    Django view for linking team to slack channel. Creates an entry on ExternalActor table.\n    \"\"\"\n\n    @transaction_start(\"SlackLinkTeamView\")\n    @method_decorator(never_cache)\n    def handle(self, request: Request, signed_params: str) -> HttpResponse:\n        if request.method not in ALLOWED_METHODS:\n            return render_error_page(request, status=405, body_text=\"HTTP 405: Method not allowed\")\n\n        try:\n            params = unsign(signed_params)\n        except (SignatureExpired, BadSignature):\n            return render_to_response(\n                \"sentry/integrations/slack/expired-link.html\",\n                status=400,\n                request=request,\n            )\n\n        integration = integration_service.get_integration(integration_id=params[\"integration_id\"])\n        if integration is None:\n            raise Http404\n\n        organization_memberships = OrganizationMember.objects.get_for_integration(\n            integration, request.user\n        )\n        # Filter to teams where we have write access to, either through having a sufficient\n        # organization role (owner/manager/admin) or by being a team admin on at least one team.\n        teams_by_id = {}\n        for org_membership in organization_memberships:\n            for team in Team.objects.get_for_user(\n                org_membership.organization,\n                request.user,\n                # Setting is_team_admin to True only returns teams that member is team admin on.\n                # We only want to filter for this when the user does not have a sufficient\n                # role in the org, which is checked using is_valid_role.\n                is_team_admin=not is_valid_role(org_membership),\n            ):\n                teams_by_id[team.id] = team\n\n        if not teams_by_id:\n            return render_error_page(\n                request,\n                status=404,\n                body_text=\"HTTP 404: No teams found in your organizations to link. You must be a Sentry organization admin/manager/owner or a team admin to link a team in your respective organization.\",\n            )\n\n        channel_name = params[\"channel_name\"]\n        channel_id = params[\"channel_id\"]\n        form = SelectTeamForm(list(teams_by_id.values()), request.POST or None)\n\n        if request.method == \"GET\":\n            return self.respond(\n                \"sentry/integrations/slack/link-team.html\",\n                {\n                    \"form\": form,\n                    \"teams\": teams_by_id.values(),\n                    \"channel_name\": channel_name,\n                    \"provider\": integration.get_provider(),\n                },\n            )\n\n        if not form.is_valid():\n            return render_error_page(request, status=400, body_text=\"HTTP 400: Bad request\")\n\n        team_id = int(form.cleaned_data[\"team\"])\n        team = teams_by_id.get(team_id)\n        if not team:\n            return render_error_page(\n                request,\n                status=404,\n                body_text=\"HTTP 404: Team does not exist or you do not have sufficient permission to link a team\",\n            )\n\n        idp = identity_service.get_provider(\n            provider_type=\"slack\", provider_ext_id=integration.external_id\n        )\n        if idp is None:\n            logger.info(\"slack.action.invalid-team-id\", extra={\"slack_id\": integration.external_id})\n            return render_error_page(request, status=403, body_text=\"HTTP 403: Invalid team ID\")\n\n        ident = identity_service.get_identity(\n            filter={\"provider_id\": idp.id, \"identity_ext_id\": params[\"slack_id\"]}\n        )\n        if not ident:\n            return render_error_page(\n                request, status=403, body_text=\"HTTP 403: User identity does not exist\"\n            )\n\n        external_team, created = ExternalActor.objects.get_or_create(\n            team_id=team.id,\n            organization=team.organization,\n            integration_id=integration.id,\n            provider=ExternalProviders.SLACK.value,\n            defaults=dict(\n                external_name=channel_name,\n                external_id=channel_id,\n            ),\n        )\n\n        analytics.record(\n            \"integrations.identity_linked\",\n            provider=\"slack\",\n            actor_id=team.actor_id,\n            actor_type=\"team\",\n        )\n\n        if not created:\n            message = ALREADY_LINKED_MESSAGE.format(slug=team.slug)\n\n            integration_service.send_message(\n                integration_id=integration.id,\n                organization_id=team.organization_id,\n                channel=channel_id,\n                message=message,\n            )\n            return render_to_response(\n                \"sentry/integrations/slack/post-linked-team.html\",\n                request=request,\n                context={\n                    \"heading_text\": ALREADY_LINKED_TITLE,\n                    \"body_text\": message,\n                    \"channel_id\": channel_id,\n                    \"team_id\": integration.external_id,\n                },\n            )\n\n        # Turn on notifications for all of a team's projects.\n        notifications_service.update_settings(\n            external_provider=ExternalProviders.SLACK,\n            notification_type=NotificationSettingTypes.ISSUE_ALERTS,\n            setting_option=NotificationSettingOptionValues.ALWAYS,\n            actor=RpcActor(id=team.id, actor_type=ActorType.TEAM),\n            organization_id_for_team=team.organization_id,\n        )\n        message = SUCCESS_LINKED_MESSAGE.format(slug=team.slug, channel_name=channel_name)\n        integration_service.send_message(\n            integration_id=integration.id,\n            organization_id=team.organization_id,\n            channel=channel_id,\n            message=message,\n        )\n        return render_to_response(\n            \"sentry/integrations/slack/post-linked-team.html\",\n            request=request,\n            context={\n                \"heading_text\": SUCCESS_LINKED_TITLE,\n                \"body_text\": message,\n                \"channel_id\": channel_id,\n                \"team_id\": integration.external_id,\n            },\n        )\n", "path": "src/sentry/integrations/slack/views/link_team.py"}], "after_files": [{"content": "from __future__ import annotations\n\nfrom typing import Any, Sequence\n\nfrom django import forms\nfrom django.core.signing import BadSignature, SignatureExpired\nfrom django.http import Http404, HttpResponse\nfrom django.utils.decorators import method_decorator\nfrom rest_framework.request import Request\n\nfrom sentry import analytics, features\nfrom sentry.models.integrations.external_actor import ExternalActor\nfrom sentry.models.integrations.integration import Integration\nfrom sentry.models.organizationmember import OrganizationMember\nfrom sentry.models.team import Team\nfrom sentry.notifications.types import NotificationSettingOptionValues, NotificationSettingTypes\nfrom sentry.services.hybrid_cloud.actor import ActorType, RpcActor\nfrom sentry.services.hybrid_cloud.identity import identity_service\nfrom sentry.services.hybrid_cloud.integration import RpcIntegration, integration_service\nfrom sentry.services.hybrid_cloud.notifications import notifications_service\nfrom sentry.types.integrations import ExternalProviders\nfrom sentry.utils.signing import unsign\nfrom sentry.web.decorators import transaction_start\nfrom sentry.web.frontend.base import BaseView, region_silo_view\nfrom sentry.web.helpers import render_to_response\n\nfrom ..utils import is_valid_role, logger\nfrom . import build_linking_url as base_build_linking_url\nfrom . import never_cache, render_error_page\n\nALLOWED_METHODS = [\"GET\", \"POST\"]\n\nALREADY_LINKED_TITLE = \"Already linked\"\nALREADY_LINKED_MESSAGE = \"The {slug} team has already been linked to a Slack channel.\"\nSUCCESS_LINKED_TITLE = \"Team linked\"\nSUCCESS_LINKED_MESSAGE = \"The {slug} team will now receive issue alert{workflow_addon} notifications in the {channel_name} channel.\"\n\n\ndef build_team_linking_url(\n    integration: Integration | RpcIntegration,\n    slack_id: str,\n    channel_id: str,\n    channel_name: str,\n    response_url: str,\n) -> str:\n    return base_build_linking_url(\n        \"sentry-integration-slack-link-team\",\n        integration_id=integration.id,\n        slack_id=slack_id,\n        channel_id=channel_id,\n        channel_name=channel_name,\n        response_url=response_url,\n    )\n\n\nclass SelectTeamForm(forms.Form):\n    team = forms.ChoiceField(label=\"Team\")\n\n    def __init__(self, teams: Sequence[Team], *args: Any, **kwargs: Any):\n        super().__init__(*args, **kwargs)\n\n        self.fields[\"team\"].choices = [(team.id, team.slug) for team in teams]\n        self.fields[\"team\"].widget.choices = self.fields[\"team\"].choices\n\n\n@region_silo_view\nclass SlackLinkTeamView(BaseView):\n    \"\"\"\n    Django view for linking team to slack channel. Creates an entry on ExternalActor table.\n    \"\"\"\n\n    @transaction_start(\"SlackLinkTeamView\")\n    @method_decorator(never_cache)\n    def handle(self, request: Request, signed_params: str) -> HttpResponse:\n        if request.method not in ALLOWED_METHODS:\n            return render_error_page(request, status=405, body_text=\"HTTP 405: Method not allowed\")\n\n        try:\n            params = unsign(signed_params)\n        except (SignatureExpired, BadSignature):\n            return render_to_response(\n                \"sentry/integrations/slack/expired-link.html\",\n                status=400,\n                request=request,\n            )\n\n        integration = integration_service.get_integration(integration_id=params[\"integration_id\"])\n        if integration is None:\n            raise Http404\n\n        organization_memberships = OrganizationMember.objects.get_for_integration(\n            integration, request.user\n        )\n        # Filter to teams where we have write access to, either through having a sufficient\n        # organization role (owner/manager/admin) or by being a team admin on at least one team.\n        teams_by_id = {}\n        for org_membership in organization_memberships:\n            for team in Team.objects.get_for_user(\n                org_membership.organization,\n                request.user,\n                # Setting is_team_admin to True only returns teams that member is team admin on.\n                # We only want to filter for this when the user does not have a sufficient\n                # role in the org, which is checked using is_valid_role.\n                is_team_admin=not is_valid_role(org_membership),\n            ):\n                teams_by_id[team.id] = team\n\n        if not teams_by_id:\n            return render_error_page(\n                request,\n                status=404,\n                body_text=\"HTTP 404: No teams found in your organizations to link. You must be a Sentry organization admin/manager/owner or a team admin to link a team in your respective organization.\",\n            )\n\n        channel_name = params[\"channel_name\"]\n        channel_id = params[\"channel_id\"]\n        form = SelectTeamForm(list(teams_by_id.values()), request.POST or None)\n\n        if request.method == \"GET\":\n            return self.respond(\n                \"sentry/integrations/slack/link-team.html\",\n                {\n                    \"form\": form,\n                    \"teams\": teams_by_id.values(),\n                    \"channel_name\": channel_name,\n                    \"provider\": integration.get_provider(),\n                },\n            )\n\n        if not form.is_valid():\n            return render_error_page(request, status=400, body_text=\"HTTP 400: Bad request\")\n\n        team_id = int(form.cleaned_data[\"team\"])\n        team = teams_by_id.get(team_id)\n        if not team:\n            return render_error_page(\n                request,\n                status=404,\n                body_text=\"HTTP 404: Team does not exist or you do not have sufficient permission to link a team\",\n            )\n\n        idp = identity_service.get_provider(\n            provider_type=\"slack\", provider_ext_id=integration.external_id\n        )\n        if idp is None:\n            logger.info(\"slack.action.invalid-team-id\", extra={\"slack_id\": integration.external_id})\n            return render_error_page(request, status=403, body_text=\"HTTP 403: Invalid team ID\")\n\n        ident = identity_service.get_identity(\n            filter={\"provider_id\": idp.id, \"identity_ext_id\": params[\"slack_id\"]}\n        )\n        if not ident:\n            return render_error_page(\n                request, status=403, body_text=\"HTTP 403: User identity does not exist\"\n            )\n\n        external_team, created = ExternalActor.objects.get_or_create(\n            team_id=team.id,\n            organization=team.organization,\n            integration_id=integration.id,\n            provider=ExternalProviders.SLACK.value,\n            defaults=dict(\n                external_name=channel_name,\n                external_id=channel_id,\n            ),\n        )\n\n        analytics.record(\n            \"integrations.identity_linked\",\n            provider=\"slack\",\n            actor_id=team.actor_id,\n            actor_type=\"team\",\n        )\n\n        if not created:\n            message = ALREADY_LINKED_MESSAGE.format(slug=team.slug)\n\n            integration_service.send_message(\n                integration_id=integration.id,\n                organization_id=team.organization_id,\n                channel=channel_id,\n                message=message,\n            )\n            return render_to_response(\n                \"sentry/integrations/slack/post-linked-team.html\",\n                request=request,\n                context={\n                    \"heading_text\": ALREADY_LINKED_TITLE,\n                    \"body_text\": message,\n                    \"channel_id\": channel_id,\n                    \"team_id\": integration.external_id,\n                },\n            )\n\n        # Turn on notifications for all of a team's projects.\n        notifications_service.update_settings(\n            external_provider=ExternalProviders.SLACK,\n            notification_type=NotificationSettingTypes.ISSUE_ALERTS,\n            setting_option=NotificationSettingOptionValues.ALWAYS,\n            actor=RpcActor(id=team.id, actor_type=ActorType.TEAM),\n            organization_id_for_team=team.organization_id,\n        )\n        message = SUCCESS_LINKED_MESSAGE.format(\n            slug=team.slug,\n            workflow_addon=\" and workflow\"\n            if features.has(\"organizations:team-workflow-notifications\", team.organization)\n            else \"\",\n            channel_name=channel_name,\n        )\n        integration_service.send_message(\n            integration_id=integration.id,\n            organization_id=team.organization_id,\n            channel=channel_id,\n            message=message,\n        )\n        return render_to_response(\n            \"sentry/integrations/slack/post-linked-team.html\",\n            request=request,\n            context={\n                \"heading_text\": SUCCESS_LINKED_TITLE,\n                \"body_text\": message,\n                \"channel_id\": channel_id,\n                \"team_id\": integration.external_id,\n            },\n        )\n", "path": "src/sentry/integrations/slack/views/link_team.py"}]}