From: Stephen Finucane Date: Fri, 30 Sep 2022 14:01:14 +0000 (+0100) Subject: REST: Add missing 'url' parameter for comments X-Git-Tag: v3.2.0~121 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=73b0b12df256c4e2e9c5e724828c778e69f0cf13;p=thirdparty%2Fpatchwork.git REST: Add missing 'url' parameter for comments This should be present on all resources. Signed-off-by: Stephen Finucane Fixes: 88f56051 ("api: add comments detail endpoint") --- diff --git a/docs/api/schemas/latest/patchwork.yaml b/docs/api/schemas/latest/patchwork.yaml index 3a1fdd3a..b3de0db5 100644 --- a/docs/api/schemas/latest/patchwork.yaml +++ b/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 a/docs/api/schemas/patchwork.j2 b/docs/api/schemas/patchwork.j2 index b9786654..68655348 100644 --- a/docs/api/schemas/patchwork.j2 +++ b/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 a/docs/api/schemas/v1.0/patchwork.yaml b/docs/api/schemas/v1.0/patchwork.yaml index 817b2f2a..6c3893ec 100644 --- a/docs/api/schemas/v1.0/patchwork.yaml +++ b/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 a/docs/api/schemas/v1.1/patchwork.yaml b/docs/api/schemas/v1.1/patchwork.yaml index 574a8ad8..7e2299c5 100644 --- a/docs/api/schemas/v1.1/patchwork.yaml +++ b/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 a/docs/api/schemas/v1.2/patchwork.yaml b/docs/api/schemas/v1.2/patchwork.yaml index 7a4e8e8e..93c3e97e 100644 --- a/docs/api/schemas/v1.2/patchwork.yaml +++ b/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 a/docs/api/schemas/v1.3/patchwork.yaml b/docs/api/schemas/v1.3/patchwork.yaml index 6bd0419d..8663406d 100644 --- a/docs/api/schemas/v1.3/patchwork.yaml +++ b/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 a/patchwork/api/base.py b/patchwork/api/base.py index 0f5c44a2..16e5cb8d 100644 --- a/patchwork/api/base.py +++ b/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 a/patchwork/api/bundle.py b/patchwork/api/bundle.py index b6c7c9d2..134b2724 100644 --- a/patchwork/api/bundle.py +++ b/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 a/patchwork/api/comment.py b/patchwork/api/comment.py index 13c116ee..eae83719 100644 --- a/patchwork/api/comment.py +++ b/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 a/patchwork/api/embedded.py b/patchwork/api/embedded.py index 4cfdf8e6..52018435 100644 --- a/patchwork/api/embedded.py +++ b/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 a/patchwork/api/patch.py b/patchwork/api/patch.py index 9fd10e06..34067611 100644 --- a/patchwork/api/patch.py +++ b/patchwork/api/patch.py @@ -180,6 +180,7 @@ class PatchListSerializer(BaseHyperlinkedModelSerializer): 'related', ) read_only_fields = ( + 'url', 'web_url', 'project', 'msgid',