def dispatch(self, request, pipeline): try: integration = get_integration_from_request(request, BitbucketIntegrationProvider.key) except AtlassianConnectValidationError: return pipeline.error('Unable to verify installation.') pipeline.bind_state('external_id', integration.external_id) return pipeline.next_step()
def dispatch(self, request, pipeline): try: integration = get_integration_from_request( request, BitbucketIntegrationProvider.key) except AtlassianConnectValidationError: return pipeline.error('Unable to verify installation.') pipeline.bind_state('external_id', integration.external_id) return pipeline.next_step()
def handle(self, request): try: integration = get_integration_from_request(request, 'jira') except AtlassianConnectValidationError: return self.get_response( {'error_message': 'Unable to verify installation.'}) except ExpiredSignatureError: return self.get_response({'refresh_required': True}) if not request.user.is_authenticated(): return self.get_response({ 'login_required': True, 'login_url': absolute_uri(reverse('sentry-login')), }) organizations = list(request.user.get_orgs().filter( id__in=OrganizationMember.objects.filter( role__in=[r.id for r in roles.get_all() if r.is_global], user=request.user, ).values('organization'), )) form = JiraConfigForm(organizations, request.POST) if request.method == 'GET' or not form.is_valid(): active_orgs = OrganizationIntegration.objects.filter( integration__provider='jira', integration=integration, organization__in=organizations).values_list('organization_id', flat=True) form = JiraConfigForm(organizations, initial={'organizations': active_orgs}) return self.get_response({ 'form': form, 'organizations': organizations }) enabled_orgs = [ o for o in organizations if o.id in form.cleaned_data['organizations'] ] disabled_orgs = list(set(organizations) - set(enabled_orgs)) # Remove Jira integrations not in the set of enabled organizations OrganizationIntegration.objects.filter( integration__provider='jira', integration=integration, organization__in=disabled_orgs, ).delete() # Ensure all enabled integrations. for org in enabled_orgs: integration.add_organization(org, request.user) return self.get_response({'form': form, 'completed': True})
def handle(self, request): try: integration = get_integration_from_request(request, "jira") except AtlassianConnectValidationError: return self.get_response({"error_message": "Unable to verify installation."}) except ExpiredSignatureError: return self.get_response({"refresh_required": True}) if not request.user.is_authenticated(): parsed_user_agent = user_agent_parser.ParseUserAgent( request.META.get("HTTP_USER_AGENT", "") ) # not enabling cross site cookies seems to be a common problem with Safari # as a result, there is a Safari specific link to instructions when is_safari=true is_safari = parsed_user_agent.get("family") == "Safari" return self.get_response( { "login_required": True, "is_safari": is_safari, "login_url": absolute_uri(reverse("sentry-login")), } ) organizations = list( request.user.get_orgs().filter( id__in=OrganizationMember.objects.filter( role__in=[r.id for r in roles.get_all() if r.is_global], user=request.user ).values("organization") ) ) form = JiraConfigForm(organizations, request.POST) if request.method == "GET" or not form.is_valid(): active_orgs = OrganizationIntegration.objects.filter( integration__provider="jira", integration=integration, organization__in=organizations, ).values_list("organization_id", flat=True) form = JiraConfigForm(organizations, initial={"organizations": active_orgs}) return self.get_response({"form": form, "organizations": organizations}) enabled_orgs = [o for o in organizations if o.id in form.cleaned_data["organizations"]] disabled_orgs = list(set(organizations) - set(enabled_orgs)) # Remove Jira integrations not in the set of enabled organizations OrganizationIntegration.objects.filter( integration__provider="jira", integration=integration, organization__in=disabled_orgs ).delete() # Ensure all enabled integrations. for org in enabled_orgs: integration.add_organization(org, request.user) return self.get_response({"form": form, "completed": True})
def handle(self, request): try: integration = get_integration_from_request(request, "jira") except AtlassianConnectValidationError: return self.get_response( {"error_message": "Unable to verify installation."}) except ExpiredSignatureError: return self.get_response({"refresh_required": True}) if not request.user.is_authenticated(): return self.get_response({ "login_required": True, "login_url": absolute_uri(reverse("sentry-login")) }) organizations = list(request.user.get_orgs().filter( id__in=OrganizationMember.objects.filter( role__in=[r.id for r in roles.get_all() if r.is_global], user=request.user).values("organization"))) form = JiraConfigForm(organizations, request.POST) if request.method == "GET" or not form.is_valid(): active_orgs = OrganizationIntegration.objects.filter( integration__provider="jira", integration=integration, organization__in=organizations, ).values_list("organization_id", flat=True) form = JiraConfigForm(organizations, initial={"organizations": active_orgs}) return self.get_response({ "form": form, "organizations": organizations }) enabled_orgs = [ o for o in organizations if o.id in form.cleaned_data["organizations"] ] disabled_orgs = list(set(organizations) - set(enabled_orgs)) # Remove Jira integrations not in the set of enabled organizations OrganizationIntegration.objects.filter( integration__provider="jira", integration=integration, organization__in=disabled_orgs).delete() # Ensure all enabled integrations. for org in enabled_orgs: integration.add_organization(org, request.user) return self.get_response({"form": form, "completed": True})
def handle(self, request): try: integration = get_integration_from_request(request, 'jira') except AtlassianConnectValidationError: return self.get_response({'error_message': 'Unable to verify installation.'}) except ExpiredSignatureError: return self.get_response({'refresh_required': True}) if not request.user.is_authenticated(): return self.get_response({ 'login_required': True, 'login_url': absolute_uri(reverse('sentry-login')), }) organizations = list(request.user.get_orgs().filter( id__in=OrganizationMember.objects.filter( role__in=[r.id for r in roles.get_all() if r.is_global], user=request.user, ).values('organization'), )) form = JiraConfigForm(organizations, request.POST) if request.method == 'GET' or not form.is_valid(): active_orgs = OrganizationIntegration.objects.filter( integration__provider='jira', integration=integration, organization__in=organizations ).values_list('organization_id', flat=True) form = JiraConfigForm(organizations, initial={'organizations': active_orgs}) return self.get_response({'form': form, 'organizations': organizations}) enabled_orgs = [o for o in organizations if o.id in form.cleaned_data['organizations']] disabled_orgs = list(set(organizations) - set(enabled_orgs)) # Remove Jira integrations not in the set of enabled organizations OrganizationIntegration.objects.filter( integration__provider='jira', integration=integration, organization__in=disabled_orgs, ).delete() # Ensure all enabled integrations. for org in enabled_orgs: integration.add_organization(org, request.user) return self.get_response({'form': form, 'completed': True})
def handle(self, request): try: integration = get_integration_from_request(request, 'jira') except AtlassianConnectValidationError: return self.get_response( {'error_message': 'Unable to verify installation.'}) organizations = request.user.get_orgs().filter( id__in=OrganizationMember.objects.filter( role__in=[r.id for r in roles.get_all() if r.is_global], user=request.user, ).values('organization'), ) form = JiraConfigForm(organizations, request.POST) if request.method == 'GET' or not form.is_valid(): active_orgs = OrganizationIntegration.objects.filter( integration__provider='jira', integration=integration, organization__in=organizations).values_list('organization_id', flat=True) form = JiraConfigForm(organizations, initial={'organizations': active_orgs}) return self.get_response({'form': form}) enabled_orgs = form.cleaned_data['organizations'] disabled_orgs = list( set(o.id for o in organizations) - set(enabled_orgs)) # Remove organization and project Jira integrations not in the set of # enabled organizations OrganizationIntegration.objects.filter( integration__provider='jira', integration=integration, organization__in=disabled_orgs, ).delete() ProjectIntegration.objects.filter( integration__provider='jira', integration=integration, integration__organizations__in=disabled_orgs, ).delete() # Ensure all enabled integrations. for org_id in enabled_orgs: integration.add_organization(org_id) return self.get_response({'form': form, 'completed': True})
def get(self, request, *args, **kwargs): try: integration = get_integration_from_request(request, "jira") except AtlassianConnectValidationError: return self.get_response( {"error_message": "Unable to verify installation."}) except ExpiredSignatureError: return self.get_response({"refresh_required": True}) # expose a link to the configuration view signed_data = { "external_id": integration.external_id, "metadata": json.dumps(integration.metadata), } finish_link = u"{}.?signed_params={}".format( absolute_uri("/extensions/jira/configure/"), sign(**signed_data)) return self.get_response({"finish_link": finish_link})
def handle(self, request): try: integration = get_integration_from_request(request) except AtlassianConnectValidationError: return self.get_response({'error_message': 'Unable to verify installation.'}) organizations = request.user.get_orgs().filter( id__in=OrganizationMember.objects.filter( role__in=[r.id for r in roles.get_all() if r.is_global], ), ) form = JiraConfigForm(organizations, request.POST) if request.method == 'GET' or not form.is_valid(): active_orgs = OrganizationIntegration.objects.filter( integration__provider='jira', integration=integration, organization__in=organizations ).values_list('organization_id', flat=True) form = JiraConfigForm(organizations, initial={'organizations': active_orgs}) return self.get_response({'form': form}) enabled_orgs = form.cleaned_data['organizations'] disabled_orgs = list(set(o.id for o in organizations) - set(enabled_orgs)) # Remove organization and project Jira integrations not in the set of # enabled organizations OrganizationIntegration.objects.filter( integration__provider='jira', integration=integration, organization__in=disabled_orgs, ).delete() ProjectIntegration.objects.filter( integration__provider='jira', integration=integration, integration__organizations__in=disabled_orgs, ).delete() # Ensure all enabled integrations. for org_id in enabled_orgs: integration.add_organization(org_id) return self.get_response({'form': form, 'completed': True})
def handle(self, request): try: integration = get_integration_from_request(request) except AtlassianConnectValidationError: return self.get_response( {'error_message': 'Unable to verify installation.'}) # TODO(jess): restrict to org owners? organizations = request.user.get_orgs() form = JiraConfigForm(organizations, request.POST) if request.method == 'GET' or not form.is_valid(): active_orgs = OrganizationIntegration.objects.filter( integration__provider='jira', organization__in=organizations).values_list('organization_id', flat=True) form = JiraConfigForm(organizations, initial={'organizations': active_orgs}) return self.get_response({'form': form}) enabled_orgs = form.cleaned_data['organizations'] disabled_orgs = list( set(o.id for o in organizations) - set(enabled_orgs)) # Remove organization and project JIRA integrations not in the set of # enabled organizations OrganizationIntegration.objects.filter( integration__provider='jira', organization__in=disabled_orgs, ).delete() ProjectIntegration.objects.filter( integration__provider='jira', integration__organizations__in=disabled_orgs, ).delete() # Ensure all enabled integrations. for org_id in enabled_orgs: integration.add_organization(org_id) return self.get_response({'form': form})
def handle(self, request): try: integration = get_integration_from_request(request) except AtlassianConnectValidationError: return self.get_response({'error_message': 'Unable to verify installation.'}) # TODO(jess): restrict to org owners? org_choices = [(o.id, o.name) for o in request.user.get_orgs()] if request.method == 'GET': form = JiraConfigForm(org_choices) else: form = JiraConfigForm(org_choices, request.POST) if form.is_valid(): organization_id = form.cleaned_data['organization'] added = integration.add_organization(organization_id) if not added: return self.get_response({ 'error_message': 'That Sentry organization is already linked.', 'form': form, }) return self.get_response({'form': form})
def get(self, request, issue_key, *args, **kwargs): with configure_scope() as scope: try: integration = get_integration_from_request(request, "jira") except AtlassianConnectValidationError: scope.set_tag("failure", "AtlassianConnectValidationError") return self.get_response( {"error_message": "Unable to verify installation."}) except ExpiredSignatureError: scope.set_tag("failure", "ExpiredSignatureError") return self.get_response({"refresh_required": True}) try: external_issue = ExternalIssue.objects.get( integration_id=integration.id, key=issue_key) # TODO: handle multiple group_link = GroupLink.objects.filter( linked_type=GroupLink.LinkedType.issue, linked_id=external_issue.id, relationship=GroupLink.Relationship.references, ).first() if not group_link: raise GroupLink.DoesNotExist() group = Group.objects.get(id=group_link.group_id) except (ExternalIssue.DoesNotExist, GroupLink.DoesNotExist, Group.DoesNotExist) as e: scope.set_tag("failure", e.__class__.__name__) return self.get_response({"issue_not_linked": True}) scope.set_tag("organization.slug", group.organization.slug) # TODO: find more efficient way of getting stats def get_serialized_and_stats(stats_period): result = serialize( group, None, StreamGroupSerializer(stats_period=stats_period), ) stats = result["stats"][stats_period] return result, reduce(accum, stats, 0) def get_release_url(release): project = group.project return absolute_uri( "/organizations/{}/releases/{}/?project={}".format( project.organization.slug, quote(release), project.id)) def get_group_url(group): return group.get_absolute_url( params={"referrer": "sentry-issues-glance"}) result, stats_24hr = get_serialized_and_stats("24h") _, stats_14d = get_serialized_and_stats("14d") first_release = group.get_first_release() if first_release is not None: last_release = group.get_last_release() else: last_release = None first_release_url = None if first_release: first_release_url = get_release_url(first_release) last_release_url = None if last_release: last_release_url = get_release_url(last_release) context = { "type": result.get("metadata", {}).get("type", "Unknown Error"), "title": group.title, "title_url": get_group_url(group), "first_seen": result["firstSeen"], "last_seen": result["lastSeen"], "first_release": first_release, "first_release_url": first_release_url, "last_release": last_release, "last_release_url": last_release_url, "stats_24hr": stats_24hr, "stats_14d": stats_14d, } logger.info( "issue_hook.response", extra={ "type": context["type"], "title_url": context["title_url"] }, ) result = self.get_response(context) scope.set_tag("status_code", result.status_code) return result