Skip to content

Commit 7af9403

Browse files
committed
REST: Allow unsetting of delegate
While we recently fixed setting of this field via the API, we didn't resolve unsetting. Fix this now. Signed-off-by: Stephen Finucane <[email protected]> (cherry picked from commit 7be9958)
1 parent e1ae71a commit 7af9403

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

patchwork/api/patch.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class PatchListSerializer(BaseHyperlinkedModelSerializer):
8282
project = ProjectSerializer(read_only=True)
8383
state = StateField()
8484
submitter = PersonSerializer(read_only=True)
85-
delegate = UserSerializer()
85+
delegate = UserSerializer(allow_null=True)
8686
mbox = SerializerMethodField()
8787
series = SeriesSerializer(many=True, read_only=True)
8888
comments = SerializerMethodField()
@@ -116,6 +116,9 @@ def get_tags(self, instance):
116116

117117
def validate_delegate(self, value):
118118
"""Check that the delgate is a maintainer of the patch's project."""
119+
if not value:
120+
return value
121+
119122
if not self.instance.project.maintainer_project.filter(
120123
id=value.id).exists():
121124
raise ValidationError("User '%s' is not a maintainer for project "

patchwork/tests/api/test_patch.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,13 @@ def test_update(self):
224224
self.assertEqual(Patch.objects.get(id=patch.id).state, state)
225225
self.assertEqual(Patch.objects.get(id=patch.id).delegate, user)
226226

227+
# (who can unset fields too)
228+
# we need to send as JSON due to https://stackoverflow.com/q/30677216/
229+
resp = self.client.patch(self.api_url(patch.id), {'delegate': None},
230+
format='json')
231+
self.assertEqual(status.HTTP_200_OK, resp.status_code, resp)
232+
self.assertIsNone(Patch.objects.get(id=patch.id).delegate)
233+
227234
def test_update_invalid(self):
228235
"""Ensure we handle invalid Patch updates."""
229236
project = create_project()

0 commit comments

Comments
 (0)