Skip to content

Commit 168b17a

Browse files
committed
🐛 Scope the nominee preview's nominator lookup to the election
1 parent 9ec9d55 commit 168b17a

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

‎apps/nominations/tests/test_views.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,13 @@ def test_preview_excludes_nominations_by_other_people(self):
389389
response = self.client.get(self._url(self.election))
390390
self.assertNotIn(self.unrelated_nominee, response.context["object_list"])
391391

392+
def test_preview_ignores_nominations_filed_under_another_election(self):
393+
# A nomination whose election disagrees with its nominee's (possible via the admin).
394+
self._nomination(self.other_election, self.nominator, self.unrelated_nominee)
395+
self.client.force_login(self.nominator)
396+
response = self.client.get(self._url(self.election))
397+
self.assertNotIn(self.unrelated_nominee, response.context["object_list"])
398+
392399
def test_preview_includes_the_user_as_a_candidate(self):
393400
self.client.force_login(self.nominator)
394401
response = self.client.get(self._url(self.other_election))

‎apps/nominations/views.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ def get_queryset(self, *args, **kwargs):
7878
# themselves when somebody nominated them.
7979
return (
8080
Nominee.objects.filter(
81-
Q(user=self.request.user) | Q(nominations__nominator=self.request.user),
81+
Q(user=self.request.user)
82+
| Q(nominations__nominator=self.request.user, nominations__election=election),
8283
election=election,
8384
)
8485
.exclude(user=None)

0 commit comments

Comments
 (0)