|
|
@ -268,18 +268,20 @@ class CollectionInvitationSerializer(serializers.ModelSerializer):
|
|
|
|
slug_field=User.USERNAME_FIELD,
|
|
|
|
slug_field=User.USERNAME_FIELD,
|
|
|
|
queryset=User.objects
|
|
|
|
queryset=User.objects
|
|
|
|
)
|
|
|
|
)
|
|
|
|
collection = serializers.SlugRelatedField(
|
|
|
|
collection = serializers.SerializerMethodField('get_collection')
|
|
|
|
source='fromMember__collection',
|
|
|
|
fromPubkey = serializers.SerializerMethodField('get_from_pubkey')
|
|
|
|
slug_field='uid',
|
|
|
|
|
|
|
|
read_only=True,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
fromPubkey = BinaryBase64Field(source='fromMember__user__userinfo__pubkey', read_only=True)
|
|
|
|
|
|
|
|
signedEncryptionKey = BinaryBase64Field()
|
|
|
|
signedEncryptionKey = BinaryBase64Field()
|
|
|
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
class Meta:
|
|
|
|
model = models.CollectionInvitation
|
|
|
|
model = models.CollectionInvitation
|
|
|
|
fields = ('username', 'uid', 'collection', 'signedEncryptionKey', 'accessLevel', 'fromPubkey', 'version')
|
|
|
|
fields = ('username', 'uid', 'collection', 'signedEncryptionKey', 'accessLevel', 'fromPubkey', 'version')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_collection(self, obj):
|
|
|
|
|
|
|
|
return obj.collection.uid
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_from_pubkey(self, obj):
|
|
|
|
|
|
|
|
return b64encode(obj.fromMember.user.userinfo.pubkey)
|
|
|
|
|
|
|
|
|
|
|
|
def create(self, validated_data):
|
|
|
|
def create(self, validated_data):
|
|
|
|
collection = self.context['collection']
|
|
|
|
collection = self.context['collection']
|
|
|
|
request = self.context['request']
|
|
|
|
request = self.context['request']
|
|
|
@ -301,6 +303,30 @@ class CollectionInvitationSerializer(serializers.ModelSerializer):
|
|
|
|
return instance
|
|
|
|
return instance
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class InvitationAcceptSerializer(serializers.Serializer):
|
|
|
|
|
|
|
|
encryptionKey = BinaryBase64Field()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create(self, validated_data):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with transaction.atomic():
|
|
|
|
|
|
|
|
invitation = self.context['invitation']
|
|
|
|
|
|
|
|
encryption_key = validated_data.get('encryptionKey')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
member = models.CollectionMember.objects.create(
|
|
|
|
|
|
|
|
collection=invitation.collection,
|
|
|
|
|
|
|
|
user=invitation.user,
|
|
|
|
|
|
|
|
accessLevel=invitation.accessLevel,
|
|
|
|
|
|
|
|
encryptionKey=encryption_key,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
invitation.delete()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return member
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update(self, instance, validated_data):
|
|
|
|
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UserSerializer(serializers.ModelSerializer):
|
|
|
|
class UserSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
class Meta:
|
|
|
|
model = User
|
|
|
|
model = User
|
|
|
|