Пример #1
0
    def post(self, request: Request, sentry_app) -> Response:
        # check status of app to make sure it is unpublished
        if sentry_app.is_published:
            return Response(
                {"detail": "Cannot publish already published integration."},
                status=400)

        if sentry_app.is_internal:
            return Response({"detail": "Cannot publish internal integration."},
                            status=400)

        if sentry_app.is_publish_request_inprogress:
            return Response({"detail": "Publish request in progress."},
                            status=400)

        if not SentryAppAvatar.objects.filter(
                sentry_app=sentry_app,
                color=True,
                avatar_type=SentryAppAvatarTypes.UPLOAD.value).exists():
            return Response(
                {"detail": "Must upload a logo for the integration."},
                status=400)

        if (self.has_ui_component(sentry_app)
                and not SentryAppAvatar.objects.filter(
                    sentry_app=sentry_app,
                    color=False,
                    avatar_type=SentryAppAvatarTypes.UPLOAD.value,
                ).exists()):
            return Response(
                {
                    "detail":
                    "Must upload an icon for issue and stack trace linking integrations."
                },
                status=400,
            )

        Updater.run(
            user=request.user,
            sentry_app=sentry_app,
            status=SentryAppStatus.PUBLISH_REQUEST_INPROGRESS_STR,
        )

        message = f"User {request.user.email} of organization {sentry_app.owner.slug} wants to publish {sentry_app.slug}\n"

        for question_pair in request.data.get("questionnaire"):
            message += "\n\n>{}\n{}".format(question_pair["question"],
                                            question_pair["answer"])

        subject = "Sentry Integration Publication Request from %s" % sentry_app.owner.slug

        email.send_mail(
            subject,
            message,
            options.get("mail.from"),
            ["*****@*****.**"],
            reply_to=[request.user.email],
        )

        return Response(status=201)
    def post(self, request, sentry_app):
        # check status of app to make sure it is unpublished
        if sentry_app.is_published:
            return Response({"detail": "Cannot publish already published integration."}, status=400)

        if sentry_app.is_internal:
            return Response({"detail": "Cannot publish internal integration."}, status=400)

        if sentry_app.is_publish_request_inprogress:
            return Response({"detail": "Publish request in progress."}, status=400)

        Updater.run(
            user=request.user,
            sentry_app=sentry_app,
            status=SentryAppStatus.PUBLISH_REQUEST_INPROGRESS_STR,
        )

        message = f"User {request.user.email} of organization {sentry_app.owner.slug} wants to publish {sentry_app.slug}\n"

        for question_pair in request.data.get("questionnaire"):
            message += "\n\n>{}\n{}".format(question_pair["question"], question_pair["answer"])

        subject = "Sentry Integration Publication Request from %s" % sentry_app.owner.slug

        email.send_mail(
            subject,
            message,
            options.get("mail.from"),
            ["*****@*****.**"],
            reply_to=[request.user.email],
        )

        return Response(status=201)
Пример #3
0
    def put(self, request, sentry_app):
        if not features.has('organizations:internal-catchall',
                            sentry_app.owner,
                            actor=request.user):

            return Response(status=404)

        serializer = SentryAppSerializer(data=request.DATA, partial=True)

        if serializer.is_valid():
            result = serializer.object

            updated_app = Updater.run(
                sentry_app=sentry_app,
                name=result.get('name'),
                webhook_url=result.get('webhookUrl'),
                redirect_url=result.get('redirectUrl'),
                is_alertable=result.get('isAlertable'),
                scopes=result.get('scopes'),
                events=result.get('events'),
                overview=result.get('overview'),
            )

            return Response(serialize(updated_app, request.user))

        return Response(serializer.errors, status=400)
Пример #4
0
    def put(self, request, sentry_app):
        if not features.has('organizations:internal-catchall',
                            sentry_app.owner,
                            actor=request.user):

            return Response(status=404)

        serializer = SentryAppSerializer(data=request.DATA, partial=True)

        if serializer.is_valid():
            result = serializer.object

            updated_app = Updater.run(
                sentry_app=sentry_app,
                name=result.get('name'),
                webhook_url=result.get('webhookUrl'),
                redirect_url=result.get('redirectUrl'),
                is_alertable=result.get('isAlertable'),
                scopes=result.get('scopes'),
                events=result.get('events'),
                overview=result.get('overview'),
            )

            return Response(serialize(updated_app, request.user))

        return Response(serializer.errors, status=400)
