From 118dbea4e34bbdfc06fec9b6b42d219a10369ce0 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Sun, 24 May 2020 17:52:09 +0300 Subject: [PATCH] InvitationSerializer: fix user validator. --- django_etesync/serializers.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/django_etesync/serializers.py b/django_etesync/serializers.py index 21ce6a4..95dbc1f 100644 --- a/django_etesync/serializers.py +++ b/django_etesync/serializers.py @@ -282,13 +282,16 @@ class CollectionInvitationSerializer(serializers.ModelSerializer): def get_from_pubkey(self, obj): return b64encode(obj.fromMember.user.userinfo.pubkey) - def create(self, validated_data): - collection = self.context['collection'] + def validate_user(self, value): request = self.context['request'] - if request.user == validated_data.get('user'): + if request.user == value: raise serializers.ValidationError('Inviting yourself is not allowed') + def create(self, validated_data): + collection = self.context['collection'] + request = self.context['request'] + member = collection.members.get(user=request.user) with transaction.atomic():