Пример #1
0
    def handle(self, request, organization, team, project):
        op = request.POST.get('op')
        if op == 'enable':
            self._handle_enable_plugin(request, project)
            return HttpResponseRedirect(request.path)
        elif op == 'disable':
            self._handle_disable_plugin(request, project)
            return HttpResponseRedirect(request.path)

        if op == 'save-settings':
            general_form = NotificationSettingsForm(
                data=request.POST,
                prefix='general',
                initial={
                    'subject_prefix': project.get_option(
                        'mail:subject_prefix', settings.EMAIL_SUBJECT_PREFIX),
                },
            )
            if general_form.is_valid():
                project.update_option(
                    'mail:subject_prefix', general_form.cleaned_data['subject_prefix'])
                messages.add_message(
                    request, messages.SUCCESS,
                    OK_SETTINGS_SAVED)
                return HttpResponseRedirect(request.path)
        else:
            general_form = NotificationSettingsForm(
                prefix='general',
                initial={
                    'subject_prefix': project.get_option(
                        'mail:subject_prefix', settings.EMAIL_SUBJECT_PREFIX),
                },
            )

        enabled_plugins = []
        other_plugins = []
        for plugin in self._iter_plugins():
            if plugin.is_enabled(project):
                content = plugin.get_notification_doc_html()

                form = plugin.project_conf_form
                if form is not None:
                    view = plugin.configure(request, project=project)
                    if isinstance(view, HttpResponse):
                        return view
                    enabled_plugins.append((plugin, mark_safe(content + view)))
                elif content:
                    enabled_plugins.append((plugin, mark_safe(content)))
            else:
                other_plugins.append(plugin)

        context = {
            'page': 'notifications',
            'enabled_plugins': enabled_plugins,
            'other_plugins': other_plugins,
            'general_form': general_form,
        }

        return self.respond('sentry/project-notifications.html', context)
Пример #2
0
def notification_settings(request, organization, project):
    general_form = NotificationSettingsForm(
        data=request.POST or None,
        prefix='general',
        initial={
            'subject_prefix':
            project.get_option('mail:subject_prefix',
                               settings.EMAIL_SUBJECT_PREFIX),
        },
    )

    threshold, min_events = project.get_option(
        'alert:threshold', DEFAULT_ALERT_PROJECT_THRESHOLD)

    alert_form = AlertSettingsForm(data=request.POST or None,
                                   prefix='alert',
                                   initial={
                                       'pct_threshold': threshold,
                                       'min_events': min_events,
                                   })

    all_forms = [
        alert_form,
        general_form,
    ]

    if request.method == 'POST' and all(f.is_valid() for f in all_forms):
        project.update_option('alert:threshold',
                              (alert_form.cleaned_data['pct_threshold'],
                               alert_form.cleaned_data['min_events']))
        project.update_option('mail:subject_prefix',
                              general_form.cleaned_data['subject_prefix'])

        messages.add_message(request, messages.SUCCESS,
                             _('Your settings were saved successfully.'))

        return HttpResponseRedirect(
            reverse('sentry-project-notifications',
                    args=[project.organization.slug, project.slug]))

    context = csrf(request)
    context.update({
        'organization': organization,
        'team': project.team,
        'project': project,
        'general_form': general_form,
        'alert_form': alert_form,
        'page': 'notifications',
    })
    return render_to_response('sentry/projects/notifications.html', context,
                              request)
