Prevent multiple entries in entitled_users_at_stop

This commit is contained in:
Joshua Sangmeister 2021-04-08 10:47:26 +02:00
parent a94f00672b
commit f54050a83c
2 changed files with 16 additions and 1 deletions

View File

@ -275,9 +275,11 @@ class BasePoll(models.Model):
def calculate_entitled_users(self):
entitled_users = []
entitled_users_ids = set()
for group in self.groups.all():
for user in group.user_set.all():
if user.is_present:
if user.is_present and user.id not in entitled_users_ids:
entitled_users_ids.add(user.id)
entitled_users.append(
{
"user_id": user.id,

View File

@ -1208,6 +1208,19 @@ class StopMotionPoll(TestCase):
],
)
def test_stop_poll_assert_no_duplicate_entitled_users(self):
self.setup_entitled_users()
delegate_group = get_group_model().objects.get(pk=GROUP_DELEGATE_PK)
self.admin.groups.add(delegate_group)
self.poll.groups.add(delegate_group)
response = self.client.post(reverse("motionpoll-stop", args=[self.poll.pk]))
self.assertHttpStatusVerbose(response, status.HTTP_200_OK)
self.assertEqual(
MotionPoll.objects.get().entitled_users_at_stop,
[{"user_id": self.admin.id, "voted": False, "vote_delegated_to_id": None}],
)
class PublishMotionPoll(TestCase):
def advancedSetUp(self):