Browse Source

Make document filter respect collab flag

pull/527/head
Clemens Wolff 4 years ago
parent
commit
e5d04947df
2 changed files with 28 additions and 2 deletions
  1. 2
      app/api/filters.py
  2. 28
      app/api/tests/test_api.py

2
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:

28
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')

Loading…
Cancel
Save