<commit_before>from rest_framework import viewsets

from wafer.kv.models import KeyValue
from wafer.kv.serializers import KeyValueSerializer
from wafer.kv.permissions import KeyValueGroupPermission

class KeyValueViewSet(viewsets.ModelViewSet):
    """API endpoint that allows key-value pairs to be viewed or edited."""
    queryset = KeyValue.objects.all()  # Needed for the REST Permissions
    serializer_class = KeyValueSerializer
    permission_classes = (KeyValueGroupPermission, )

    def get_queryset(self):
        # Space for future expansion
        return super(KeyValueViewSet, self).get_queryset()<commit_msg>Restrict view to only owned key-value pairs<commit_after>from rest_framework import viewsets

from wafer.kv.models import KeyValue
from wafer.kv.serializers import KeyValueSerializer
from wafer.kv.permissions import KeyValueGroupPermission

class KeyValueViewSet(viewsets.ModelViewSet):
    """API endpoint that allows key-value pairs to be viewed or edited."""
    queryset = KeyValue.objects.none()  # Needed for the REST Permissions
    serializer_class = KeyValueSerializer
    permission_classes = (KeyValueGroupPermission, )

    def get_queryset(self):
        # Restrict the list to only those that match the user's
        # groups
        if self.request.user.id is not None:
            grp_ids = [x.id for x in self.request.user.groups.all()]
            return KeyValue.objects.filter(group_id__in=grp_ids)
        return KeyValue.objects.none()
{'fraction_non_alphanumeric': 0.07017543859649122, 'fraction_numerical': 0.0, 'mean_word_length': 4.078767123287672, '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': '6673183', 'n_tokens_mistral': 406, 'n_tokens_neox': 396, 'n_words': 122}