default motion poll method set, changed permission from 'can_manage_metadata' to 'can_manage'

This commit is contained in:
Joshua Sangmeister 2020-01-21 09:33:33 +01:00 committed by FinnStutzenstein
parent fff1f15b6c
commit e67ca77ad1
2 changed files with 26 additions and 2 deletions

View File

@ -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:

View File

@ -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",