remove OPTION request to query permissions (fixes #2862)

This commit is contained in:
FinnStutzenstein 2017-06-21 14:27:22 +02:00
parent 573fc4da57
commit 90af3e6d1d
4 changed files with 27 additions and 21 deletions

View File

@ -45,3 +45,16 @@ class UsersAppConfig(AppConfig):
"""
for model in ('User', 'Group', 'PersonalNote'):
yield Collection(self.get_model(model).get_collection_string())
def get_angular_constants(self):
from django.contrib.auth.models import Permission
permissions = []
for permission in Permission.objects.all():
permissions.append({
'display_name': permission.name,
'value': '.'.join((permission.content_type.app_label, permission.codename,))})
permission_settings = {
'name': 'permissions',
'value': permissions}
return [permission_settings]

View File

@ -128,25 +128,12 @@ angular.module('OpenSlidesApp.users', [])
])
.factory('Group', [
'$http',
'DS',
function($http, DS) {
function(DS) {
var name = 'users/group';
var permissions;
return DS.defineResource({
name: name,
permissions: permissions,
// TODO (Issue 2862): Do not query the permissions from server. They should be included
// in the startup data. Then remove 'permission' injection from group list controller.
getPermissions: function() {
if (!this.permissions) {
this.permissions = $http({ 'method': 'OPTIONS', 'url': '/rest/users/group/' })
.then(function(result) {
return result.data.actions.POST.permissions.choices;
});
}
return this.permissions;
}
});
}
])

View File

@ -85,13 +85,7 @@ angular.module('OpenSlidesApp.users.site', [
title: gettext('Groups'),
},
})
.state('users.group.list', {
resolve: {
permissions: function(Group) {
return Group.getPermissions();
}
}
})
.state('users.group.list', {})
.state('login', {
template: null,
url: '/login',

View File

@ -164,3 +164,15 @@ class ProjectorAPI(TestCase):
self.viewset.request = request
self.viewset.clear_elements(request=request, pk=MagicMock())
self.assertEqual(len(mock_object.return_value.config), 1)
class WebclientJavaScriptView(TestCase):
def setUp(self):
self.request = MagicMock()
self.view_instance = views.WebclientJavaScriptView()
self.view_instance.request = self.request
@patch('django.contrib.auth.models.Permission.objects.all')
def test_permissions_as_constant(self, mock_all):
self.view_instance.get()
self.assertEqual(mock_all.call_count, 1)