Merge pull request #3306 from FinnStutzenstein/Issue2862

Remove OPTION request to query permissions (fixes #2862)
This commit is contained in:
Norman Jäckel 2017-07-05 21:26:08 +02:00 committed by GitHub
commit 77a321894b
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)