From 3eb79e0a04444f3b3ec5b3e4110a1b9910299c81 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Wed, 26 Feb 2020 20:42:28 +0200 Subject: [PATCH] Create collection member when creating collection. --- django_etesync/views.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/django_etesync/views.py b/django_etesync/views.py index 3d27e72..60e79a6 100644 --- a/django_etesync/views.py +++ b/django_etesync/views.py @@ -24,7 +24,7 @@ from rest_framework.decorators import action as action_decorator from rest_framework.response import Response from . import app_settings, paginators -from .models import Collection, CollectionItem +from .models import Collection, CollectionItem, CollectionMember from .serializers import ( CollectionSerializer, CollectionItemSerializer, @@ -73,7 +73,12 @@ class CollectionViewSet(BaseViewSet): if serializer.is_valid(): try: with transaction.atomic(): - serializer.save(owner=self.request.user) + col = serializer.save(owner=self.request.user) + CollectionMember(collection=col, + user=self.request.user, + accessLevel=CollectionMember.AccessLevels.ADMIN, + encryptionKey=serializer.validated_data['encryptionKey'] + ).save() except IntegrityError: content = {'code': 'integrity_error'} return Response(content, status=status.HTTP_400_BAD_REQUEST)