Coverage for django_napse/api/keys/serializers/key.py: 72%
18 statements
« prev ^ index » next coverage.py v7.4.3, created at 2024-03-12 13:49 +0000
« prev ^ index » next coverage.py v7.4.3, created at 2024-03-12 13:49 +0000
1from rest_framework import serializers
3from django_napse.api.permissions.serializers import PermissionSerializer
4from django_napse.auth.models import NapseAPIKey
7class NapseAPIKeySerializer(serializers.ModelSerializer):
8 permissions = PermissionSerializer(many=True, read_only=True)
10 class Meta:
11 model = NapseAPIKey
12 fields = [
13 "name",
14 "prefix",
15 "permissions",
16 "is_master_key",
17 "revoked",
18 "description",
19 ]
22class NapseAPIKeySpaceSerializer(serializers.ModelSerializer):
23 class Meta:
24 model = NapseAPIKey
25 fields = [
26 "name",
27 "prefix",
28 "is_master_key",
29 "revoked",
30 "description",
31 ]
33 def to_representation(self, instance):
34 representation = super().to_representation(instance)
35 representation["permissions"] = []
36 for permission in instance.permissions.filter(space__uuid=self.context["space"]):
37 representation["permissions"].append(permission.permission_type)
38 return representation