Пример #5
0
    def put(self, request, sentry_app):
        if not features.has('organizations:sentry-apps',
                            sentry_app.owner,
                            actor=request.user):

            return Response(status=404)

        serializer = SentryAppSerializer(
            sentry_app,
            data=request.data,
            partial=True,
        )

        if serializer.is_valid():
            result = serializer.validated_data

            updated_app = Updater.run(
                user=request.user,
                sentry_app=sentry_app,
                name=result.get('name'),
                author=result.get('author'),
                status=result.get('status'),
                webhook_url=result.get('webhookUrl'),
                redirect_url=result.get('redirectUrl'),
                is_alertable=result.get('isAlertable'),
                scopes=result.get('scopes'),
                events=result.get('events'),
                schema=result.get('schema'),
                overview=result.get('overview'),
            )

            return Response(serialize(updated_app, request.user))
        return Response(serializer.errors, status=400)
    def put(self, request, sentry_app):
        if self._has_hook_events(request) and not features.has(
            "organizations:integrations-event-hooks", sentry_app.owner, actor=request.user
        ):

            return Response(
                {
                    "non_field_errors": [
                        "Your organization does not have access to the 'error' resource subscription."
                    ]
                },
                status=403,
            )

        # isInternal is not field of our model but it is a field of the serializer
        data = request.data.copy()
        data["isInternal"] = sentry_app.status == SentryAppStatus.INTERNAL
        serializer = SentryAppSerializer(sentry_app, data=data, partial=True, access=request.access)

        if serializer.is_valid():
            result = serializer.validated_data

            updated_app = Updater.run(
                user=request.user,
                sentry_app=sentry_app,
                name=result.get("name"),
                author=result.get("author"),
                status=result.get("status"),
                webhook_url=result.get("webhookUrl"),
                redirect_url=result.get("redirectUrl"),
                is_alertable=result.get("isAlertable"),
                verify_install=result.get("verifyInstall"),
                scopes=result.get("scopes"),
                events=result.get("events"),
                schema=result.get("schema"),
                overview=result.get("overview"),
                allowed_origins=result.get("allowedOrigins"),
            )

            return Response(serialize(updated_app, request.user, access=request.access))

        # log any errors with schema
        if "schema" in serializer.errors:
            for error_message in serializer.errors["schema"]:
                name = "sentry_app.schema_validation_error"
                log_info = {
                    "schema": json.dumps(request.data["schema"]),
                    "user_id": request.user.id,
                    "sentry_app_id": sentry_app.id,
                    "sentry_app_name": sentry_app.name,
                    "organization_id": sentry_app.owner.id,
                    "error_message": error_message,
                }
                logger.info(name, extra=log_info)
                analytics.record(name, **log_info)

        return Response(serializer.errors, status=400)
Пример #7
0
    def put(self, request, sentry_app):
        serializer = SentryAppSerializer(data=request.DATA, partial=True)
        if serializer.is_valid():
            result = serializer.object
            updated_app = Updater.run(
                sentry_app=sentry_app,
                name=result.get('name'),
                webhook_url=result.get('webhook_url'),
                scopes=result.get('scopes'),
            )
            return Response(serialize(updated_app, request.user))

        return Response(serializer.errors, status=400)
Пример #8
0
    def put(self, request, sentry_app):
        if not features.has('organizations:sentry-apps',
                            sentry_app.owner,
                            actor=request.user):

            return Response(status=404)

        if self._has_hook_events(request) and not features.has(
                'organizations:integrations-event-hooks',
                sentry_app.owner,
                actor=request.user):

            return Response(
                {
                    "non_field_errors": [
                        "Your organization does not have access to the 'error' resource subscription.",
                    ]
                },
                status=403)

        serializer = SentryAppSerializer(
            sentry_app,
            data=request.data,
            partial=True,
        )

        if serializer.is_valid():
            result = serializer.validated_data

            updated_app = Updater.run(
                user=request.user,
                sentry_app=sentry_app,
                name=result.get('name'),
                author=result.get('author'),
                status=result.get('status'),
                webhook_url=result.get('webhookUrl'),
                redirect_url=result.get('redirectUrl'),
                is_alertable=result.get('isAlertable'),
                verify_install=result.get('verifyInstall'),
                scopes=result.get('scopes'),
                events=result.get('events'),
                schema=result.get('schema'),
                overview=result.get('overview'),
            )

            return Response(serialize(updated_app, request.user))
        return Response(serializer.errors, status=400)
Пример #9
0
    def put(self, request, sentry_app):
        if not features.has('organizations:sentry-apps',
                            sentry_app.owner,
                            actor=request.user):

            return Response(status=404)

        data = {
            'user': request.user,
            'sentry_app': sentry_app,
            'name': request.json_body.get('name'),
            'status': request.json_body.get('status'),
            'author': request.json_body.get('author'),
            'webhookUrl': request.json_body.get('webhookUrl'),
            'redirectUrl': request.json_body.get('redirectUrl'),
            'isAlertable': request.json_body.get('isAlertable'),
            'scopes': request.json_body.get('scopes'),
            'events': request.json_body.get('events'),
            'schema': request.json_body.get('schema'),
            'overview': request.json_body.get('overview'),
        }

        serializer = SentryAppSerializer(
            instance=sentry_app,
            data=data,
            partial=True,
        )

        if serializer.is_valid():
            result = serializer.object

            data['redirect_url'] = data['redirectUrl']
            data['webhook_url'] = data['webhookUrl']
            data['is_alertable'] = data['isAlertable']
            data['scopes'] = result.get('scopes')
            data['events'] = result.get('events')

            updated_app = Updater.run(**data)

            return Response(serialize(updated_app, request.user))
        return Response(serializer.errors, status=400)
Пример #10
0
    def put(self, request, sentry_app):
        if not features.has('organizations:sentry-apps',
                            sentry_app.owner,
                            actor=request.user):

            return Response(status=404)

        data = {
            'user': request.user,
            'sentry_app': sentry_app,
            'name': request.json_body.get('name'),
            'status': request.json_body.get('status'),
            'author': request.json_body.get('author'),
            'webhookUrl': request.json_body.get('webhookUrl'),
            'redirectUrl': request.json_body.get('redirectUrl'),
            'isAlertable': request.json_body.get('isAlertable'),
            'scopes': request.json_body.get('scopes'),
            'events': request.json_body.get('events'),
            'schema': request.json_body.get('schema'),
            'overview': request.json_body.get('overview'),
        }

        serializer = SentryAppSerializer(
            instance=sentry_app,
            data=data,
            partial=True,
        )

        if serializer.is_valid():
            result = serializer.object

            data['redirect_url'] = data['redirectUrl']
            data['webhook_url'] = data['webhookUrl']
            data['is_alertable'] = data['isAlertable']
            data['scopes'] = result.get('scopes')
            data['events'] = result.get('events')

            updated_app = Updater.run(**data)

            return Response(serialize(updated_app, request.user))
        return Response(serializer.errors, status=400)