<commit_before>from django import template

from adhocracy4.rules.discovery import NormalUser

register = template.Library()


@register.assignment_tag
def would_have_perm(perm, obj=None):
    """
    Check if the NormalUser has the given permission.
    This checks only permissions defined with django-rules.
    """
    return NormalUser().would_have_perm(perm, obj)<commit_msg>add has_or_would_have_perm<commit_after>from django import template

from adhocracy4.rules.discovery import NormalUser

register = template.Library()


@register.assignment_tag
def would_have_perm(perm, obj=None):
    """
    Check if the NormalUser has the given permission.
    This checks only permissions defined with django-rules.
    """
    return NormalUser().would_have_perm(perm, obj)


@register.assignment_tag
def has_or_would_have_perm(perm, user, obj=None):
    """
    Check if the NormalUser has the given permission.
    This checks only permissions defined with django-rules.
    """
    if not hasattr(user, 'has_perm'):  # pragma: no cover
        return False  # swapped user model that doesn't support permissions
    elif user.is_authenticated():
        return user.has_perm(perm, obj)
    else:
        return NormalUser().would_have_perm(perm, obj)
{'fraction_non_alphanumeric': 0.08286852589641434, 'fraction_numerical': 0.0015936254980079682, 'mean_word_length': 4.105691056910569, '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': '3305874', 'n_tokens_mistral': 368, 'n_tokens_neox': 352, 'n_words': 109}