]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
REST: Add missing 'url' parameter for comments
authorStephen Finucane <stephen@that.guru>
Fri, 30 Sep 2022 14:01:14 +0000 (15:01 +0100)
committerStephen Finucane <stephen@that.guru>
Fri, 30 Sep 2022 16:38:54 +0000 (17:38 +0100)
This should be present on all resources.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Fixes: 88f56051 ("api: add comments detail endpoint")
docs/api/schemas/latest/patchwork.yaml
docs/api/schemas/patchwork.j2
docs/api/schemas/v1.0/patchwork.yaml
docs/api/schemas/v1.1/patchwork.yaml
docs/api/schemas/v1.2/patchwork.yaml
docs/api/schemas/v1.3/patchwork.yaml
patchwork/api/base.py
patchwork/api/bundle.py
patchwork/api/comment.py
patchwork/api/embedded.py
patchwork/api/patch.py

index 3a1fdd3aa42dcb882bfc608c5baf196f1c50bbbc..b3de0db5e75df2a810004ba083ee9c54353a736a 100644 (file)
@@ -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
index b97866541a9d6805d9fc6ac5fdf1e7ba5cf9a2db..6865534872cde7ca892f48c09cde8b35e9a5ebc7 100644 (file)
@@ -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
index 817b2f2abe889922122f1174a378eccaf5b980a3..6c3893ec780efcbfb8c38e35faf2988597a8f64e 100644 (file)
@@ -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
index 574a8ad8cdeae372eadf238e4333e15b2014213c..7e2299c5bb3ec61fae8f6246609848092e1a6add 100644 (file)
@@ -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
index 7a4e8e8e2e4a633e7d77aa05f654201f5b0a2c6f..93c3e97eb0854b3ea771e66a7b4249cda4dfc4f6 100644 (file)
@@ -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
index 6bd0419ddf904b3688175a0617fec877143a6eaf..8663406d1a3386a5c02a66dc157fe4545da07621 100644 (file)
@@ -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
index 0f5c44a20774565971b2e9cfc1f826bacdbe95e9..16e5cb8dc7237b6ea8c71d375f8a0871a60f209d 100644 (file)
@@ -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
index b6c7c9d21365b5bc032a89b7cf3862db32c8eba6..134b2724d5991bbd5a188b7e30b0e1427fcd0be8 100644 (file)
@@ -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
index 13c116ee7227d0eec03cc6ef8f339b5746c23952..eae837191b7c714dae6f72dfbeef0231b438988c 100644 (file)
@@ -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:
index 4cfdf8e622e97b667812433474dec625658d65fc..52018435df04840fc44b06c19f7ffc7f0ce2137f 100644 (file)
@@ -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'},
index 9fd10e06e4f3e9ca0cfb4ea2068611a47a454a98..34067611432a807044c170cdf90456915f3894b6 100644 (file)
@@ -180,6 +180,7 @@ class PatchListSerializer(BaseHyperlinkedModelSerializer):
             'related',
         )
         read_only_fields = (
+            'url',
             'web_url',
             'project',
             'msgid',