<commit_before>from sentry.constants import MEMBER_USER
from sentry.models import Team, Project, User


class PermissionError(Exception):
    pass


def has_perm(object, user, access=MEMBER_USER):
    if user.is_superuser:
        return True

    # TODO: abstract this into a permission registry
    if type(object) == User:
        return object == user

    if type(object) == Team:
        return object.slug in Team.objects.get_for_user(user, access=access)

    if hasattr(object, 'project'):
        object = object.project

    if type(object) == Project:
        return object.slug in Project.objects.get_for_user(user, access=access)

    raise TypeError(type(object))


def assert_perm(*args, **kwargs):
    if not has_perm(*args, **kwargs):
        raise PermissionError
<commit_msg>Correct project permission<commit_after>from sentry.constants import MEMBER_USER
from sentry.models import Team, Project, User


class PermissionError(Exception):
    pass


def has_perm(object, user, access=MEMBER_USER):
    if user.is_superuser:
        return True

    # TODO: abstract this into a permission registry
    if type(object) == User:
        return object == user

    if type(object) == Team:
        return object.slug in Team.objects.get_for_user(user, access=access)

    if hasattr(object, 'project'):
        object = object.project

    if type(object) == Project:
        return object in Project.objects.get_for_user(user, access=access)

    raise TypeError(type(object))


def assert_perm(*args, **kwargs):
    if not has_perm(*args, **kwargs):
        raise PermissionError

{'fraction_non_alphanumeric': 0.09574468085106383, 'fraction_numerical': 0.0, 'mean_word_length': 3.491573033707865, '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': '3196023', 'n_tokens_mistral': 472, 'n_tokens_neox': 455, 'n_words': 134}