Пример #3
0
    def handle(self, request, organization, team, project):
        op = request.POST.get('op')
        if op == 'enable':
            self._handle_enable_plugin(request, project)
            return HttpResponseRedirect(request.path)
        elif op == 'disable':
            self._handle_disable_plugin(request, project)
            return HttpResponseRedirect(request.path)

        if op == 'save-settings':
            if digests.enabled(project):
                digests_form = DigestSettingsForm(
                    data=request.POST,
                    prefix='digests',
                    initial={
                        'minimum_delay':
                        project.get_option(
                            get_digest_option_key('mail', 'minimum_delay'),
                            digests.minimum_delay / 60,
                        ),
                        'maximum_delay':
                        project.get_option(
                            get_digest_option_key('mail', 'maximum_delay'),
                            digests.maximum_delay / 60,
                        ),
                    },
                )
            else:
                digests_form = None

            general_form = NotificationSettingsForm(
                data=request.POST,
                prefix='general',
                initial={
                    'subject_prefix':
                    project.get_option('mail:subject_prefix',
                                       options.get('mail.subject-prefix')),
                },
            )
            if general_form.is_valid() and (digests_form.is_valid()
                                            if digests_form is not None else
                                            True):
                project.update_option(
                    'mail:subject_prefix',
                    general_form.cleaned_data['subject_prefix'])
                if digests_form is not None:
                    project.update_option(
                        get_digest_option_key('mail', 'minimum_delay'),
                        digests_form.cleaned_data['minimum_delay'] * 60,
                    )
                    project.update_option(
                        get_digest_option_key('mail', 'maximum_delay'),
                        digests_form.cleaned_data['maximum_delay'] * 60,
                    )
                messages.add_message(request, messages.SUCCESS,
                                     OK_SETTINGS_SAVED)
                return HttpResponseRedirect(request.path)
        else:
            if digests.enabled(project):
                digests_form = DigestSettingsForm(
                    prefix='digests',
                    initial={
                        'minimum_delay':
                        project.get_option(
                            get_digest_option_key('mail', 'minimum_delay'),
                            digests.minimum_delay,
                        ) / 60,
                        'maximum_delay':
                        project.get_option(
                            get_digest_option_key('mail', 'maximum_delay'),
                            digests.maximum_delay,
                        ) / 60,
                    },
                )
            else:
                digests_form = None

            general_form = NotificationSettingsForm(
                prefix='general',
                initial={
                    'subject_prefix':
                    project.get_option('mail:subject_prefix',
                                       options.get('mail.subject-prefix')),
                },
            )

        enabled_plugins = []
        other_plugins = []
        for plugin in self._iter_plugins():
            if plugin.is_enabled(project):
                content = plugin.get_notification_doc_html()

                form = plugin.project_conf_form
                if form is not None:
                    view = plugin.configure(request=request, project=project)
                    if isinstance(view, HttpResponse):
                        return view
                    enabled_plugins.append((plugin, mark_safe(content + view)))
                elif content:
                    enabled_plugins.append((plugin, mark_safe(content)))
            elif plugin.can_configure_for_project(project):
                other_plugins.append(plugin)

        is_user_subbed = project.is_user_subscribed_to_mail_alerts(
            request.user)

        context = {
            'page': 'notifications',
            'enabled_plugins': enabled_plugins,
            'other_plugins': other_plugins,
            'general_form': general_form,
            'digests_form': digests_form,
            'is_user_subbed': is_user_subbed
        }

        return self.respond('sentry/project-notifications.html', context)
Пример #4
0
    def handle(self, request, organization, team, project):
        op = request.POST.get('op')
        if op == 'enable':
            self._handle_enable_plugin(request, project)
            return HttpResponseRedirect(request.path)
        elif op == 'disable':
            self._handle_disable_plugin(request, project)
            return HttpResponseRedirect(request.path)

        if op == 'save-settings':
            general_form = NotificationSettingsForm(
                data=request.POST,
                prefix='general',
                initial={
                    'subject_prefix':
                    project.get_option('mail:subject_prefix',
                                       settings.EMAIL_SUBJECT_PREFIX),
                },
            )
            if general_form.is_valid():
                project.update_option(
                    'mail:subject_prefix',
                    general_form.cleaned_data['subject_prefix'])
                messages.add_message(request, messages.SUCCESS,
                                     OK_SETTINGS_SAVED)
                return HttpResponseRedirect(request.path)
        else:
            general_form = NotificationSettingsForm(
                prefix='general',
                initial={
                    'subject_prefix':
                    project.get_option('mail:subject_prefix',
                                       settings.EMAIL_SUBJECT_PREFIX),
                },
            )

        enabled_plugins = []
        other_plugins = []
        for plugin in self._iter_plugins():
            if plugin.is_enabled(project):
                content = plugin.get_notification_doc_html()

                form = plugin.project_conf_form
                if form is not None:
                    view = plugin.configure(request, project=project)
                    if isinstance(view, HttpResponse):
                        return view
                    enabled_plugins.append((plugin, mark_safe(content + view)))
                elif content:
                    enabled_plugins.append((plugin, mark_safe(content)))
            elif plugin.can_configure_for_project(project):
                other_plugins.append(plugin)

        context = {
            'page': 'notifications',
            'enabled_plugins': enabled_plugins,
            'other_plugins': other_plugins,
            'general_form': general_form,
        }

        return self.respond('sentry/project-notifications.html', context)
