From 7a97aa1b79cbf8e0d8fe5ed15a1f1a835f1f8fbd Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Tue, 7 Apr 2020 09:53:16 +0200 Subject: [PATCH] Cleanup for #5300 --- openslides/motions/views.py | 22 ++++++++++------------ openslides/poll/views.py | 4 +++- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/openslides/motions/views.py b/openslides/motions/views.py index 857060b95..8f9189e18 100644 --- a/openslides/motions/views.py +++ b/openslides/motions/views.py @@ -1176,10 +1176,6 @@ class MotionPollViewSet(BasePollViewSet): return result - def add_user_to_voted_array(self, user, poll): - VotedModel = MotionPoll.voted.through - VotedModel.objects.create(motionpoll=poll, user=user) - def handle_analog_vote(self, data, poll, user): option = poll.options.get() vote, _ = MotionVote.objects.get_or_create(option=option, value="Y") @@ -1226,19 +1222,21 @@ class MotionPollViewSet(BasePollViewSet): elif poll.pollmethod == MotionPoll.POLLMETHOD_YN and data not in ("Y", "N"): raise ValidationError("Data must be Y or N") + def add_user_to_voted_array(self, user, poll): + VotedModel = MotionPoll.voted.through + VotedModel.objects.create(motionpoll=poll, user=user) + def handle_named_vote(self, data, poll, user): - option = poll.options.get() - vote = MotionVote.objects.create(user=user, option=option) - self.handle_named_and_pseudoanonymous_vote(data, user, poll, option, vote) + self.handle_named_and_pseudoanonymous_vote(data, user.vote_weight, user, poll) def handle_pseudoanonymous_vote(self, data, poll, user): - option = poll.options.get() - vote = MotionVote.objects.create(user=None, option=option) - self.handle_named_and_pseudoanonymous_vote(data, user, poll, option, vote) + self.handle_named_and_pseudoanonymous_vote(data, user.vote_weight, None, poll) - def handle_named_and_pseudoanonymous_vote(self, data, user, poll, option, vote): + def handle_named_and_pseudoanonymous_vote(self, data, weight, user, poll): + option = poll.options.get() + vote = MotionVote.objects.create(user=user, option=option) vote.value = data - vote.weight = user.vote_weight + vote.weight = weight vote.save(no_delete_on_restriction=True) inform_changed_data(option) diff --git a/openslides/poll/views.py b/openslides/poll/views.py index 0b27719ac..258544197 100644 --- a/openslides/poll/views.py +++ b/openslides/poll/views.py @@ -232,6 +232,7 @@ class BasePollViewSet(ModelViewSet): else: if poll.state != BasePoll.STATE_STARTED: raise ValidationError("You can only vote on a started poll.") + if not request.user.is_present or not in_some_groups( request.user.id, list(poll.groups.values_list("pk", flat=True)), @@ -268,7 +269,8 @@ class BasePollViewSet(ModelViewSet): def add_user_to_voted_array(self, user, poll): """ To be implemented by subclass. Adds the given user to the voted array of the given poll. - Throws an IntegrityError if the user already exists in the array + This operation should be atomic: If the user is already in the array, an IntegrityError must + be thrown, otherwise the user must be added. """ raise NotImplementedError()