def handle(self, request: Request, signed_params: str) -> Response: try: params = unsign(signed_params) except (SignatureExpired, BadSignature): return render_to_response( "sentry/integrations/slack/expired-link.html", request=request, ) organization, integration, idp = get_identity_or_404( ExternalProviders.SLACK, request.user, integration_id=params["integration_id"], organization_id=params["organization_id"], ) if request.method != "POST": return render_to_response( "sentry/auth-link-identity.html", request=request, context={ "organization": organization, "provider": integration.get_provider() }, ) # TODO(epurkhiser): We could do some fancy slack querying here to # render a nice linking page with info about the user their linking. # Link the user with the identity. Handle the case where the user is linked to a # different identity or the identity is linked to a different user. defaults = { "status": IdentityStatus.VALID, "date_verified": timezone.now() } try: identity, created = Identity.objects.get_or_create( idp=idp, user=request.user, external_id=params["slack_id"], defaults=defaults) if not created: identity.update(**defaults) except IntegrityError: Identity.objects.reattach(idp, params["slack_id"], request.user, defaults) send_slack_response(integration, SUCCESS_LINKED_MESSAGE, params, command="link") return render_to_response( "sentry/integrations/slack/linked.html", request=request, context={ "channel_id": params["channel_id"], "team_id": integration.external_id }, )
def handle(self, request: Request, signed_params: str) -> Response: try: params = unsign(signed_params) except (SignatureExpired, BadSignature): return render_to_response( "sentry/integrations/slack/expired-link.html", request=request, ) organization, integration, idp = get_identity_or_404( ExternalProviders.SLACK, request.user, integration_id=params["integration_id"], ) if request.method != "POST": return render_to_response( "sentry/auth-unlink-identity.html", request=request, context={"organization": organization, "provider": integration.get_provider()}, ) try: Identity.objects.filter(idp=idp, external_id=params["slack_id"]).delete() except IntegrityError as e: logger.error("slack.unlink.integrity-error", extra=e) raise Http404 send_slack_response(integration, SUCCESS_UNLINKED_MESSAGE, params, command="unlink") return render_to_response( "sentry/integrations/slack/unlinked.html", request=request, context={"channel_id": params["channel_id"], "team_id": integration.external_id}, )
def handle(self, request: Request, signed_params: str) -> Response: try: params = unsign(signed_params) except (SignatureExpired, BadSignature): return render_to_response( "sentry/integrations/slack/expired-link.html", request=request, ) organization, integration, idp = get_identity_or_404( ExternalProviders.SLACK, request.user, integration_id=params["integration_id"], organization_id=params["organization_id"], ) channel_name = params["channel_name"] channel_id = params["channel_id"] external_teams = ExternalActor.objects.filter( organization=organization, integration=integration, provider=ExternalProviders.SLACK.value, external_name=channel_name, external_id=channel_id, ) if len(external_teams) == 0: return render_error_page(request, body_text="HTTP 404: Team not found") team = external_teams[0].actor.resolve() if request.method != "POST": return render_to_response( "sentry/integrations/slack/unlink-team.html", request=request, context={ "team": team, "channel_name": channel_name, "provider": integration.get_provider(), }, ) if not Identity.objects.filter( idp=idp, external_id=params["slack_id"]).exists(): return render_error_page( request, body_text="HTTP 403: User identity does not exist") # Someone may have accidentally added multiple teams so unlink them all. for external_team in external_teams: external_team.delete() return send_confirmation( integration, channel_id, SUCCESS_UNLINKED_TITLE, SUCCESS_UNLINKED_MESSAGE.format(team=team.slug), "sentry/integrations/slack/unlinked-team.html", request, )
def handle(self, request, signed_params): try: params = unsign(signed_params) except (SignatureExpired, BadSignature): return render_to_response( "sentry/integrations/msteams/expired-link.html", request=request, ) organization, integration, idp = get_identity_or_404( ExternalProviders.MSTEAMS, request.user, integration_id=params["integration_id"], organization_id=params["organization_id"], ) if request.method != "POST": return render_to_response( "sentry/auth-link-identity.html", request=request, context={ "organization": organization, "provider": integration.get_provider() }, ) defaults = { "status": IdentityStatus.VALID, "date_verified": timezone.now() } try: identity, created = Identity.objects.get_or_create( idp=idp, user=request.user, external_id=params["teams_user_id"], defaults=defaults, ) if not created: identity.update(**defaults) except IntegrityError: Identity.objects.reattach(idp, params["teams_user_id"], request.user, defaults) card = build_linked_card() client = MsTeamsClient(integration) user_conversation_id = client.get_user_conversation_id( params["teams_user_id"], params["tenant_id"]) client.send_card(user_conversation_id, card) return render_to_response( "sentry/integrations/msteams/linked.html", request=request, context={"team_id": params["team_id"]}, )
def handle(self, request: Request, signed_params: str) -> Response: try: params = unsign(signed_params) except (SignatureExpired, BadSignature): return render_to_response( "sentry/integrations/slack/expired-link.html", request=request, ) organization, integration, idp = get_identity_or_404( ExternalProviders.SLACK, request.user, integration_id=params["integration_id"], ) if request.method != "POST": return render_to_response( "sentry/auth-link-identity.html", request=request, context={ "organization": organization, "provider": integration.get_provider() }, ) Identity.objects.link_identity(user=request.user, idp=idp, external_id=params["slack_id"]) send_slack_response(integration, SUCCESS_LINKED_MESSAGE, params, command="link") if not NotificationSetting.objects.has_any_provider_settings( request.user, ExternalProviders.SLACK): IntegrationNudgeNotification(organization, request.user, ExternalProviders.SLACK).send() # TODO(epurkhiser): We could do some fancy slack querying here to # render a nice linking page with info about the user their linking. return render_to_response( "sentry/integrations/slack/linked.html", request=request, context={ "channel_id": params["channel_id"], "team_id": integration.external_id }, )
def handle(self, request: Request, signed_params) -> Response: try: params = unsign(signed_params) except (SignatureExpired, BadSignature): return render_to_response( "sentry/integrations/msteams/expired-link.html", request=request, ) organization, integration, idp = get_identity_or_404( ExternalProviders.MSTEAMS, request.user, integration_id=params["integration_id"], organization_id=params["organization_id"], ) if request.method != "POST": return render_to_response( "sentry/auth-link-identity.html", request=request, context={ "organization": organization, "provider": integration.get_provider() }, ) Identity.objects.link_identity(user=request.user, idp=idp, external_id=params["teams_user_id"]) card = build_linked_card() client = MsTeamsClient(integration) user_conversation_id = client.get_user_conversation_id( params["teams_user_id"], params["tenant_id"]) client.send_card(user_conversation_id, card) return render_to_response( "sentry/integrations/msteams/linked.html", request=request, context={"team_id": params["team_id"]}, )