<commit_before>from functools import wraps
import json

from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect

from simpleoncall.models import TeamMember


def require_authentication(require_team=True):
    def wrapped(func):
        @wraps(func)
        def _wrapped(request, *args, **kwargs):
            if not request.user.is_authenticated():
                return HttpResponseRedirect(reverse('login'))
            if require_team:
                teams = TeamMember.objects.filter(user=request.user)
                if not teams:
                    return HttpResponseRedirect(reverse('create-team'))
            return func(request, *args, **kwargs)
        return _wrapped
    return wrapped


def require_selected_team():
    def wrapped(func):
        @wraps(func)<commit_msg>allow require_authentication to work with internal endpoints<commit_after>from functools import wraps
import json

from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect

from simpleoncall.models import TeamMember
from simpleoncall.internal import InternalResponse


def require_authentication(require_team=True, internal=False):
    def wrapped(func):
        @wraps(func)
        def _wrapped(request, *args, **kwargs):
            redirect = None
            if not request.user.is_authenticated():
                redirect = reverse('login')
            elif require_team:
                teams = TeamMember.objects.filter(user=request.user)
                if not teams:
                    redirect = reverse('create-team')

            if redirect:
                if internal:
                    return InternalResponse(redirect=redirect)
                return HttpResponseRedirect(redirect)

            return func(request, *args, **kwargs)
        return _wrapped
    return wrapped


def require_selected_team():
    def wrapped(func):
        @wraps(func)
{'fraction_non_alphanumeric': 0.0751684810782789, 'fraction_numerical': 0.0, 'mean_word_length': 2.574074074074074, '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': '1045441', 'n_tokens_mistral': 490, 'n_tokens_neox': 472, 'n_words': 128}