Skip to content

Commit

Permalink
Merge pull request #629 from UW-GAC/bugfix/member-uploader-lists-when…
Browse files Browse the repository at this point in the history
…-group-is-not-set

Fix member and upload tables when groups are not set
  • Loading branch information
amstilp authored Jul 9, 2024
2 parents 55fea17 + 6b8dae0 commit d5fb864
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 12 deletions.
32 changes: 32 additions & 0 deletions gregor_django/gregor_anvil/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,14 @@ def test_rc_member_table(self):
self.assertIn(account, table.data)
self.assertNotIn(other_account, table.data)

def test_member_table_group_not_set(self):
obj = self.model_factory.create()
acm_factories.AccountFactory.create(verified=True)
self.client.force_login(self.user)
response = self.client.get(self.get_url(obj.pk))
table = response.context_data["tables"][1]
self.assertEqual(len(table.rows), 0)

def test_rc_uploader_table(self):
uploader_group = acm_factories.ManagedGroupFactory.create()
obj = self.model_factory.create(uploader_group=uploader_group)
Expand All @@ -346,6 +354,14 @@ def test_rc_uploader_table(self):
self.assertIn(account, table.data)
self.assertNotIn(other_account, table.data)

def test_upload_table_group_not_set(self):
obj = self.model_factory.create()
acm_factories.AccountFactory.create(verified=True)
self.client.force_login(self.user)
response = self.client.get(self.get_url(obj.pk))
table = response.context_data["tables"][2]
self.assertEqual(len(table.rows), 0)


class ResearchCenterListTest(TestCase):
"""Tests for the ResearchCenterList view."""
Expand Down Expand Up @@ -512,6 +528,14 @@ def test_member_table(self):
self.assertIn(account, table.data)
self.assertNotIn(other_account, table.data)

def test_member_table_group_not_set(self):
obj = self.model_factory.create()
acm_factories.AccountFactory.create(verified=True)
self.client.force_login(self.user)
response = self.client.get(self.get_url(obj.pk))
table = response.context_data["tables"][1]
self.assertEqual(len(table.rows), 0)

def test_uploader_table(self):
uploader_group = acm_factories.ManagedGroupFactory.create()
obj = self.model_factory.create(uploader_group=uploader_group)
Expand All @@ -525,6 +549,14 @@ def test_uploader_table(self):
self.assertIn(account, table.data)
self.assertNotIn(other_account, table.data)

def test_upload_table_group_not_set(self):
obj = self.model_factory.create()
acm_factories.AccountFactory.create(verified=True)
self.client.force_login(self.user)
response = self.client.get(self.get_url(obj.pk))
table = response.context_data["tables"][2]
self.assertEqual(len(table.rows), 0)


class PartnerGroupListTest(TestCase):
"""Tests for the ResearchCenterList view."""
Expand Down
36 changes: 24 additions & 12 deletions gregor_django/gregor_anvil/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,18 @@ class ResearchCenterDetail(AnVILConsortiumManagerStaffViewRequired, MultiTableMi
model = models.ResearchCenter

def get_tables(self):
members = Account.objects.filter(
groupaccountmembership__group=self.object.member_group,
)
uploaders = Account.objects.filter(
groupaccountmembership__group=self.object.uploader_group,
)
if self.object.member_group is None:
members = Account.objects.none()
else:
members = Account.objects.filter(
groupaccountmembership__group=self.object.member_group,
)
if self.object.uploader_group is None:
uploaders = Account.objects.none()
else:
uploaders = Account.objects.filter(
groupaccountmembership__group=self.object.uploader_group,
)
return [
UserTable(User.objects.filter(research_centers=self.object)),
tables.AccountTable(members, exclude=("user__research_centers", "number_groups")),
Expand All @@ -61,12 +67,18 @@ class PartnerGroupDetail(AnVILConsortiumManagerStaffViewRequired, MultiTableMixi
model = models.PartnerGroup

def get_tables(self):
members = Account.objects.filter(
groupaccountmembership__group=self.object.member_group,
)
uploaders = Account.objects.filter(
groupaccountmembership__group=self.object.uploader_group,
)
if self.object.member_group is None:
members = Account.objects.none()
else:
members = Account.objects.filter(
groupaccountmembership__group=self.object.member_group,
)
if self.object.uploader_group is None:
uploaders = Account.objects.none()
else:
uploaders = Account.objects.filter(
groupaccountmembership__group=self.object.uploader_group,
)
return [
UserTable(User.objects.filter(partner_groups=self.object)),
tables.AccountTable(members, exclude=("user__research_centers", "number_groups")),
Expand Down

0 comments on commit d5fb864

Please sign in to comment.