From 409248d419aa0fbbc23fad4ec163c95fb59ebad5 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Thu, 15 Oct 2020 10:50:07 +0300 Subject: [PATCH] CollectionTypes: add backward compatibility adjustments until 2.0 is out. --- django_etebase/serializers.py | 3 ++- django_etebase/views.py | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/django_etebase/serializers.py b/django_etebase/serializers.py index 58ad10c..d753bf9 100644 --- a/django_etebase/serializers.py +++ b/django_etebase/serializers.py @@ -273,7 +273,8 @@ class CollectionListMultiSerializer(BetterErrorsMixin, serializers.Serializer): class CollectionSerializer(BetterErrorsMixin, serializers.ModelSerializer): collectionKey = CollectionEncryptionKeyField() - collectionType = CollectionTypeField() + # FIXME: make required once "collection-type-migration" is done + collectionType = CollectionTypeField(required=False) accessLevel = serializers.SerializerMethodField('get_access_level_from_context') stoken = serializers.CharField(read_only=True) diff --git a/django_etebase/views.py b/django_etebase/views.py index 34f6254..5328c84 100644 --- a/django_etebase/views.py +++ b/django_etebase/views.py @@ -18,7 +18,7 @@ from django.conf import settings from django.contrib.auth import get_user_model, user_logged_in, user_logged_out from django.core.exceptions import PermissionDenied from django.db import transaction, IntegrityError -from django.db.models import Max, Value as V +from django.db.models import Max, Value as V, Q from django.db.models.functions import Coalesce, Greatest from django.http import HttpResponseBadRequest, HttpResponse, Http404 from django.shortcuts import get_object_or_404 @@ -221,7 +221,9 @@ class CollectionViewSet(BaseViewSet): collection_types = serializer.validated_data['collectionTypes'] queryset = self.get_queryset() - queryset = queryset.filter(members__collectionType__uid__in=collection_types) + # FIXME: Remove the isnull part once "collection-type-migration" is done + queryset = queryset.filter( + Q(members__collectionType__uid__in=collection_types) | Q(members__collectionType__isnull=True)) return self.list_common(request, queryset, *args, **kwargs)