From 9488094ff9c124c4df418d5a42d7e661e2736cc7 Mon Sep 17 00:00:00 2001
From: Eliot Berriot <contact@eliotberriot.com>
Date: Tue, 27 Aug 2019 14:00:33 +0200
Subject: [PATCH] See #890: Added is_local attribute on admin account API
 representations

---
 api/funkwhale_api/manage/serializers.py | 7 +++++++
 api/tests/manage/test_serializers.py    | 1 +
 2 files changed, 8 insertions(+)

diff --git a/api/funkwhale_api/manage/serializers.py b/api/funkwhale_api/manage/serializers.py
index 38a9cd57..f5fe1a53 100644
--- a/api/funkwhale_api/manage/serializers.py
+++ b/api/funkwhale_api/manage/serializers.py
@@ -1,3 +1,4 @@
+from django.conf import settings
 from django.db import transaction
 
 from rest_framework import serializers
@@ -183,6 +184,8 @@ class ManageDomainActionSerializer(common_serializers.ActionSerializer):
 
 
 class ManageBaseActorSerializer(serializers.ModelSerializer):
+    is_local = serializers.SerializerMethodField()
+
     class Meta:
         model = federation_models.Actor
         fields = [
@@ -201,9 +204,13 @@ class ManageBaseActorSerializer(serializers.ModelSerializer):
             "outbox_url",
             "shared_inbox_url",
             "manually_approves_followers",
+            "is_local",
         ]
         read_only_fields = ["creation_date", "instance_policy"]
 
+    def get_is_local(self, o):
+        return o.domain_id == settings.FEDERATION_HOSTNAME
+
 
 class ManageActorSerializer(ManageBaseActorSerializer):
     uploads_count = serializers.SerializerMethodField()
diff --git a/api/tests/manage/test_serializers.py b/api/tests/manage/test_serializers.py
index 7f99dd90..4056c181 100644
--- a/api/tests/manage/test_serializers.py
+++ b/api/tests/manage/test_serializers.py
@@ -87,6 +87,7 @@ def test_manage_actor_serializer(factories, now, to_api_date):
         "full_username": actor.full_username,
         "user": None,
         "instance_policy": None,
+        "is_local": False,
     }
     s = serializers.ManageActorSerializer(actor)
 
-- 
GitLab