diff --git a/django_datawatch/querysets.py b/django_datawatch/querysets.py index 1eb9bd8..b1665c0 100644 --- a/django_datawatch/querysets.py +++ b/django_datawatch/querysets.py @@ -9,10 +9,10 @@ class ResultQuerySet(models.QuerySet): def for_user(self, user): - user_groups = user.groups.all() + # Should only check assigned groups if result has no assigned users return self.filter( Q(assigned_users=user) - | Q(assigned_groups__in=user_groups) + | Q(assigned_users__isnull=True, assigned_groups__in=user.groups.all()) | Q(assigned_users__isnull=True, assigned_groups__isnull=True) ).distinct() diff --git a/django_datawatch/tests/test_querysets.py b/django_datawatch/tests/test_querysets.py index 9a08d64..a6b3bdf 100644 --- a/django_datawatch/tests/test_querysets.py +++ b/django_datawatch/tests/test_querysets.py @@ -65,11 +65,11 @@ def test_for_user(self): res_with_users_no_group = self._make_result( "test5", users=[user_with_group, user_with_groups] ) - # One group and one user (u2, u3) + # One group and one user (u2) res_with_group_and_user = self._make_result( "test6", users=[user_without_group], groups=[group_with_user] ) - # Multiple groups and one user (u2, u3) + # Multiple groups and one user (u2) res_with_groups_and_user = self._make_result( "test7", users=[user_without_group], @@ -99,8 +99,6 @@ def test_for_user(self): res_with_group_no_user, res_with_groups_no_user, res_with_users_no_group, - res_with_group_and_user, - res_with_groups_and_user, res_with_group_and_users, ], )