From 7d455b34f5babada3e0c7f2314a01d2fc879ec58 Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Wed, 10 Jun 2020 08:44:26 +0200 Subject: [PATCH] Fix the creation of saml users When created, they are put into the cache. Also allows bulk-delete for saml users. --- .gitignore | 1 + openslides/saml/views.py | 3 +++ openslides/users/views.py | 17 ++++++++--------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 9f2130d4c..a3d015171 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,7 @@ dist/* debug/* .DS_Store .idea +*.code-workspace # Unit test and coverage reports .coverage diff --git a/openslides/saml/views.py b/openslides/saml/views.py index e57068055..9be2408a6 100644 --- a/openslides/saml/views.py +++ b/openslides/saml/views.py @@ -12,6 +12,8 @@ from onelogin.saml2.auth import OneLogin_Saml2_Auth from onelogin.saml2.errors import OneLogin_Saml2_Error from onelogin.saml2.utils import OneLogin_Saml2_Utils +from openslides.utils.autoupdate import inform_changed_data + from .settings import get_saml_settings @@ -141,6 +143,7 @@ class SamlView(View): logger.info( f"Created new saml user with id {user.id} and username {user.username}" ) + inform_changed_data(user) # put the new user into the cache else: logger.info( f"Found saml user with id {user.id} and username {user.username}" diff --git a/openslides/users/views.py b/openslides/users/views.py index 99884401f..b12dcf723 100644 --- a/openslides/users/views.py +++ b/openslides/users/views.py @@ -322,22 +322,21 @@ class UserViewSet(ModelViewSet): self.assert_list_of_ints(ids) # Exclude the request user - users = self.bulk_get_users(request, ids) + users = self.bulk_get_users(request, ids, auth_type=None) for user in list(users): user.delete() return Response(status=status.HTTP_204_NO_CONTENT) - def bulk_get_users(self, request, ids): + def bulk_get_users(self, request, ids, auth_type="default"): """ - Get all users for the given ids. Exludes the request user and all - users with a non-default auth_type. + Get all users for the given ids. Exludes the request user. + If the auth type is given (so it is not None), only these users are included. """ - return ( - User.objects.filter(auth_type="default") - .exclude(pk=request.user.id) - .filter(pk__in=ids) - ) + queryset = User.objects + if auth_type is not None: + queryset = queryset.filter(auth_type=auth_type) + return queryset.exclude(pk=request.user.id).filter(pk__in=ids) @list_route(methods=["post"]) @transaction.atomic