[PATCH 09/10] REST: Add missing 'url' parameter for comments
Stephen Finucane
stephen at that.guru
Sat Oct 1 02:19:20 AEST 2022
This should be present on all resources.
Signed-off-by: Stephen Finucane <stephen at that.guru>
Fixes: 88f56051 ("api: add comments detail endpoint")
---
docs/api/schemas/latest/patchwork.yaml | 5 +++++
docs/api/schemas/patchwork.j2 | 9 +++++++++
docs/api/schemas/v1.0/patchwork.yaml | 5 -----
docs/api/schemas/v1.1/patchwork.yaml | 5 -----
docs/api/schemas/v1.2/patchwork.yaml | 5 -----
docs/api/schemas/v1.3/patchwork.yaml | 5 +++++
patchwork/api/base.py | 14 ++++++--------
patchwork/api/bundle.py | 2 +-
patchwork/api/comment.py | 24 ++++++++++++++++++++++--
patchwork/api/embedded.py | 2 ++
patchwork/api/patch.py | 1 +
11 files changed, 51 insertions(+), 26 deletions(-)
diff --git docs/api/schemas/latest/patchwork.yaml docs/api/schemas/latest/patchwork.yaml
index 3a1fdd3a..b3de0db5 100644
--- docs/api/schemas/latest/patchwork.yaml
+++ docs/api/schemas/latest/patchwork.yaml
@@ -1627,6 +1627,11 @@ components:
title: ID
type: integer
readOnly: true
+ url:
+ title: URL
+ type: string
+ format: uri
+ readOnly: true
web_url:
title: Web URL
type: string
diff --git docs/api/schemas/patchwork.j2 docs/api/schemas/patchwork.j2
index b9786654..68655348 100644
--- docs/api/schemas/patchwork.j2
+++ docs/api/schemas/patchwork.j2
@@ -1683,6 +1683,13 @@ components:
title: ID
type: integer
readOnly: true
+{% if version >= (1, 3) %}
+ url:
+ title: URL
+ type: string
+ format: uri
+ readOnly: true
+{% endif %}
{% if version >= (1, 1) %}
web_url:
title: Web URL
@@ -2528,11 +2535,13 @@ components:
title: ID
type: integer
readOnly: true
+{% if version >= (1, 3) %}
url:
title: URL
type: string
format: uri
readOnly: true
+{% endif %}
{% if version >= (1, 1) %}
web_url:
title: Web URL
diff --git docs/api/schemas/v1.0/patchwork.yaml docs/api/schemas/v1.0/patchwork.yaml
index 817b2f2a..6c3893ec 100644
--- docs/api/schemas/v1.0/patchwork.yaml
+++ docs/api/schemas/v1.0/patchwork.yaml
@@ -1993,11 +1993,6 @@ components:
title: ID
type: integer
readOnly: true
- url:
- title: URL
- type: string
- format: uri
- readOnly: true
msgid:
title: Message ID
type: string
diff --git docs/api/schemas/v1.1/patchwork.yaml docs/api/schemas/v1.1/patchwork.yaml
index 574a8ad8..7e2299c5 100644
--- docs/api/schemas/v1.1/patchwork.yaml
+++ docs/api/schemas/v1.1/patchwork.yaml
@@ -2044,11 +2044,6 @@ components:
title: ID
type: integer
readOnly: true
- url:
- title: URL
- type: string
- format: uri
- readOnly: true
web_url:
title: Web URL
type: string
diff --git docs/api/schemas/v1.2/patchwork.yaml docs/api/schemas/v1.2/patchwork.yaml
index 7a4e8e8e..93c3e97e 100644
--- docs/api/schemas/v1.2/patchwork.yaml
+++ docs/api/schemas/v1.2/patchwork.yaml
@@ -2287,11 +2287,6 @@ components:
title: ID
type: integer
readOnly: true
- url:
- title: URL
- type: string
- format: uri
- readOnly: true
web_url:
title: Web URL
type: string
diff --git docs/api/schemas/v1.3/patchwork.yaml docs/api/schemas/v1.3/patchwork.yaml
index 6bd0419d..8663406d 100644
--- docs/api/schemas/v1.3/patchwork.yaml
+++ docs/api/schemas/v1.3/patchwork.yaml
@@ -1627,6 +1627,11 @@ components:
title: ID
type: integer
readOnly: true
+ url:
+ title: URL
+ type: string
+ format: uri
+ readOnly: true
web_url:
title: Web URL
type: string
diff --git patchwork/api/base.py patchwork/api/base.py
index 0f5c44a2..16e5cb8d 100644
--- patchwork/api/base.py
+++ patchwork/api/base.py
@@ -151,19 +151,17 @@ class NestedHyperlinkedIdentityField(HyperlinkedIdentityField):
class BaseHyperlinkedModelSerializer(HyperlinkedModelSerializer):
def to_representation(self, instance):
- data = super(BaseHyperlinkedModelSerializer, self).to_representation(
- instance
- )
-
request = self.context.get('request')
for version in getattr(self.Meta, 'versioned_fields', {}):
# if the user has requested a version lower that than in which the
# field was added, we drop it
if not utils.has_version(request, version):
for field in self.Meta.versioned_fields[version]:
- # After a PATCH with an older API version, we may not see
- # these fields. If they don't exist, don't panic, return
- # (and then discard) None.
- data.pop(field, None)
+ if field in self.fields:
+ del self.fields[field]
+
+ data = super(BaseHyperlinkedModelSerializer, self).to_representation(
+ instance
+ )
return data
diff --git patchwork/api/bundle.py patchwork/api/bundle.py
index b6c7c9d2..134b2724 100644
--- patchwork/api/bundle.py
+++ patchwork/api/bundle.py
@@ -99,7 +99,7 @@ class BundleSerializer(BaseHyperlinkedModelSerializer):
if len(set([p.project.id for p in value])) > 1:
raise ValidationError(
- 'Bundle patches must belong to the same ' 'project'
+ 'Bundle patches must belong to the same project'
)
return value
diff --git patchwork/api/comment.py patchwork/api/comment.py
index 13c116ee..eae83719 100644
--- patchwork/api/comment.py
+++ patchwork/api/comment.py
@@ -12,6 +12,7 @@ from rest_framework.serializers import HiddenField
from rest_framework.serializers import SerializerMethodField
from patchwork.api.base import BaseHyperlinkedModelSerializer
+from patchwork.api.base import NestedHyperlinkedIdentityField
from patchwork.api.base import MultipleFieldLookupMixin
from patchwork.api.base import PatchworkPermission
from patchwork.api.base import CurrentCoverDefault
@@ -58,6 +59,7 @@ class BaseCommentListSerializer(BaseHyperlinkedModelSerializer):
class Meta:
fields = (
'id',
+ 'url',
'web_url',
'msgid',
'list_archive_url',
@@ -70,6 +72,7 @@ class BaseCommentListSerializer(BaseHyperlinkedModelSerializer):
)
read_only_fields = (
'id',
+ 'url',
'web_url',
'msgid',
'list_archive_url',
@@ -82,17 +85,27 @@ class BaseCommentListSerializer(BaseHyperlinkedModelSerializer):
versioned_fields = {
'1.1': ('web_url',),
'1.2': ('list_archive_url',),
- '1.3': ('addressed',),
+ '1.3': (
+ 'addressed',
+ 'url',
+ ),
}
class CoverCommentSerializer(BaseCommentListSerializer):
+ url = NestedHyperlinkedIdentityField(
+ 'api-cover-comment-detail',
+ lookup_field_mapping={
+ 'cover_id': 'cover_id',
+ 'comment_id': 'id',
+ },
+ )
cover = HiddenField(default=CurrentCoverDefault())
class Meta:
model = CoverComment
- fields = BaseCommentListSerializer.Meta.fields + ('cover', 'addressed')
+ fields = BaseCommentListSerializer.Meta.fields + ('cover',)
read_only_fields = BaseCommentListSerializer.Meta.read_only_fields + (
'cover',
)
@@ -123,6 +136,13 @@ class CoverCommentMixin(object):
class PatchCommentSerializer(BaseCommentListSerializer):
+ url = NestedHyperlinkedIdentityField(
+ 'api-patch-comment-detail',
+ lookup_field_mapping={
+ 'patch_id': 'patch_id',
+ 'comment_id': 'id',
+ },
+ )
patch = HiddenField(default=CurrentPatchDefault())
class Meta:
diff --git patchwork/api/embedded.py patchwork/api/embedded.py
index 4cfdf8e6..52018435 100644
--- patchwork/api/embedded.py
+++ patchwork/api/embedded.py
@@ -163,6 +163,7 @@ class CoverCommentSerializer(SerializedRelatedField):
'mbox',
),
'1.2': ('list_archive_url',),
+ '1.3': ('url',),
}
extra_kwargs = {
'url': {'view_name': 'api-cover-comment-detail'},
@@ -225,6 +226,7 @@ class PatchCommentSerializer(SerializedRelatedField):
'mbox',
),
'1.2': ('list_archive_url',),
+ '1.3': ('url',),
}
extra_kwargs = {
'url': {'view_name': 'api-patch-comment-detail'},
diff --git patchwork/api/patch.py patchwork/api/patch.py
index 9fd10e06..34067611 100644
--- patchwork/api/patch.py
+++ patchwork/api/patch.py
@@ -180,6 +180,7 @@ class PatchListSerializer(BaseHyperlinkedModelSerializer):
'related',
)
read_only_fields = (
+ 'url',
'web_url',
'project',
'msgid',
--
2.37.3
More information about the Patchwork
mailing list