Fixed groups metadata view. Upgraded to djangorestframework 3.4.x. Fixed #2275.

This commit is contained in:
Norman Jäckel 2016-08-29 17:05:06 +02:00
parent 9fdc050048
commit ac6d78b0ee
3 changed files with 25 additions and 3 deletions

View File

@ -1,6 +1,7 @@
from django.contrib.auth import login as auth_login from django.contrib.auth import login as auth_login
from django.contrib.auth import logout as auth_logout from django.contrib.auth import logout as auth_logout
from django.contrib.auth.forms import AuthenticationForm 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 as _
from django.utils.translation import ugettext_lazy from django.utils.translation import ugettext_lazy
@ -177,8 +178,13 @@ class GroupViewSetMetadata(SimpleMetadata):
""" """
field_info = super().get_field_info(field) field_info = super().get_field_info(field)
if field.field_name == 'permissions': if field.field_name == 'permissions':
for choice in field_info['choices']: field_info['choices'] = [
choice['display_name'] = choice['display_name'].split(' | ')[2] {
'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 return field_info

View File

@ -2,7 +2,7 @@
Django>=1.9,<1.11,!=1.10.0 Django>=1.9,<1.11,!=1.10.0
beautifulsoup4>=4.5,<4.6 beautifulsoup4>=4.5,<4.6
channels>=0.15,<1.0 channels>=0.15,<1.0
djangorestframework>=3.2.0,<3.4 djangorestframework>=3.4,<3.5
html5lib>=0.99,<1.0 html5lib>=0.99,<1.0
jsonfield>=0.9.19,<1.1 jsonfield>=0.9.19,<1.1
natsort>=3.2,<5.1 natsort>=3.2,<5.1

View File

@ -185,6 +185,22 @@ class UserResetPassword(TestCase):
'new_password_Yuuh8OoQueePahngohy3')) '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): class GroupReceive(TestCase):
def test_get_groups_as_anonymous_deactivated(self): def test_get_groups_as_anonymous_deactivated(self):
""" """