<commit_before># -*- coding: utf-8 -*-
from rest_framework import permissions

from website.models import Node, NodeLog

from api.nodes.permissions import ContributorOrPublic
from api.base.utils import get_object_or_error


class ContributorOrPublicForLogs(permissions.BasePermission):

    def has_object_permission(self, request, view, obj):
        assert isinstance(obj, (NodeLog)), 'obj must be a NodeLog, got {}'.format(obj)

        if obj._backrefs.get('logged'):
            for node_id in obj._backrefs['logged']['node']['logs']:
                node = get_object_or_error(Node, node_id, display_name='node')
                if ContributorOrPublic().has_object_permission(request, view, node):
                    return True

        if getattr(obj, 'node'):
            if ContributorOrPublic().has_object_permission(request, view, obj.node):
                return True

        return False<commit_msg>Minor logic simplification<commit_after># -*- coding: utf-8 -*-
from rest_framework import permissions

from website.models import Node, NodeLog

from api.nodes.permissions import ContributorOrPublic
from api.base.utils import get_object_or_error


class ContributorOrPublicForLogs(permissions.BasePermission):

    def has_object_permission(self, request, view, obj):
        assert isinstance(obj, (NodeLog)), 'obj must be a NodeLog, got {}'.format(obj)

        if obj._backrefs.get('logged'):
            for node_id in obj._backrefs['logged']['node']['logs']:
                node = get_object_or_error(Node, node_id, display_name='node')
                if ContributorOrPublic().has_object_permission(request, view, node):
                    return True

        if getattr(obj, 'node'):
            return ContributorOrPublic().has_object_permission(request, view, obj.node)
        return False
{'fraction_non_alphanumeric': 0.102803738317757, 'fraction_numerical': 0.0010995052226498076, 'mean_word_length': 3.292452830188679, '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': '4190824', 'n_tokens_mistral': 511, 'n_tokens_neox': 490, 'n_words': 127}