Skip to content

Commit

Permalink
Merge pull request #61 from RegioHelden/fix-user-filter
Browse files Browse the repository at this point in the history
Fix queryset filter to only utilize assigned groups if no assigned users
  • Loading branch information
lociii authored Jan 26, 2024
2 parents ac2e847 + b155fb6 commit b1b5675
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 2 additions & 2 deletions django_datawatch/querysets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
6 changes: 2 additions & 4 deletions django_datawatch/tests/test_querysets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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,
],
)

0 comments on commit b1b5675

Please sign in to comment.