Use the in operator to test against the Organization membership subquery

If more than one Organization were selected by this subquery, then
Postgres would complain with "more than one row returned by a subquery
used as an expression".  We needed to allow for that case.

Annoyingly SQLite3 doesn't seem to care, so writing a py.test test to
exercise this isn't feasible under our current development setup.
This commit is contained in:
Jeff Bradberry 2019-06-19 14:42:07 -04:00
parent 9c06dc7106
commit 1a72ff4c47

View File

@ -1265,7 +1265,7 @@ class TeamAccess(BaseAccess):
(self.user.admin_of_organizations.exists() or self.user.auditor_of_organizations.exists()):
return self.model.objects.all()
return self.model.objects.filter(
Q(organization=Organization.accessible_pk_qs(self.user, 'member_role')) |
Q(organization__in=Organization.accessible_pk_qs(self.user, 'member_role')) |
Q(pk__in=self.model.accessible_pk_qs(self.user, 'read_role'))
)