Merge pull request #1888 from normanjaeckel/DefaultPerms

Deleted Django default permission of some apps. Fixed #1643.
This commit is contained in:
Oskar Hahn 2016-01-25 21:16:35 +01:00
commit 41c43a7b31
2 changed files with 24 additions and 3 deletions

View File

@ -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)

View File

@ -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.