From 90af3e6d1d1ecf055ab8aed58f1074a4c0ffdff0 Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Wed, 21 Jun 2017 14:27:22 +0200 Subject: [PATCH] remove OPTION request to query permissions (fixes #2862) --- openslides/users/apps.py | 13 +++++++++++++ openslides/users/static/js/users/base.js | 15 +-------------- openslides/users/static/js/users/site.js | 8 +------- tests/unit/core/test_views.py | 12 ++++++++++++ 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/openslides/users/apps.py b/openslides/users/apps.py index e4d7deb69..efaae509f 100644 --- a/openslides/users/apps.py +++ b/openslides/users/apps.py @@ -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] diff --git a/openslides/users/static/js/users/base.js b/openslides/users/static/js/users/base.js index 631ad08bf..eddde81c3 100644 --- a/openslides/users/static/js/users/base.js +++ b/openslides/users/static/js/users/base.js @@ -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; - } }); } ]) diff --git a/openslides/users/static/js/users/site.js b/openslides/users/static/js/users/site.js index f2ff2a77e..0ab0bcdcc 100644 --- a/openslides/users/static/js/users/site.js +++ b/openslides/users/static/js/users/site.js @@ -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', diff --git a/tests/unit/core/test_views.py b/tests/unit/core/test_views.py index 0d5dbd350..01fe96280 100644 --- a/tests/unit/core/test_views.py +++ b/tests/unit/core/test_views.py @@ -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)