From cc0049b55b49f188f8520030b30de3e114612825 Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Tue, 7 Mar 2017 10:23:24 +0100 Subject: [PATCH] Adding agenda/topics app, fixes user app --- openslides/agenda/apps.py | 5 +++++ openslides/agenda/signals.py | 15 +++++++++++++++ openslides/topics/apps.py | 7 +++++++ openslides/topics/signals.py | 14 ++++++++++++++ openslides/users/signals.py | 6 +++--- 5 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 openslides/topics/signals.py diff --git a/openslides/agenda/apps.py b/openslides/agenda/apps.py index e0123cfe9..2a7087bbd 100644 --- a/openslides/agenda/apps.py +++ b/openslides/agenda/apps.py @@ -17,9 +17,11 @@ class AgendaAppConfig(AppConfig): # Import all required stuff. from django.db.models.signals import pre_delete, post_save from openslides.core.config import config + from openslides.core.signals import permission_change from openslides.utils.rest_api import router from .config_variables import get_config_variables from .signals import ( + get_permission_change_data, listen_to_related_object_post_delete, listen_to_related_object_post_save) from .views import ItemViewSet @@ -34,6 +36,9 @@ class AgendaAppConfig(AppConfig): pre_delete.connect( listen_to_related_object_post_delete, dispatch_uid='listen_to_related_object_post_delete') + permission_change.connect( + get_permission_change_data, + dispatch_uid='agenda_get_permission_change_data') # Register viewsets. router.register(self.get_model('Item').get_collection_string(), ItemViewSet) diff --git a/openslides/agenda/signals.py b/openslides/agenda/signals.py index 83679a5d0..2e2064942 100644 --- a/openslides/agenda/signals.py +++ b/openslides/agenda/signals.py @@ -1,3 +1,4 @@ +from django.apps import apps from django.contrib.contenttypes.models import ContentType from openslides.utils.autoupdate import inform_changed_data @@ -36,3 +37,17 @@ def listen_to_related_object_post_delete(sender, instance, **kwargs): except Item.DoesNotExist: # Item does not exist so we do not have to delete it. pass + + +def get_permission_change_data(sender, permissions, **kwargs): + """ + Yields all necessary collections if 'agenda.can_see' or + 'agenda.can_see_hidden_items' permissions changes. + """ + agenda_app = apps.get_app_config(app_label='agenda') + for permission in permissions: + # There could be only one 'agenda.can_see' and then we want to return data. + if (permission.content_type.app_label == agenda_app.label + and permission.codename in ('can_see', 'can_see_hidden_items')): + yield from agenda_app.get_startup_elements() + break diff --git a/openslides/topics/apps.py b/openslides/topics/apps.py index f7f246288..a48165464 100644 --- a/openslides/topics/apps.py +++ b/openslides/topics/apps.py @@ -15,9 +15,16 @@ class TopicsAppConfig(AppConfig): from . import projector # noqa # Import all required stuff. + from openslides.core.signals import permission_change from ..utils.rest_api import router + from .signals import get_permission_change_data from .views import TopicViewSet + # Connect signals. + permission_change.connect( + get_permission_change_data, + dispatch_uid='topics_get_permission_change_data') + # Register viewsets. router.register(self.get_model('Topic').get_collection_string(), TopicViewSet) diff --git a/openslides/topics/signals.py b/openslides/topics/signals.py new file mode 100644 index 000000000..61b313021 --- /dev/null +++ b/openslides/topics/signals.py @@ -0,0 +1,14 @@ +from django.apps import apps + + +def get_permission_change_data(sender, permissions, **kwargs): + """ + Yields all necessary collections from the topics app if + 'agenda.can_see' permission changes, because topics are strongly + connected to the agenda items. + """ + topics_app = apps.get_app_config(app_label='topics') + for permission in permissions: + # There could be only one 'agenda.can_see' and then we want to return data. + if permission.content_type.app_label == 'agenda' and permission.codename == 'can_see': + yield from topics_app.get_startup_elements() diff --git a/openslides/users/signals.py b/openslides/users/signals.py index 157473780..155ca6197 100644 --- a/openslides/users/signals.py +++ b/openslides/users/signals.py @@ -8,12 +8,12 @@ from .models import Group, User def get_permission_change_data(sender, permissions=None, **kwargs): """ - Yields all necessary collections if 'users.can_see' permission changes. + Yields all necessary collections if 'users.can_see_name' permission changes. """ users_app = apps.get_app_config(app_label='users') for permission in permissions: - # There could be only one 'users.can_see' and then we want to return data. - if permission.content_type.app_label == users_app.label and permission.codename == 'can_see': + # There could be only one 'users.can_see_name' and then we want to return data. + if permission.content_type.app_label == users_app.label and permission.codename == 'can_see_name': yield from users_app.get_startup_elements()