diff --git a/openslides/motions/views.py b/openslides/motions/views.py index 0d1ef4987..8b5e5fc78 100644 --- a/openslides/motions/views.py +++ b/openslides/motions/views.py @@ -1123,9 +1123,18 @@ class MotionPollViewSet(BasePollViewSet): Returns True if the user has required permissions. """ return has_perm(self.request.user, "motions.can_see") and has_perm( - self.request.user, "motions.can_manage_metadata" + self.request.user, "motions.can_manage" ) + def create(self, request, *args, **kwargs): + # set default pollmethod to YNA + if "pollmethod" not in request.data: + # hack to make request.data mutable. Otherwise fields cannot be changed. + if isinstance(request.data, QueryDict): + request.data._mutable = True + request.data["pollmethod"] = MotionPoll.POLLMETHOD_YNA + return super().create(request, *args, **kwargs) + def perform_create(self, serializer): motion = serializer.validated_data["motion"] if not motion.state.allow_create_poll: diff --git a/tests/integration/motions/test_polls.py b/tests/integration/motions/test_polls.py index 7971efb74..c0da78417 100644 --- a/tests/integration/motions/test_polls.py +++ b/tests/integration/motions/test_polls.py @@ -106,6 +106,22 @@ class CreateMotionPoll(TestCase): self.assertEqual(poll.motion.id, self.motion.id) self.assertTrue(poll.options.exists()) + def test_default_method(self): + response = self.client.post( + reverse("motionpoll-list"), + { + "title": "test_title_ailai4toogh3eefaa2Vo", + "type": "named", + "motion_id": self.motion.id, + "onehundred_percent_base": "YN", + "majority_method": "simple", + }, + ) + self.assertHttpStatusVerbose(response, status.HTTP_201_CREATED) + self.assertTrue(MotionPoll.objects.exists()) + poll = MotionPoll.objects.get() + self.assertEqual(poll.pollmethod, "YNA") + def test_autoupdate(self): response = self.client.post( reverse("motionpoll-list"), @@ -147,7 +163,6 @@ class CreateMotionPoll(TestCase): complete_request_data = { "title": "test_title_OoCh9aitaeyaeth8nom1", "type": "named", - "pollmethod": "YNA", "motion_id": self.motion.id, "onehundred_percent_base": "YN", "majority_method": "simple",