Repository: akvo/akvo-rsr

Issue:
enumerators should be able to see "pending/unapproved" indicator updates from other enumerators.
When multiple enumerators are collaborating on a single indicator, they need to be able to see the updates from other enumerators. 


Discussion:
This requirement seems to be modified to include draft updates as well. 

Resolving patch:
diff --git a/akvo/rsr/models/result/indicator_period_data.py b/akvo/rsr/models/result/indicator_period_data.py
--- a/akvo/rsr/models/result/indicator_period_data.py
+++ b/akvo/rsr/models/result/indicator_period_data.py
@@ -217,29 +217,29 @@ def get_user_viewable_updates(cls, queryset, user):
             f_queryset = queryset
 
         else:
-            own_updates = queryset.filter(user=user)
-            non_draft_updates = queryset.exclude(status=cls.STATUS_DRAFT_CODE)
-            filter_ = user.get_permission_filter(
-                'rsr.view_indicatorperioddata',
-                'period__indicator__result__project__'
-            )
-
             from akvo.rsr.models import Project
             projects = Project.objects\
                               .filter(results__indicators__periods__data__in=queryset)\
                               .distinct()
+            project = projects.first() if projects.count() == 1 else None
+
+            # Allow Nuffic users to see all updates, irrespective of what state they are in
+            if project is not None and project.in_nuffic_hierarchy() and user.has_perm('rsr.view_project', project):
+                f_queryset = queryset
 
-            project = projects.first()
-            if projects.count() == 1 and user.has_perm('rsr.view_project', project) and project.in_nuffic_hierarchy():
-                others_updates = non_draft_updates
             else:
+                own_updates = queryset.filter(user=user)
+                non_draft_updates = queryset.exclude(status=cls.STATUS_DRAFT_CODE)
+                filter_ = user.get_permission_filter(
+                    'rsr.view_indicatorperioddata',
+                    'period__indicator__result__project__'
+                )
                 others_updates = non_draft_updates.filter(filter_)
-
-            f_queryset = (
-                approved_updates
-                | own_updates
-                | others_updates
-            )
+                f_queryset = (
+                    approved_updates
+                    | own_updates
+                    | others_updates
+                )
 
         return f_queryset.distinct()
 


Test patch:
diff --git a/akvo/rsr/tests/rest/test_result.py b/akvo/rsr/tests/rest/test_result.py
--- a/akvo/rsr/tests/rest/test_result.py
+++ b/akvo/rsr/tests/rest/test_result.py
@@ -175,13 +175,15 @@ def test_indicator_updates_visibility(self):
         self.assertEqual(response.status_code, 200)
         results = response.data['results']
         updates = results[0]['indicators'][1]['periods'][0]['updates']
-        self.assertEqual(len(updates), 5)
+        # Nuffic users can see drafts of other users too?!
+        self.assertEqual(len(updates), 6)
 
         user1_status = set(u['status'] for u in updates if u['user_details']['id'] == user1.id)
         user2_status = set(u['status'] for u in updates if u['user_details']['id'] != user1.id)
         self.assertIn('D', user1_status)
-        self.assertEqual(2, len(user2_status))
-        self.assertNotIn('D', user2_status)
+        self.assertIn('D', user2_status)
+        self.assertEqual(3, len(user1_status))
+        self.assertEqual(3, len(user2_status))
 
         # Non employed user should only see approved updates
         self.c.login(username=user3.email, password=password)