Пример #5
0
    def handle(self, request, organization, team, project):
        op = request.POST.get("op")
        if op == "enable":
            self._handle_enable_plugin(request, project)
            return HttpResponseRedirect(request.path)
        elif op == "disable":
            self._handle_disable_plugin(request, project)
            return HttpResponseRedirect(request.path)

        if op == "save-settings":
            if digests.enabled(project):
                digests_form = DigestSettingsForm(
                    data=request.POST,
                    prefix="digests",
                    initial={
                        "minimum_delay": project.get_option(
                            get_digest_option_key("mail", "minimum_delay"), digests.minimum_delay / 60
                        ),
                        "maximum_delay": project.get_option(
                            get_digest_option_key("mail", "maximum_delay"), digests.maximum_delay / 60
                        ),
                    },
                )
            else:
                digests_form = None

            general_form = NotificationSettingsForm(
                data=request.POST,
                prefix="general",
                initial={
                    "subject_prefix": project.get_option("mail:subject_prefix", options.get("mail.subject-prefix"))
                },
            )
            if general_form.is_valid() and (digests_form.is_valid() if digests_form is not None else True):
                project.update_option("mail:subject_prefix", general_form.cleaned_data["subject_prefix"])
                if digests_form is not None:
                    project.update_option(
                        get_digest_option_key("mail", "minimum_delay"), digests_form.cleaned_data["minimum_delay"] * 60
                    )
                    project.update_option(
                        get_digest_option_key("mail", "maximum_delay"), digests_form.cleaned_data["maximum_delay"] * 60
                    )
                messages.add_message(request, messages.SUCCESS, OK_SETTINGS_SAVED)
                return HttpResponseRedirect(request.path)
        else:
            if digests.enabled(project):
                digests_form = DigestSettingsForm(
                    prefix="digests",
                    initial={
                        "minimum_delay": project.get_option(
                            get_digest_option_key("mail", "minimum_delay"), digests.minimum_delay
                        )
                        / 60,
                        "maximum_delay": project.get_option(
                            get_digest_option_key("mail", "maximum_delay"), digests.maximum_delay
                        )
                        / 60,
                    },
                )
            else:
                digests_form = None

            general_form = NotificationSettingsForm(
                prefix="general",
                initial={
                    "subject_prefix": project.get_option("mail:subject_prefix", options.get("mail.subject-prefix"))
                },
            )

        enabled_plugins = []
        other_plugins = []
        for plugin in self._iter_plugins():
            if plugin.is_enabled(project):
                content = plugin.get_notification_doc_html()

                form = plugin.project_conf_form
                if form is not None:
                    view = plugin.configure(request, project=project)
                    if isinstance(view, HttpResponse):
                        return view
                    enabled_plugins.append((plugin, mark_safe(content + view)))
                elif content:
                    enabled_plugins.append((plugin, mark_safe(content)))
            elif plugin.can_configure_for_project(project):
                other_plugins.append(plugin)

        context = {
            "page": "notifications",
            "enabled_plugins": enabled_plugins,
            "other_plugins": other_plugins,
            "general_form": general_form,
            "digests_form": digests_form,
        }

        return self.respond("sentry/project-notifications.html", context)
Пример #6
0
def notification_settings(request, team, project):
    initial = project.get_option('notifcation:tags', {})

    general_form = NotificationSettingsForm(
        data=request.POST or None,
        prefix='general',
        initial={
            'subject_prefix':
            project.get_option('mail:subject_prefix',
                               settings.EMAIL_SUBJECT_PREFIX),
        },
    )

    tag_forms = []
    for tag in TagKey.objects.all_keys(project):
        tag_forms.append(
            NotificationTagValuesForm(
                project=project,
                tag=tag,
                data=request.POST or None,
                prefix='tag-%s' % (tag, ),
                initial={
                    'values': ', '.join(initial.get(tag, [])),
                },
            ))

    threshold, min_events = project.get_option(
        'alert:threshold', DEFAULT_ALERT_PROJECT_THRESHOLD)

    alert_form = AlertSettingsForm(data=request.POST or None,
                                   prefix='alert',
                                   initial={
                                       'pct_threshold': threshold,
                                       'min_events': min_events,
                                   })

    all_forms = [
        alert_form,
        general_form,
    ] + tag_forms

    if request.method == 'POST' and all(f.is_valid() for f in all_forms):
        tags = {}
        for t_form in tag_forms:
            values = t_form.cleaned_data['values']
            if values:
                tags[t_form.tag] = values

        project.update_option('notifcation:tags', tags)
        project.update_option('alert:threshold',
                              (alert_form.cleaned_data['pct_threshold'],
                               alert_form.cleaned_data['min_events']))
        project.update_option('mail:subject_prefix',
                              general_form.cleaned_data['subject_prefix'])

        messages.add_message(request, messages.SUCCESS,
                             _('Your settings were saved successfully.'))

        return HttpResponseRedirect(
            reverse('sentry-project-notifications',
                    args=[project.team.slug, project.slug]))

    context = csrf(request)
    context.update({
        'team': team,
        'project': project,
        'general_form': general_form,
        'alert_form': alert_form,
        'tag_forms': tag_forms,
        'page': 'notifications',
    })
    return render_to_response('sentry/projects/notifications.html', context,
                              request)
