Add a transaction to speaker handling

to prevent adding a users multiple times to the waiting queue of a list of speakers
This commit is contained in:
Finn Stutzenstein 2020-09-07 08:22:17 +02:00
parent b050a87bb2
commit d739d401c4
No known key found for this signature in database
GPG Key ID: 9042F605C6324654
3 changed files with 8 additions and 0 deletions

1
.gitignore vendored
View File

@ -26,6 +26,7 @@ server/.venv
# OS4-Submodules
/openslides-*/
/haproxy/
/docker/keys/
# Plugin development
openslides_*
# Old OS3 stuff

View File

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

View File

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