From 7a38e26872a9d0094e056ebe67862be3867187a0 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Wed, 26 Feb 2020 20:54:00 +0200 Subject: [PATCH] Collection: fix issue with encryptionKey not being base64 encoded. --- django_etesync/serializers.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/django_etesync/serializers.py b/django_etesync/serializers.py index c194243..5a57900 100644 --- a/django_etesync/serializers.py +++ b/django_etesync/serializers.py @@ -30,8 +30,16 @@ class BinaryBase64Field(serializers.Field): return base64.b64decode(data) +class CollectionEncryptionKeyField(BinaryBase64Field): + def get_attribute(self, instance): + request = self.context.get('request', None) + if request is not None: + return instance.members.get(user=request.user).encryptionKey + return None + + class CollectionSerializer(serializers.ModelSerializer): - encryptionKey = serializers.SerializerMethodField('get_key_from_context') + encryptionKey = CollectionEncryptionKeyField() accessLevel = serializers.SerializerMethodField('get_access_level_from_context') ctag = serializers.SerializerMethodField('get_ctag') @@ -39,12 +47,6 @@ class CollectionSerializer(serializers.ModelSerializer): model = models.Collection fields = ('uid', 'version', 'accessLevel', 'encryptionKey', 'ctag') - def get_key_from_context(self, obj): - request = self.context.get('request', None) - if request is not None: - return obj.members.get(user=request.user).encryptionKey - return None - def get_access_level_from_context(self, obj): request = self.context.get('request', None) if request is not None: