<commit_before>"""
sentry.web.frontend.projects
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:copyright: (c) 2012 by the Sentry Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect

from sentry.constants import (MEMBER_OWNER, PLATFORM_LIST, PLATFORM_TITLES,
    PLATFORM_ROOTS)
from sentry.models import ProjectKey
from sentry.web.decorators import has_access
from sentry.web.helpers import render_to_response, render_to_string


def can_see_global_keys(user, project):
    if user.is_superuser:
        return True
    if not project.team:
        return False
    if not project.team.member_set.filter(user=user, type=MEMBER_OWNER).exists():
        return False
    return True


def get_key_context(user, project):
    try:
        key = ProjectKey.objects.get(user=user, project=project)
    except ProjectKey.DoesNotExist:
        if can_see_global_keys(user, project):
            key_list = list(ProjectKey.objects.filter(project=project, user__isnull=True)[0:2])
        if len(key_list) == 1:
            key = key_list[0]
        else:
            key = None

    if key is None:
        dsn = 'SENTRY_DSN'
        dsn_public = 'SENTRY_PUBLIC_DSN'
    else:
        dsn = key.dsn_private
        dsn_public = key.dsn_public

    return {
        'key': key,
        'dsn': dsn,
        'dsn_public': dsn_public,
    }


@has_access
def client_help(request, team, project):
    context = {
        'page': 'client_help',
        'project': project,
        'team': project.team,
        'SUBSECTION': 'projects',
        'SECTION': 'team',
    }
    context.update(get_key_context(request.user, project))

    return render_to_response('sentry/projects/client_help.html', context, request)
<commit_msg>Prevent hard error on docs page when no ability to see global keys<commit_after>"""
sentry.web.frontend.projects
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:copyright: (c) 2012 by the Sentry Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect

from sentry.constants import (MEMBER_OWNER, PLATFORM_LIST, PLATFORM_TITLES,
    PLATFORM_ROOTS)
from sentry.models import ProjectKey
from sentry.web.decorators import has_access
from sentry.web.helpers import render_to_response, render_to_string


def can_see_global_keys(user, project):
    if user.is_superuser:
        return True
    if not project.team:
        return False
    if not project.team.member_set.filter(user=user, type=MEMBER_OWNER).exists():
        return False
    return True


def get_key_context(user, project):
    try:
        key = ProjectKey.objects.get(user=user, project=project)
    except ProjectKey.DoesNotExist:
        if can_see_global_keys(user, project):
            key_list = list(ProjectKey.objects.filter(project=project, user__isnull=True)[0:2])
            if len(key_list) == 1:
                key = key_list[0]
            else:
                key = None
        else:
            key = None

    if key is None:
        dsn = 'SENTRY_DSN'
        dsn_public = 'SENTRY_PUBLIC_DSN'
    else:
        dsn = key.dsn_private
        dsn_public = key.dsn_public

    return {
        'key': key,
        'dsn': dsn,
        'dsn_public': dsn_public,
    }


@has_access
def client_help(request, team, project):
    context = {
        'page': 'client_help',
        'project': project,
        'team': project.team,
        'SUBSECTION': 'projects',
        'SECTION': 'team',
    }
    context.update(get_key_context(request.user, project))

    return render_to_response('sentry/projects/client_help.html', context, request)

{'fraction_non_alphanumeric': 0.11004273504273504, 'fraction_numerical': 0.004273504273504274, 'mean_word_length': 2.9967982924226253, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4716304', 'n_tokens_mistral': 1204, 'n_tokens_neox': 1172, 'n_words': 283}