Ejemplo n.º 1
0
    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)

        message = "User %s of organization %s wants to publish %s\n" % (
            request.user.email,
            sentry_app.owner.slug,
            sentry_app.slug,
        )

        for question_pair in request.data.get("questionnaire"):
            message += "\n\n>%s\n%s" % (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"), ["*****@*****.**"],
                        fail_silently=False)

        return Response(status=201)
Ejemplo n.º 2
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)

        # For now, just send an email that a request to publish has been amde
        message = "User %s of organization %s wants to publish %s" % (
            request.user.email,
            sentry_app.owner.slug,
            sentry_app.slug,
        )

        email.send_mail(
            "Sentry App Publication Request",
            message,
            options.get("mail.from"),
            ["*****@*****.**"],
            fail_silently=False,
        )

        return Response(status=201)
Ejemplo n.º 4
0
def status_mail(request):
    form = TestEmailForm(request.POST or None)

    if form.is_valid():
        body = """This email was sent as a request to test the Sentry outbound email configuration."""
        try:
            send_mail(
                "%s Test Email" % (options.get("mail.subject-prefix"),),
                body,
                options.get("mail.from"),
                [request.user.email],
                fail_silently=False,
            )
        except Exception as e:
            form.errors["__all__"] = [six.text_type(e)]

    return render_to_response(
        "sentry/admin/status/mail.html",
        {
            "form": form,
            "mail_host": options.get("mail.host"),
            "mail_password": bool(options.get("mail.password")),
            "mail_username": options.get("mail.username"),
            "mail_port": options.get("mail.port"),
            "mail_use_tls": options.get("mail.use-tls"),
            "mail_from": options.get("mail.from"),
            "mail_list_namespace": options.get("mail.list-namespace"),
        },
        request,
    )
Ejemplo n.º 5
0
def status_mail(request):
    form = TestEmailForm(request.POST or None)

    if form.is_valid():
        body = """This email was sent as a request to test the Sentry outbound email configuration."""
        try:
            send_mail(
                '%s Test Email' % (options.get('mail.subject-prefix'), ),
                body,
                options.get('mail.from'), [request.user.email],
                fail_silently=False
            )
        except Exception as e:
            form.errors['__all__'] = [six.text_type(e)]

    return render_to_response(
        'sentry/admin/status/mail.html', {
            'form': form,
            'mail_host': options.get('mail.host'),
            'mail_password': bool(options.get('mail.password')),
            'mail_username': options.get('mail.username'),
            'mail_port': options.get('mail.port'),
            'mail_use_tls': options.get('mail.use-tls'),
            'mail_from': options.get('mail.from'),
            'mail_list_namespace': options.get('mail.list-namespace'),
        }, request
    )
Ejemplo n.º 6
0
    def post(self, request, sentry_app):
        if not features.has('organizations:sentry-apps',
                            sentry_app.owner,
                            actor=request.user):

            return Response(status=404)

        # 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)

        # For now, just send an email that a request to publish has been amde
        message = 'User %s of organization %s wants to publish %s' % (
            request.user.email, sentry_app.owner.slug, sentry_app.slug)

        email.send_mail('Sentry App Publication Request',
                        message,
                        options.get('mail.from'), ['*****@*****.**'],
                        fail_silently=False)

        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)
Ejemplo n.º 8
0
    def post(self, request):
        error = None

        body = """This email was sent as a request to test the Sentry outbound email configuration."""
        try:
            send_mail('%s Test Email' % (options.get('mail.subject-prefix'), ),
                      body,
                      options.get('mail.from'), [request.user.email],
                      fail_silently=False)
        except Exception as e:
            error = six.text_type(e)

        return Response({'error': error}, status=500 if error else 200)
Ejemplo n.º 9
0
 def test_send_mail_with_kwargs(self, get_connection, MockEmailMessage):
     patch.object(MockEmailMessage.return_value, "send")
     send_mail(
         "subject", "my_message", "*****@*****.**", ["*****@*****.**"], reply_to=["*****@*****.**"]
     )
     MockEmailMessage.assert_called_once_with(
         "subject",
         "my_message",
         "*****@*****.**",
         ["*****@*****.**"],
         connection="connection",
         reply_to=["*****@*****.**"],
     )
     MockEmailMessage.return_value.send.assert_called_once_with(fail_silently=False)
