Merge pull request #5678 from jsangmeister/deactivate-empty-votes

Deactivate empty votes for assignment polls
This commit is contained in:
Emanuel Schütze 2020-11-05 22:23:04 +01:00 committed by GitHub
commit 85852d158a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 10 deletions

View File

@ -149,7 +149,7 @@
<ng-template #sendNow let-delegation="delegation"> <ng-template #sendNow let-delegation="delegation">
<div class="centered-button-wrapper"> <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> <mat-icon> how_to_vote </mat-icon>
<span> <span>
{{ 'Submit vote now' | translate }} {{ 'Submit vote now' | translate }}

View File

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

View File

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