From patchwork Fri Sep 30 16:19:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 1684926 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="key not found in DNS" header.d=that.guru header.i=@that.guru header.a=rsa-sha256 header.s=x header.b=MrsQN67y; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MfFnp5kRgz1ypH for ; Sat, 1 Oct 2022 02:20:30 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4MfFnp5Wv7z2xJ6 for ; Sat, 1 Oct 2022 02:20:30 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" header.d=that.guru header.i=@that.guru header.a=rsa-sha256 header.s=x header.b=MrsQN67y; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=that.guru (client-ip=136.175.108.92; helo=mail-108-mta92.mxroute.com; envelope-from=stephen@that.guru; receiver=) Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" header.d=that.guru header.i=@that.guru header.a=rsa-sha256 header.s=x header.b=MrsQN67y; dkim-atps=neutral Received: from mail-108-mta92.mxroute.com (mail-108-mta92.mxroute.com [136.175.108.92]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4MfFmy48SDz3cF8 for ; Sat, 1 Oct 2022 02:19:45 +1000 (AEST) Received: from mail-111-mta2.mxroute.com ([136.175.111.2] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta92.mxroute.com (ZoneMTA) with ESMTPSA id 1838f3226ef0002b7a.001 for (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256); Fri, 30 Sep 2022 16:19:32 +0000 X-Zone-Loop: dcb1872e6596d1c47010638054926d08762ea60732b0 X-Originating-IP: [136.175.111.2] DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru; s=x; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=hS7KrCY/ySCcIhEJd34Xa4heaLV3ac7efQN8k0iyA3s=; b=MrsQN67y+WG9VNS8/LVD4+fzgd XLWXl1/lnQd9n97Ortw6G14tVwMECE/VX55HEL4r5IWbN9IOlNtZDB8Yb/qwhaaDwuMRPwrdffZcW Cp3vxei8ZVxQV892SHIGY2ZnpdrsjCbOrkIWrtpwfjLCf7+BlYOvs7GqigGQGEdBBOnKx/2FQBX4k FB5M2Iuxn6f2nGGmyExfZFR9a0JQfWqWMFtK73X2wPQD5vvKV+D73Ets+Vd+ssXJNUhBM/GM3sc92 qCuiu1tDq3E9DaBgbgf8VD70Df3Boy7ONoCgrxLPn+AnI7yVXzBrLRRpwl6uQuIqNc50qGs7hN910 gZ+iplGA==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH 09/10] REST: Add missing 'url' parameter for comments Date: Fri, 30 Sep 2022 17:19:20 +0100 Message-Id: <20220930161921.266633-9-stephen@that.guru> In-Reply-To: <20220930161921.266633-1-stephen@that.guru> References: <20220930161921.266633-1-stephen@that.guru> MIME-Version: 1.0 X-Authenticated-Id: stephen@that.guru X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" This should be present on all resources. Signed-off-by: Stephen Finucane 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',