From 87e3c536dac1cd563b5baa447ab152ed306efd76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Mon, 25 Jan 2016 14:48:00 +0100 Subject: [PATCH] Deleted Django default permission of some apps. Fixed #1643. --- openslides/core/apps.py | 11 ++++++++--- openslides/core/signals.py | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/openslides/core/apps.py b/openslides/core/apps.py index ac548c7bf..3889274b4 100644 --- a/openslides/core/apps.py +++ b/openslides/core/apps.py @@ -15,11 +15,11 @@ class CoreAppConfig(AppConfig): # Import all required stuff. from django.db.models import signals - from openslides.core.signals import config_signal + from openslides.core.signals import config_signal, post_permission_creation from openslides.utils.autoupdate import inform_changed_data_receiver from openslides.utils.rest_api import router from openslides.utils.search import index_add_instance, index_del_instance - from .signals import setup_general_config + from .signals import delete_django_app_permissions, setup_general_config from .views import ( ChatMessageViewSet, ConfigViewSet, @@ -29,7 +29,12 @@ class CoreAppConfig(AppConfig): ) # Connect signals. - config_signal.connect(setup_general_config, dispatch_uid='setup_general_config') + config_signal.connect( + setup_general_config, + dispatch_uid='setup_general_config') + post_permission_creation.connect( + delete_django_app_permissions, + dispatch_uid='delete_django_app_permissions') # Register viewsets. router.register('core/projector', ProjectorViewSet) diff --git a/openslides/core/signals.py b/openslides/core/signals.py index d3abb968a..4dd295746 100644 --- a/openslides/core/signals.py +++ b/openslides/core/signals.py @@ -1,4 +1,7 @@ +from django.contrib.auth.models import Permission +from django.contrib.contenttypes.models import ContentType from django.core.validators import MaxLengthValidator +from django.db.models import Q from django.dispatch import Signal from django.utils.translation import ugettext as _ from django.utils.translation import ugettext_lazy @@ -11,6 +14,19 @@ from openslides.core.config import ConfigVariable post_permission_creation = Signal() +def delete_django_app_permissions(sender, **kwargs): + """ + Deletes the permissions, Django creates by default. Only required + for auth, contenttypes and sessions. + """ + contenttypes = ContentType.objects.filter( + Q(app_label='auth') | + Q(app_label='contenttypes') | + Q(app_label='sessions')) + for permission in Permission.objects.filter(content_type__in=contenttypes): + permission.delete() + + def setup_general_config(sender, **kwargs): """ Receiver function to setup general config variables for OpenSlides.