Skip to content

Commit e5d0494

Browse files
committed
Make document filter respect collab flag
1 parent 70b63b6 commit e5d0494

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

app/api/filters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class DocumentFilter(FilterSet):
1212
def filter_annotations(self, queryset, field_name, value):
1313
queryset = queryset.annotate(num_annotations=
1414
Count(field_name, filter=
15-
Q(**{ f"{field_name}__user": self.request.user})))
15+
Q(**{ f"{field_name}__user": self.request.user}) | Q(project__collaborative_annotation=True)))
1616

1717
should_have_annotations = not value
1818
if should_have_annotations:

app/api/tests/test_api.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ def doCleanups(cls):
376376
remove_all_role_mappings()
377377

378378

379-
class TestDocumentListAPI(APITestCase):
379+
class TestDocumentListAPI(APITestCase, TestUtilsMixin):
380380

381381
@classmethod
382382
def setUpTestData(cls):
@@ -441,6 +441,32 @@ def test_returns_docs_to_project_member_filtered_to_completed(self):
441441
password=self.project_member_pass,
442442
expected_num_results=2)
443443

444+
def test_returns_docs_to_project_member_filtered_to_active_with_collaborative_annotation(self):
445+
self._test_list('{}?doc_annotations__isnull=true'.format(self.url),
446+
username=self.super_user_name,
447+
password=self.super_user_pass,
448+
expected_num_results=3)
449+
450+
self._patch_project(self.main_project, 'collaborative_annotation', True)
451+
452+
self._test_list('{}?doc_annotations__isnull=true'.format(self.url),
453+
username=self.super_user_name,
454+
password=self.super_user_pass,
455+
expected_num_results=1)
456+
457+
def test_returns_docs_to_project_member_filtered_to_completed_with_collaborative_annotation(self):
458+
self._test_list('{}?doc_annotations__isnull=false'.format(self.url),
459+
username=self.super_user_name,
460+
password=self.super_user_pass,
461+
expected_num_results=0)
462+
463+
self._patch_project(self.main_project, 'collaborative_annotation', True)
464+
465+
self._test_list('{}?doc_annotations__isnull=false'.format(self.url),
466+
username=self.super_user_name,
467+
password=self.super_user_pass,
468+
expected_num_results=2)
469+
444470
def test_returns_docs_in_consistent_order_for_all_users(self):
445471
self.client.login(username=self.project_member_name, password=self.project_member_pass)
446472
user1_documents = self.client.get(self.url, format='json').json().get('results')

0 commit comments

Comments
 (0)