Small fixes

This commit is contained in:
Finn Stutzenstein 2021-04-12 07:52:47 +02:00
parent feb54c52a3
commit a1e7920b34
No known key found for this signature in database
GPG Key ID: 9042F605C6324654
3 changed files with 30 additions and 13 deletions

@ -1 +1 @@
Subproject commit 4efec028f8d98d28fbe0f098b21108c53e04f4dd Subproject commit c1211219d81965b10780ecfa5a1de31f9e30d31e

View File

@ -106,6 +106,14 @@ class MediafileViewSet(ModelViewSet):
raise ValidationError({"detail": "You forgot to provide a file."}) raise ValidationError({"detail": "You forgot to provide a file."})
if mediafile: if mediafile:
# Still don't know, how this can happen. But catch it...
if isinstance(mediafile, str):
raise ValidationError(
{
"detail": "The upload was not successful. Please reach out for the support."
}
)
if mediafile.size > max_upload_size: if mediafile.size > max_upload_size:
max_size_for_humans = bytes_to_human(max_upload_size) max_size_for_humans = bytes_to_human(max_upload_size)
raise ValidationError( raise ValidationError(

View File

@ -31,13 +31,13 @@ from ..core.signals import permission_change
from ..utils.auth import ( from ..utils.auth import (
GROUP_ADMIN_PK, GROUP_ADMIN_PK,
GROUP_DEFAULT_PK, GROUP_DEFAULT_PK,
UserDoesNotExist,
anonymous_is_enabled, anonymous_is_enabled,
has_perm, has_perm,
) )
from ..utils.autoupdate import AutoupdateElement, inform_changed_data, inform_elements from ..utils.autoupdate import AutoupdateElement, inform_changed_data, inform_elements
from ..utils.cache import element_cache from ..utils.cache import element_cache
from ..utils.rest_api import ( from ..utils.rest_api import (
APIException,
ModelViewSet, ModelViewSet,
Response, Response,
SimpleMetadata, SimpleMetadata,
@ -193,7 +193,10 @@ class UserViewSet(ModelViewSet):
if "vote_delegated_from_users_id" in request.data: if "vote_delegated_from_users_id" in request.data:
del request.data["vote_delegated_from_users_id"] del request.data["vote_delegated_from_users_id"]
try:
response = super().update(request, *args, **kwargs) response = super().update(request, *args, **kwargs)
except IntegrityError as e:
raise ValidationError({"detail": str(e)})
# after rest of the request succeeded, handle delegation changes # after rest of the request succeeded, handle delegation changes
if isinstance(new_delegation_ids, list): if isinstance(new_delegation_ids, list):
@ -841,18 +844,24 @@ class WhoAmIDataView(APIView):
user_id = self.request.user.pk or 0 user_id = self.request.user.pk or 0
guest_enabled = anonymous_is_enabled() guest_enabled = anonymous_is_enabled()
auth_type = "default"
if user_id: if user_id:
try:
user_full_data = async_to_sync(element_cache.get_element_data)( user_full_data = async_to_sync(element_cache.get_element_data)(
self.request.user.get_collection_string(), user_id self.request.user.get_collection_string(), user_id
) )
if user_full_data is None: if user_full_data is None:
raise APIException(f"Could not find user {user_id}", 500) raise UserDoesNotExist()
auth_type = user_full_data["auth_type"] auth_type = user_full_data["auth_type"]
user_data = async_to_sync(restrict_user)(user_full_data) user_data = async_to_sync(restrict_user)(
user_full_data
) # This could also raise UserDoesNotExist
group_ids = user_data["groups_id"] or [GROUP_DEFAULT_PK] group_ids = user_data["groups_id"] or [GROUP_DEFAULT_PK]
else: except UserDoesNotExist:
user_id = None # continue as the anonymous user
if not user_id:
auth_type = "default"
user_data = None user_data = None
group_ids = [GROUP_DEFAULT_PK] if guest_enabled else [] group_ids = [GROUP_DEFAULT_PK] if guest_enabled else []