From ac6d78b0ee975cc218ffa5a8efe279746f8e0b1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Mon, 29 Aug 2016 17:05:06 +0200 Subject: [PATCH] Fixed groups metadata view. Upgraded to djangorestframework 3.4.x. Fixed #2275. --- openslides/users/views.py | 10 ++++++++-- requirements_production.txt | 2 +- tests/integration/users/test_viewset.py | 16 ++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/openslides/users/views.py b/openslides/users/views.py index 625a323b2..c79a92bc4 100644 --- a/openslides/users/views.py +++ b/openslides/users/views.py @@ -1,6 +1,7 @@ from django.contrib.auth import login as auth_login from django.contrib.auth import logout as auth_logout from django.contrib.auth.forms import AuthenticationForm +from django.utils.encoding import force_text from django.utils.translation import ugettext as _ from django.utils.translation import ugettext_lazy @@ -177,8 +178,13 @@ class GroupViewSetMetadata(SimpleMetadata): """ field_info = super().get_field_info(field) if field.field_name == 'permissions': - for choice in field_info['choices']: - choice['display_name'] = choice['display_name'].split(' | ')[2] + field_info['choices'] = [ + { + 'value': choice_value, + 'display_name': force_text(choice_name, strings_only=True).split(' | ')[2] + } + for choice_value, choice_name in field.choices.items() + ] return field_info diff --git a/requirements_production.txt b/requirements_production.txt index 8b2c21b51..2a0a5b96b 100644 --- a/requirements_production.txt +++ b/requirements_production.txt @@ -2,7 +2,7 @@ Django>=1.9,<1.11,!=1.10.0 beautifulsoup4>=4.5,<4.6 channels>=0.15,<1.0 -djangorestframework>=3.2.0,<3.4 +djangorestframework>=3.4,<3.5 html5lib>=0.99,<1.0 jsonfield>=0.9.19,<1.1 natsort>=3.2,<5.1 diff --git a/tests/integration/users/test_viewset.py b/tests/integration/users/test_viewset.py index bf74eb58a..d563baf25 100644 --- a/tests/integration/users/test_viewset.py +++ b/tests/integration/users/test_viewset.py @@ -185,6 +185,22 @@ class UserResetPassword(TestCase): 'new_password_Yuuh8OoQueePahngohy3')) +class GroupMetadata(TestCase): + def test_options_request_as_anonymous_user_activated(self): + config['general_system_enable_anonymous'] = True + + response = self.client.options('/rest/users/group/') + + self.assertEqual(response.status_code, 200) + self.assertEqual(response.data['name'], 'Group List') + perm_list = response.data['actions']['POST']['permissions']['choices'] + self.assertEqual(type(perm_list), list) + for item in perm_list: + self.assertEqual(type(item), dict) + self.assertTrue(item.get('display_name') is not None) + self.assertTrue(item.get('value') is not None) + + class GroupReceive(TestCase): def test_get_groups_as_anonymous_deactivated(self): """