From 9388f3b810ae23508d727f445ace407192a2c55c Mon Sep 17 00:00:00 2001 From: Anne Haley Date: Mon, 30 Sep 2024 22:47:47 +0000 Subject: [PATCH] fix: update setting permissions in Project `partial_update` --- uvdat/core/rest/project.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/uvdat/core/rest/project.py b/uvdat/core/rest/project.py index 81487827..e2589708 100644 --- a/uvdat/core/rest/project.py +++ b/uvdat/core/rest/project.py @@ -25,17 +25,16 @@ def perform_create(self, serializer): def partial_update(self, request, id): project = self.get_object() dataset_ids = request.data.pop('dataset_ids', None) - owner_id = request.data.pop('owner', None) - collaborator_ids = request.data.pop('collaborators', None) - follower_ids = request.data.pop('followers', None) if dataset_ids is not None: project.datasets.set(Dataset.objects.filter(id__in=dataset_ids)) - if owner_id is not None: - project.owner = User.objects.get(id=owner_id) - if collaborator_ids is not None: - project.collaborators.set(User.objects.filter(id__in=collaborator_ids)) - if follower_ids is not None: - project.followers.set(User.objects.filter(id__in=follower_ids)) + owner_id = request.data.pop('owner', None) + collaborator_ids = request.data.pop('collaborators', []) + follower_ids = request.data.pop('followers', []) + project.set_permissions( + owner=User.objects.filter(id=owner_id), + collaborator=User.objects.filter(id__in=collaborator_ids), + follower=User.objects.filter(id__in=follower_ids), + ) serializer = ProjectSerializer(project, data=request.data, partial=True) if serializer.is_valid(): serializer.save()