mirror of
https://github.com/etesync/server
synced 2024-11-25 18:28:46 +00:00
Collection: fix issue with encryptionKey not being base64 encoded.
This commit is contained in:
parent
3eb79e0a04
commit
7a38e26872
@ -30,8 +30,16 @@ class BinaryBase64Field(serializers.Field):
|
|||||||
return base64.b64decode(data)
|
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):
|
class CollectionSerializer(serializers.ModelSerializer):
|
||||||
encryptionKey = serializers.SerializerMethodField('get_key_from_context')
|
encryptionKey = CollectionEncryptionKeyField()
|
||||||
accessLevel = serializers.SerializerMethodField('get_access_level_from_context')
|
accessLevel = serializers.SerializerMethodField('get_access_level_from_context')
|
||||||
ctag = serializers.SerializerMethodField('get_ctag')
|
ctag = serializers.SerializerMethodField('get_ctag')
|
||||||
|
|
||||||
@ -39,12 +47,6 @@ class CollectionSerializer(serializers.ModelSerializer):
|
|||||||
model = models.Collection
|
model = models.Collection
|
||||||
fields = ('uid', 'version', 'accessLevel', 'encryptionKey', 'ctag')
|
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):
|
def get_access_level_from_context(self, obj):
|
||||||
request = self.context.get('request', None)
|
request = self.context.get('request', None)
|
||||||
if request is not None:
|
if request is not None:
|
||||||
|
Loading…
Reference in New Issue
Block a user