Skip to content

Commit 1552b7d

Browse files
committed
REST: Don't allow settings of some project fields
These should only be configurable by superusers as invalid configuration can break things. Signed-off-by: Stephen Finucane <stephen@that.guru> Closes: #217 (cherry picked from commit 530999b)
1 parent 7a69a77 commit 1552b7d

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

patchwork/api/project.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030

3131
class ProjectSerializer(BaseHyperlinkedModelSerializer):
3232

33-
link_name = CharField(max_length=255, source='linkname')
34-
list_id = CharField(max_length=255, source='listid')
35-
list_email = CharField(max_length=200, source='listemail')
33+
link_name = CharField(max_length=255, source='linkname', read_only=True)
34+
list_id = CharField(max_length=255, source='listid', read_only=True)
35+
list_email = CharField(max_length=200, source='listemail', read_only=True)
3636
maintainers = UserProfileSerializer(many=True, read_only=True,
3737
source='maintainer_project')
3838

@@ -41,7 +41,8 @@ class Meta:
4141
fields = ('id', 'url', 'name', 'link_name', 'list_id', 'list_email',
4242
'web_url', 'scm_url', 'webscm_url', 'maintainers',
4343
'subject_match')
44-
read_only_fields = ('name', 'maintainers', 'subject_match')
44+
read_only_fields = ('name', 'link_name', 'list_id', 'list_email',
45+
'maintainers', 'subject_match')
4546
versioned_fields = {
4647
'1.1': ('subject_match', ),
4748
}

patchwork/tests/api/test_project.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def test_create(self):
143143
def test_update(self):
144144
"""Ensure updates can be performed by maintainers."""
145145
project = create_project()
146-
data = {'linkname': 'TEST'}
146+
data = {'web_url': 'TEST'}
147147

148148
# an anonymous user
149149
resp = self.client.patch(self.api_url(project.id), data)
@@ -160,6 +160,15 @@ def test_update(self):
160160
self.client.force_authenticate(user=user)
161161
resp = self.client.patch(self.api_url(project.id), data)
162162
self.assertEqual(status.HTTP_200_OK, resp.status_code)
163+
self.assertEqual(resp.data['web_url'], 'TEST')
164+
165+
# ...with the exception of some read-only fields
166+
resp = self.client.patch(self.api_url(project.id), {
167+
'link_name': 'test'})
168+
# NOTE(stephenfin): This actually returns HTTP 200 due to
169+
# https://github.com/encode/django-rest-framework/issues/1655
170+
self.assertEqual(status.HTTP_200_OK, resp.status_code)
171+
self.assertNotEqual(resp.data['link_name'], 'test')
163172

164173
def test_delete(self):
165174
"""Ensure deletions are rejected."""
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
fixes:
3+
- |
4+
A project's ``list_email``, ``list_id`` and ``link_name`` fields can no
5+
longer be updated via the REST API. This is a superuser-only operation
6+
that, for now, should only be done via the admin interface.
7+
(`#217 <https://github.com/getpatchwork/patchwork/issues/217>`__)

0 commit comments

Comments
 (0)