]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
REST: Allow unsetting of delegate
authorStephen Finucane <stephen@that.guru>
Sun, 14 Oct 2018 14:29:47 +0000 (15:29 +0100)
committerStephen Finucane <stephen@that.guru>
Sun, 14 Oct 2018 14:33:06 +0000 (15:33 +0100)
While we recently fixed setting of this field via the API, we didn't
resolve unsetting. Fix this now.

Signed-off-by: Stephen Finucane <stephen@that.guru>
(cherry picked from commit 7be99581f1d1b35274987e43ec57272daff94f02)

patchwork/api/patch.py
patchwork/tests/api/test_patch.py

index 6b5cc0d1a789e6684af29a70521c8006b04b56b0..7b8e12e39fe2d480a51aba3b42e0ea7a702ba195 100644 (file)
@@ -82,7 +82,7 @@ class PatchListSerializer(BaseHyperlinkedModelSerializer):
     project = ProjectSerializer(read_only=True)
     state = StateField()
     submitter = PersonSerializer(read_only=True)
-    delegate = UserSerializer()
+    delegate = UserSerializer(allow_null=True)
     mbox = SerializerMethodField()
     series = SeriesSerializer(many=True, read_only=True)
     comments = SerializerMethodField()
@@ -116,6 +116,9 @@ class PatchListSerializer(BaseHyperlinkedModelSerializer):
 
     def validate_delegate(self, value):
         """Check that the delgate is a maintainer of the patch's project."""
+        if not value:
+            return value
+
         if not self.instance.project.maintainer_project.filter(
                 id=value.id).exists():
             raise ValidationError("User '%s' is not a maintainer for project "
index 017707149fe267de478a3fbf676f30996503672c..6a8df512ee454916262e2294855d26aa18c05d8d 100644 (file)
@@ -224,6 +224,13 @@ class TestPatchAPI(APITestCase):
         self.assertEqual(Patch.objects.get(id=patch.id).state, state)
         self.assertEqual(Patch.objects.get(id=patch.id).delegate, user)
 
+        # (who can unset fields too)
+        # we need to send as JSON due to https://stackoverflow.com/q/30677216/
+        resp = self.client.patch(self.api_url(patch.id), {'delegate': None},
+                                 format='json')
+        self.assertEqual(status.HTTP_200_OK, resp.status_code, resp)
+        self.assertIsNone(Patch.objects.get(id=patch.id).delegate)
+
     def test_update_invalid(self):
         """Ensure we handle invalid Patch updates."""
         project = create_project()