From d739d401c4a1ab30690a701b3660be819c513c3f Mon Sep 17 00:00:00 2001 From: Finn Stutzenstein Date: Mon, 7 Sep 2020 08:22:17 +0200 Subject: [PATCH] Add a transaction to speaker handling to prevent adding a users multiple times to the waiting queue of a list of speakers --- .gitignore | 1 + server/openslides/agenda/views.py | 1 + server/tests/unit/agenda/test_views.py | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/.gitignore b/.gitignore index cf1a6e29b..ab93184bc 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ server/.venv # OS4-Submodules /openslides-*/ /haproxy/ +/docker/keys/ # Plugin development openslides_* # Old OS3 stuff diff --git a/server/openslides/agenda/views.py b/server/openslides/agenda/views.py index 017415d9b..f35b430ca 100644 --- a/server/openslides/agenda/views.py +++ b/server/openslides/agenda/views.py @@ -306,6 +306,7 @@ class ListOfSpeakersViewSet( return result @detail_route(methods=["POST", "PATCH", "DELETE"]) + @transaction.atomic def manage_speaker(self, request, pk=None): """ Special view endpoint to add users to the list of speakers or remove diff --git a/server/tests/unit/agenda/test_views.py b/server/tests/unit/agenda/test_views.py index 31805f16c..ae1e1bc22 100644 --- a/server/tests/unit/agenda/test_views.py +++ b/server/tests/unit/agenda/test_views.py @@ -1,6 +1,8 @@ from unittest import TestCase from unittest.mock import MagicMock, patch +import pytest + from openslides.agenda.views import ListOfSpeakersViewSet @@ -19,6 +21,7 @@ class ListOfSpeakersViewSetManageSpeaker(TestCase): @patch("openslides.agenda.views.inform_changed_data") @patch("openslides.agenda.views.has_perm") @patch("openslides.agenda.views.Speaker") + @pytest.mark.django_db(transaction=False) def test_add_oneself_as_speaker(self, mock_speaker, mock_has_perm, mock_icd): self.request.method = "POST" self.request.user = 1 @@ -36,6 +39,7 @@ class ListOfSpeakersViewSetManageSpeaker(TestCase): @patch("openslides.agenda.views.has_perm") @patch("openslides.agenda.views.get_user_model") @patch("openslides.agenda.views.Speaker") + @pytest.mark.django_db(transaction=False) def test_add_someone_else_as_speaker( self, mock_speaker, mock_get_user_model, mock_has_perm, mock_icd ): @@ -56,6 +60,7 @@ class ListOfSpeakersViewSetManageSpeaker(TestCase): ) @patch("openslides.agenda.views.Speaker") + @pytest.mark.django_db(transaction=False) def test_remove_oneself(self, mock_speaker): self.request.method = "DELETE" self.request.data = {} @@ -66,6 +71,7 @@ class ListOfSpeakersViewSetManageSpeaker(TestCase): @patch("openslides.agenda.views.inform_changed_data") @patch("openslides.agenda.views.has_perm") @patch("openslides.agenda.views.Speaker") + @pytest.mark.django_db(transaction=False) def test_remove_someone_else( self, mock_speaker, mock_has_perm, mock_inform_changed_data ):