Skip to content

Commit

Permalink
feat: add organisation info to tokens serializers (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
rohan-chaturvedi authored Mar 10, 2024
1 parent 52df755 commit d8f0ac3
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions backend/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def create(self, validated_data):
class OrganisationSerializer(serializers.ModelSerializer):
class Meta:
model = Organisation
fields = ["id", "name", "identity_key", "created_at"]
fields = ["id", "name"]

def create(self, validated_data):
return Organisation(**validated_data)
Expand Down Expand Up @@ -103,9 +103,17 @@ class UserTokenSerializer(serializers.ModelSerializer):
# New field 'offline_enabled' with default value False
offline_enabled = serializers.BooleanField(default=False, read_only=True)

organisation = OrganisationSerializer(source="user.organisation", read_only=True)

class Meta:
model = UserToken
fields = ["wrapped_key_share", "user_id", "offline_enabled", "apps"]
fields = [
"wrapped_key_share",
"user_id",
"offline_enabled",
"apps",
"organisation",
]

def to_representation(self, instance):
representation = super().to_representation(instance)
Expand Down Expand Up @@ -143,9 +151,11 @@ def to_representation(self, instance):
class ServiceTokenSerializer(serializers.ModelSerializer):
apps = EnvironmentKeySerializer(many=True, read_only=True)

organisation = OrganisationSerializer(source="app.organisation", read_only=True)

class Meta:
model = ServiceToken
fields = ["wrapped_key_share", "apps"]
fields = ["wrapped_key_share", "apps", "organisation"]

def to_representation(self, instance):
representation = super().to_representation(instance)
Expand Down

0 comments on commit d8f0ac3

Please sign in to comment.