From 8741d204f73ce8d066ee0b3595c5ee98f6376b99 Mon Sep 17 00:00:00 2001 From: niklub Date: Thu, 3 Jun 2021 13:38:23 +0200 Subject: [PATCH] Fix API for getting organizations (#997) * Return organizations where user belongs to * Add tests Co-authored-by: nik --- label_studio/organizations/api.py | 2 +- ...{test_active_organization.py => test_organizations.py} | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) rename label_studio/tests/{test_active_organization.py => test_organizations.py} (61%) diff --git a/label_studio/organizations/api.py b/label_studio/organizations/api.py index ad31bf3caf59..72d448c7d257 100644 --- a/label_studio/organizations/api.py +++ b/label_studio/organizations/api.py @@ -40,7 +40,7 @@ def get_object(self): return org def get_queryset(self): - return Organization.objects.filter(created_by=self.request.user) + return Organization.objects.filter(users=self.request.user).distinct() @swagger_auto_schema(tags=['Organizations']) def get(self, request, *args, **kwargs): diff --git a/label_studio/tests/test_active_organization.py b/label_studio/tests/test_organizations.py similarity index 61% rename from label_studio/tests/test_active_organization.py rename to label_studio/tests/test_organizations.py index d9f5f971d37c..c7aa53144a6f 100644 --- a/label_studio/tests/test_active_organization.py +++ b/label_studio/tests/test_organizations.py @@ -8,3 +8,11 @@ def test_active_organization_filled(business_client): response = business_client.get('/api/users/') response_data = response.json() assert response_data[0]['active_organization'] == business_client.organization.id + + +@pytest.mark.django_db +def test_api_list_organizations(business_client): + response = business_client.get('/api/organizations/') + response_data = response.json() + assert len(response_data) == 1 + assert response_data[0]['id'] == business_client.organization.id