From 7e76fa0bae88ef9d24c70b4a74c18f3cee6aac7a Mon Sep 17 00:00:00 2001
From: Agate <me@agate.blue>
Date: Fri, 5 Jun 2020 11:37:12 +0200
Subject: [PATCH] Added domain: support to ?scope parameter

---
 api/funkwhale_api/common/filters.py | 3 +++
 api/tests/common/test_filters.py    | 1 +
 2 files changed, 4 insertions(+)

diff --git a/api/funkwhale_api/common/filters.py b/api/funkwhale_api/common/filters.py
index df27a312a..dec4a89ab 100644
--- a/api/funkwhale_api/common/filters.py
+++ b/api/funkwhale_api/common/filters.py
@@ -202,6 +202,9 @@ class ActorScopeFilter(filters.CharFilter):
                 return queryset.none()
 
             return queryset.filter(**{self.actor_field: actor})
+        elif value.lower().startswith("domain:"):
+            domain = value.split("domain:", 1)[1]
+            return queryset.filter(**{"{}__domain_id".format(self.actor_field): domain})
         else:
             return queryset.none()
 
diff --git a/api/tests/common/test_filters.py b/api/tests/common/test_filters.py
index b45dcf111..6e8a7c354 100644
--- a/api/tests/common/test_filters.py
+++ b/api/tests/common/test_filters.py
@@ -52,6 +52,7 @@ def test_mutation_filter_is_approved(value, expected, factories):
         ("noop", 2, []),
         ("actor:actor1@domain.test", 0, [0]),
         ("actor:actor2@domain.test", 0, [1]),
+        ("domain:domain.test", 0, [0, 1]),
     ],
 )
 def test_actor_scope_filter(
-- 
GitLab