Deactivate empty votes for assignment polls

This commit is contained in:
Joshua Sangmeister 2020-11-05 16:34:18 +01:00
parent 6bc2c104b1
commit 883463ea87
3 changed files with 16 additions and 10 deletions

View File

@ -149,7 +149,7 @@
<ng-template #sendNow let-delegation="delegation">
<div class="centered-button-wrapper">
<button mat-flat-button color="accent" (click)="submitVote(delegation)">
<button mat-flat-button color="accent" (click)="submitVote(delegation)" [disabled]="getVotesCount(delegation) == 0">
<mat-icon> how_to_vote </mat-icon>
<span>
{{ 'Submit vote now' | translate }}

View File

@ -407,6 +407,8 @@ class AssignmentPollViewSet(BasePollViewSet):
)
else:
if isinstance(data, dict) and len(data) == 0:
raise ValidationError({"details": "Empty ballots are not allowed"})
available_options = poll.get_options()
if poll.pollmethod == AssignmentPoll.POLLMETHOD_VOTES:
if isinstance(data, dict):
@ -419,9 +421,7 @@ class AssignmentPollViewSet(BasePollViewSet):
{"detail": f"Option {option_id} does not exist."}
)
if not is_int(amount):
raise ValidationError(
{"detail": "Each amounts must be int"}
)
raise ValidationError({"detail": "Each amount must be int"})
amount = int(amount)
if amount < 0:
raise ValidationError(

View File

@ -1174,10 +1174,10 @@ class VoteAssignmentPollNamedYNA(VoteAssignmentPollBaseTestClass):
response = self.client.post(
reverse("assignmentpoll-vote", args=[self.poll.pk]), {"data": {}}
)
self.assertHttpStatusVerbose(
response, status.HTTP_200_OK
) # new "feature" because of partial requests: empty requests work!
self.assertHttpStatusVerbose(response, status.HTTP_400_BAD_REQUEST)
self.assertFalse(AssignmentVote.objects.exists())
poll = AssignmentPoll.objects.get()
self.assertNotIn(self.admin.id, poll.voted.all())
def test_wrong_data_format(self):
self.start_poll()
@ -1459,8 +1459,10 @@ class VoteAssignmentPollNamedVotes(VoteAssignmentPollBaseTestClass):
response = self.client.post(
reverse("assignmentpoll-vote", args=[self.poll.pk]), {"data": {}}
)
self.assertHttpStatusVerbose(response, status.HTTP_200_OK)
self.assertHttpStatusVerbose(response, status.HTTP_400_BAD_REQUEST)
self.assertFalse(AssignmentVote.objects.exists())
poll = AssignmentPoll.objects.get()
self.assertNotIn(self.admin.id, poll.voted.all())
def test_wrong_data_format(self):
self.start_poll()
@ -1650,8 +1652,10 @@ class VoteAssignmentPollPseudoanonymousYNA(VoteAssignmentPollBaseTestClass):
response = self.client.post(
reverse("assignmentpoll-vote", args=[self.poll.pk]), {"data": {}}
)
self.assertHttpStatusVerbose(response, status.HTTP_200_OK)
self.assertHttpStatusVerbose(response, status.HTTP_400_BAD_REQUEST)
self.assertFalse(AssignmentVote.objects.exists())
poll = AssignmentPoll.objects.get()
self.assertNotIn(self.admin.id, poll.voted.all())
def test_wrong_data_format(self):
self.start_poll()
@ -1883,8 +1887,10 @@ class VoteAssignmentPollPseudoanonymousVotes(VoteAssignmentPollBaseTestClass):
response = self.client.post(
reverse("assignmentpoll-vote", args=[self.poll.pk]), {"data": {}}
)
self.assertHttpStatusVerbose(response, status.HTTP_200_OK)
self.assertHttpStatusVerbose(response, status.HTTP_400_BAD_REQUEST)
self.assertFalse(AssignmentVote.objects.exists())
poll = AssignmentPoll.objects.get()
self.assertNotIn(self.admin.id, poll.voted.all())
def test_wrong_data_format(self):
self.start_poll()