diff --git a/app/api/filters.py b/app/api/filters.py index 1efbc448..76346f4d 100644 --- a/app/api/filters.py +++ b/app/api/filters.py @@ -12,7 +12,7 @@ class DocumentFilter(FilterSet): def filter_annotations(self, queryset, field_name, value): queryset = queryset.annotate(num_annotations= Count(field_name, filter= - Q(**{ f"{field_name}__user": self.request.user}))) + Q(**{ f"{field_name}__user": self.request.user}) | Q(project__collaborative_annotation=True))) should_have_annotations = not value if should_have_annotations: diff --git a/app/api/tests/test_api.py b/app/api/tests/test_api.py index c5a8f378..cd76d17a 100644 --- a/app/api/tests/test_api.py +++ b/app/api/tests/test_api.py @@ -376,7 +376,7 @@ class TestLabelDetailAPI(APITestCase): remove_all_role_mappings() -class TestDocumentListAPI(APITestCase): +class TestDocumentListAPI(APITestCase, TestUtilsMixin): @classmethod def setUpTestData(cls): @@ -441,6 +441,32 @@ class TestDocumentListAPI(APITestCase): password=self.project_member_pass, expected_num_results=2) + def test_returns_docs_to_project_member_filtered_to_active_with_collaborative_annotation(self): + self._test_list('{}?doc_annotations__isnull=true'.format(self.url), + username=self.super_user_name, + password=self.super_user_pass, + expected_num_results=3) + + self._patch_project(self.main_project, 'collaborative_annotation', True) + + self._test_list('{}?doc_annotations__isnull=true'.format(self.url), + username=self.super_user_name, + password=self.super_user_pass, + expected_num_results=1) + + def test_returns_docs_to_project_member_filtered_to_completed_with_collaborative_annotation(self): + self._test_list('{}?doc_annotations__isnull=false'.format(self.url), + username=self.super_user_name, + password=self.super_user_pass, + expected_num_results=0) + + self._patch_project(self.main_project, 'collaborative_annotation', True) + + self._test_list('{}?doc_annotations__isnull=false'.format(self.url), + username=self.super_user_name, + password=self.super_user_pass, + expected_num_results=2) + def test_returns_docs_in_consistent_order_for_all_users(self): self.client.login(username=self.project_member_name, password=self.project_member_pass) user1_documents = self.client.get(self.url, format='json').json().get('results')