Ejemplo n.º 10
0
def create_new_user(request):
    if not request.is_superuser():
        return HttpResponseRedirect(auth.get_login_url())

    form = NewUserForm(
        request.POST or None, initial={
            'send_welcome_mail': True,
            'create_project': True,
        }
    )
    if form.is_valid():
        user = form.save(commit=False)

        # create a random password
        password = uuid.uuid4().hex
        user.set_password(password)

        user.save()

        if form.cleaned_data['send_welcome_mail']:
            context = {
                'username': user.username,
                'password': password,
                'url': absolute_uri(auth.get_login_url()),
            }
            body = render_to_string('sentry/emails/welcome_mail.txt', context, request)

            try:
                send_mail(
                    '%s Welcome to Sentry' % (options.get('mail.subject-prefix'), ),
                    body,
                    options.get('mail.from'), [user.email],
                    fail_silently=False
                )
            except Exception as e:
                logger = logging.getLogger('sentry.mail.errors')
                logger.exception(e)

        return HttpResponseRedirect(absolute_uri('/manage/users/'))

    context = {
        'form': form,
    }
    context.update(csrf(request))

    return render_to_response('sentry/admin/users/new.html', context, request)
Ejemplo n.º 11
0
def create_new_user(request):
    if not request.is_superuser():
        return HttpResponseRedirect(reverse('sentry'))

    form = NewUserForm(request.POST or None,
                       initial={
                           'send_welcome_mail': True,
                           'create_project': True,
                       })
    if form.is_valid():
        user = form.save(commit=False)

        # create a random password
        password = uuid.uuid4().hex
        user.set_password(password)

        user.save()

        if form.cleaned_data['send_welcome_mail']:
            context = {
                'username': user.username,
                'password': password,
                'url': absolute_uri(reverse('sentry')),
            }
            body = render_to_string('sentry/emails/welcome_mail.txt', context,
                                    request)

            try:
                send_mail('%s Welcome to Sentry' %
                          (options.get('mail.subject-prefix'), ),
                          body,
                          options.get('mail.from'), [user.email],
                          fail_silently=False)
            except Exception as e:
                logger = logging.getLogger('sentry.mail.errors')
                logger.exception(e)

        return HttpResponseRedirect(reverse('sentry-admin-users'))

    context = {
        'form': form,
    }
    context.update(csrf(request))

    return render_to_response('sentry/admin/users/new.html', context, request)
Ejemplo n.º 12
0
    def post(self, request: Request) -> Response:
        error = None

        body = (
            """This email was sent as a request to test the Sentry outbound email configuration."""
        )
        try:
            send_mail(
                "{} Test Email".format(options.get("mail.subject-prefix")),
                body,
                options.get("mail.from"),
                [request.user.email],
                fail_silently=False,
            )
        except Exception as e:
            error = str(e)

        return Response({"error": error}, status=500 if error else 200)
Ejemplo n.º 13
0
def status_mail(request):
    form = TestEmailForm(request.POST or None)

    if form.is_valid():
        body = """This email was sent as a request to test the Sentry outbound email configuration."""
        try:
            send_mail(
                '%s Test Email' % (options.get('mail.subject-prefix'),),
                body, options.get('mail.from'), [request.user.email],
                fail_silently=False
            )
        except Exception as e:
            form.errors['__all__'] = [six.text_type(e)]

    return render_to_response('sentry/admin/status/mail.html', {
        'form': form,
        'mail_host': options.get('mail.host'),
        'mail_password': bool(options.get('mail.password')),
        'mail_username': options.get('mail.username'),
        'mail_port': options.get('mail.port'),
        'mail_use_tls': options.get('mail.use-tls'),
        'mail_from': options.get('mail.from'),
        'mail_list_namespace': options.get('mail.list-namespace'),
    }, request)
Ejemplo n.º 14
0
def create_new_user(request):
    if not request.is_superuser():
        return HttpResponseRedirect(reverse("sentry"))

    form = NewUserForm(request.POST or None, initial={"send_welcome_mail": True, "create_project": True})
    if form.is_valid():
        user = form.save(commit=False)

        # create a random password
        password = uuid.uuid4().hex
        user.set_password(password)

        user.save()

        if form.cleaned_data["send_welcome_mail"]:
            context = {"username": user.username, "password": password, "url": absolute_uri(reverse("sentry"))}
            body = render_to_string("sentry/emails/welcome_mail.txt", context, request)

            try:
                send_mail(
                    "%s Welcome to Sentry" % (options.get("mail.subject-prefix"),),
                    body,
                    options.get("mail.from"),
                    [user.email],
                    fail_silently=False,
                )
            except Exception as e:
                logger = logging.getLogger("sentry.mail.errors")
                logger.exception(e)

        return HttpResponseRedirect(reverse("sentry-admin-users"))

    context = {"form": form}
    context.update(csrf(request))

    return render_to_response("sentry/admin/users/new.html", context, request)