Пример #7
0
    def handle(self, request, organization, team, project):
        op = request.POST.get('op')
        if op == 'enable':
            self._handle_enable_plugin(request, project)
            return HttpResponseRedirect(request.path)
        elif op == 'disable':
            self._handle_disable_plugin(request, project)
            return HttpResponseRedirect(request.path)

        if op == 'save-settings':
            if digests.enabled(project):
                digests_form = DigestSettingsForm(
                    data=request.POST,
                    prefix='digests',
                    initial={
                        'minimum_delay': project.get_option(
                            get_digest_option_key('mail', 'minimum_delay'),
                            digests.minimum_delay / 60,
                        ),
                        'maximum_delay': project.get_option(
                            get_digest_option_key('mail', 'maximum_delay'),
                            digests.maximum_delay / 60,
                        ),
                    },
                )
            else:
                digests_form = None

            general_form = NotificationSettingsForm(
                data=request.POST,
                prefix='general',
                initial={
                    'subject_prefix': project.get_option(
                        'mail:subject_prefix', options.get('mail.subject-prefix')),
                },
            )
            if general_form.is_valid() and (digests_form.is_valid() if digests_form is not None else True):
                project.update_option('mail:subject_prefix', general_form.cleaned_data['subject_prefix'])
                if digests_form is not None:
                    project.update_option(
                        get_digest_option_key('mail', 'minimum_delay'),
                        digests_form.cleaned_data['minimum_delay'] * 60,
                    )
                    project.update_option(
                        get_digest_option_key('mail', 'maximum_delay'),
                        digests_form.cleaned_data['maximum_delay'] * 60,
                    )
                messages.add_message(
                    request, messages.SUCCESS,
                    OK_SETTINGS_SAVED)
                return HttpResponseRedirect(request.path)
        else:
            if digests.enabled(project):
                digests_form = DigestSettingsForm(
                    prefix='digests',
                    initial={
                        'minimum_delay': project.get_option(
                            get_digest_option_key('mail', 'minimum_delay'),
                            digests.minimum_delay,
                        ) / 60,
                        'maximum_delay': project.get_option(
                            get_digest_option_key('mail', 'maximum_delay'),
                            digests.maximum_delay,
                        ) / 60,
                    },
                )
            else:
                digests_form = None

            general_form = NotificationSettingsForm(
                prefix='general',
                initial={
                    'subject_prefix': project.get_option(
                        'mail:subject_prefix', options.get('mail.subject-prefix')),
                },
            )

        enabled_plugins = []
        other_plugins = []
        for plugin in self._iter_plugins():
            if plugin.is_enabled(project):
                content = plugin.get_notification_doc_html()

                form = plugin.project_conf_form
                if form is not None:
                    view = plugin.configure(request, project=project)
                    if isinstance(view, HttpResponse):
                        return view
                    enabled_plugins.append((plugin, mark_safe(content + view)))
                elif content:
                    enabled_plugins.append((plugin, mark_safe(content)))
            elif plugin.can_configure_for_project(project):
                other_plugins.append(plugin)

        is_user_subbed = project.is_user_subscribed_to_mail_alerts(request.user)

        context = {
            'page': 'notifications',
            'enabled_plugins': enabled_plugins,
            'other_plugins': other_plugins,
            'general_form': general_form,
            'digests_form': digests_form,
            'is_user_subbed': is_user_subbed
        }

        return self.respond('sentry/project-notifications.html', context)