diff --git a/server/openslides/motions/views.py b/server/openslides/motions/views.py index e1ba80b9a..ff3895569 100644 --- a/server/openslides/motions/views.py +++ b/server/openslides/motions/views.py @@ -6,6 +6,7 @@ from django.contrib.auth import get_user_model from django.db import transaction from django.db.models import Case, When from django.db.models.deletion import ProtectedError +from django.db.utils import IntegrityError from django.http.request import QueryDict from rest_framework import status @@ -514,7 +515,10 @@ class MotionViewSet(TreeSortMixin, ModelViewSet): and not motion.is_supporter(request.user) ): raise ValidationError({"detail": "You can not support this motion."}) - motion.supporters.add(request.user) + try: + motion.supporters.add(request.user) + except IntegrityError: + raise ValidationError({"detail": "You are already a supporter."}) # Send new supporter via autoupdate because users without permission # to see users may not have it but can get it now. # TODO: Skip history. diff --git a/server/openslides/utils/models.py b/server/openslides/utils/models.py index 91a43107c..4ecc1ab12 100644 --- a/server/openslides/utils/models.py +++ b/server/openslides/utils/models.py @@ -6,6 +6,7 @@ from django.db import models from . import logging from .access_permissions import BaseAccessPermissions +from .auth import UserDoesNotExist from .autoupdate import AutoupdateElement, inform_changed_data, inform_elements from .rest_api import model_serializer_classes from .utils import convert_camel_case_to_pseudo_snake_case, get_element_id @@ -185,7 +186,12 @@ class RESTModelMixin: """ Converts a list of elements from full_data to restricted_data. """ - return await cls.get_access_permissions().get_restricted_data(elements, user_id) + try: + return await cls.get_access_permissions().get_restricted_data( + elements, user_id + ) + except UserDoesNotExist: + return [] def get_full_data(self) -> Dict[str, Any]: """