Пример #1
0
def notification_settings(request):
    settings_form = NotificationSettingsForm(request.user, request.POST or None)

    # TODO(dcramer): this is an extremely bad pattern and we need a more optimal
    # solution for rendering this (that ideally plays well with the org data)
    project_list = []
    organization_list = Organization.objects.get_for_user(
        user=request.user,
    )
    for organization in organization_list:
        team_list = Team.objects.get_for_user(
            user=request.user,
            organization=organization,
        )
        for team in team_list:
            project_list.extend(
                Project.objects.get_for_user(
                    user=request.user,
                    team=team,
                )
            )

    project_forms = [
        (project, ProjectEmailOptionsForm(
            project, request.user,
            request.POST or None,
            prefix='project-%s' % (project.id,)
        ))
        for project in sorted(project_list, key=lambda x: (
            x.team.name if x.team else None, x.name))
    ]

    ext_forms = []
    for plugin in plugins.all():
        for form in safe_execute(plugin.get_notification_forms) or ():
            form = safe_execute(form, plugin, request.user, request.POST or None, prefix=plugin.slug)
            if not form:
                continue
            ext_forms.append(form)

    if request.POST:
        all_forms = list(itertools.chain(
            [settings_form], ext_forms, (f for _, f in project_forms)
        ))
        if all(f.is_valid() for f in all_forms):
            for form in all_forms:
                form.save()
            messages.add_message(request, messages.SUCCESS, 'Your settings were saved.')
            return HttpResponseRedirect(request.path)

    context = csrf(request)
    context.update({
        'settings_form': settings_form,
        'project_forms': project_forms,
        'ext_forms': ext_forms,
        'page': 'notifications',
        'AUTH_PROVIDERS': get_auth_providers(),
    })
    return render_to_response('sentry/account/notifications.html', context, request)
Пример #2
0
def notification_settings(request):
    settings_form = NotificationSettingsForm(request.user, request.POST
                                             or None)

    project_list = list(
        Project.objects.filter(
            team__organizationmemberteam__organizationmember__user=request.
            user,
            team__organizationmemberteam__is_active=True,
            status=ProjectStatus.VISIBLE,
        ).distinct())

    project_forms = [
        (project,
         ProjectEmailOptionsForm(project,
                                 request.user,
                                 request.POST or None,
                                 prefix='project-%s' % (project.id, )))
        for project in sorted(project_list,
                              key=lambda x: (x.team.name
                                             if x.team else None, x.name))
    ]

    ext_forms = []
    for plugin in plugins.all():
        for form in safe_execute(plugin.get_notification_forms,
                                 _with_transaction=False) or ():
            form = safe_execute(form,
                                plugin,
                                request.user,
                                request.POST or None,
                                prefix=plugin.slug,
                                _with_transaction=False)
            if not form:
                continue
            ext_forms.append(form)

    if request.POST:
        all_forms = list(
            itertools.chain([settings_form], ext_forms,
                            (f for _, f in project_forms)))
        if all(f.is_valid() for f in all_forms):
            for form in all_forms:
                form.save()
            messages.add_message(request, messages.SUCCESS,
                                 'Your settings were saved.')
            return HttpResponseRedirect(request.path)

    context = csrf(request)
    context.update({
        'settings_form': settings_form,
        'project_forms': project_forms,
        'ext_forms': ext_forms,
        'page': 'notifications',
        'AUTH_PROVIDERS': get_auth_providers(),
    })
    return render_to_response('sentry/account/notifications.html', context,
                              request)
Пример #3
0
def notification_settings(request):
    settings_form = NotificationSettingsForm(request.user, request.POST
                                             or None)

    project_list = Project.objects.get_for_user(request.user,
                                                access=MEMBER_USER)
    project_forms = [
        (project,
         ProjectEmailOptionsForm(project,
                                 request.user,
                                 request.POST or None,
                                 prefix='project-%s' % (project.id, )))
        for project in sorted(project_list,
                              key=lambda x: (x.team.name, x.name))
    ]

    ext_forms = []
    for plugin in plugins.all():
        for form in safe_execute(plugin.get_notification_forms) or ():
            form = safe_execute(form,
                                plugin,
                                request.user,
                                request.POST or None,
                                prefix=plugin.slug)
            if not form:
                continue
            ext_forms.append(form)

    if request.POST:
        all_forms = list(
            itertools.chain([settings_form], ext_forms,
                            (f for _, f in project_forms)))
        if all(f.is_valid() for f in all_forms):
            for form in all_forms:
                form.save()
            messages.add_message(request, messages.SUCCESS,
                                 'Your settings were saved.')
            return HttpResponseRedirect(request.path)

    context = csrf(request)
    context.update({
        'settings_form': settings_form,
        'project_forms': project_forms,
        'ext_forms': ext_forms,
        'page': 'notifications',
    })
    return render_to_response('sentry/account/notifications.html', context,
                              request)
Пример #4
0
    def handle(self, request):
        settings_form = self.notification_settings_form(
            request.user, request.POST or None)
        reports_form = NotificationReportSettingsForm(
            request.user, request.POST or None,
            prefix='reports')

        org_list = list(Organization.objects.filter(
            status=OrganizationStatus.VISIBLE,
            member_set__user=request.user,
        ).distinct())

        org_list = [
            o for o in org_list if features.has(
                'organizations:release-commits',
                o,
                actor=request.user
            )
        ]

        org_forms = [
            (org, NotificationDeploySettingsForm(
                request.user,
                org,
                request.POST or None,
                prefix='deploys-org-%s' % (org.id,)
            ))
            for org in sorted(org_list, key=lambda o: o.name)
        ]

        project_list = list(Project.objects.filter(
            team__organizationmemberteam__organizationmember__user=request.user,
            team__organizationmemberteam__is_active=True,
            status=ProjectStatus.VISIBLE,
        ).distinct())

        project_forms = [
            (project, ProjectEmailOptionsForm(
                project, request.user,
                request.POST or None,
                prefix='project-%s' % (project.id,)
            ))
            for project in sorted(project_list, key=lambda x: (
                x.organization.name, x.name))
        ]

        ext_forms = []
        for plugin in plugins.all():
            for form in safe_execute(plugin.get_notification_forms, _with_transaction=False) or ():
                form = safe_execute(form, plugin, request.user, request.POST or None, prefix=plugin.slug,
                                    _with_transaction=False)
                if not form:
                    continue
                ext_forms.append(form)

        if request.POST:
            all_forms = list(itertools.chain(
                [settings_form, reports_form],
                ext_forms,
                (f for _, f in project_forms),
                (f for _, f in org_forms)
            ))
            if all(f.is_valid() for f in all_forms):
                for form in all_forms:
                    form.save()
                messages.add_message(request, messages.SUCCESS, 'Your settings were saved.')
                return HttpResponseRedirect(request.path)

        context = csrf(request)
        context.update({
            'settings_form': settings_form,
            'project_forms': project_forms,
            'org_forms': org_forms,
            'reports_form': reports_form,
            'ext_forms': ext_forms,
            'page': 'notifications',
            'AUTH_PROVIDERS': get_auth_providers(),
        })
        return render_to_response('sentry/account/notifications.html', context, request)