From patchwork Sat Nov 30 16:40:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 1202704 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47QHDw4v0xz9sNx for ; Sun, 1 Dec 2019 03:40:48 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="cWv8x4RC"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47QHDv62d3zDqw6 for ; Sun, 1 Dec 2019 03:40:47 +1100 (AEDT) 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=160.202.107.175; helo=q2relay175.mxroute.com; envelope-from=stephen@that.guru; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="cWv8x4RC"; dkim-atps=neutral Received: from q2relay175.mxroute.com (q2relay175.mxroute.com [160.202.107.175]) (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 47QHDj18m8zDqvp for ; Sun, 1 Dec 2019 03:40:36 +1100 (AEDT) Received: from filter003.mxroute.com [168.235.111.26] (Authenticated sender: mN4UYu2MZsgR) by q2relay175.mxroute.com (ZoneMTA) with ESMTPSA id 16ebd2f6e4d000f0dc.002 for (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256); Sat, 30 Nov 2019 16:40:32 +0000 X-Zone-Loop: 106ee113ba7ebbb4dc1b3ef80797e37c6cb0c37e2c7e X-Originating-IP: [168.235.111.26] Received: from one.mxroute.com (one.mxroute.com [195.201.59.211]) by filter003.mxroute.com (Postfix) with ESMTPS id 0576861159; Sat, 30 Nov 2019 16:40:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru; s=default; h=Content-Transfer-Encoding:MIME-Version: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: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=7kX8lk2dEQhQG32yolSIZRSWzAbwtomUyEE2chOgbbI=; b=cWv8x4RCllv6vjsS4/GZUnZEMQ sNWCvf7gZgAmYynHukzSaiKDhkbvFSeAUSAYLtoNpIiuMSF1taz2CeOXKLH/yg2JeSJO5SJpVJy0K 2fgyk59edzisrF/nLHp+S/Pa1boLx8yfd2G0q7y3iD3q22DVKDDYRTH49Ctkp8OFIj3lhdVrs6Wmo S0v/hBHDy8XRQh7Y8n1JIIuxJzZvb6fNbZAHKkTBHCqTcgSwZGDvgZit3zf5vJBFN8IlTlYZeQfrd jWBuE6M5/Bp79vSh/+4hM2luw87aYsfAONCah1JDoVOGsglmrXVcNWUF9vaK+USAt6DIFuFRJ3m2n MtdRVjPg==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH] REST: Exclude filters added in later version Date: Sat, 30 Nov 2019 16:40:21 +0000 Message-Id: <20191130164021.57099-1-stephen@that.guru> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 X-AuthUser: 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" If a person requests API version 1.1, they should get the exact same behavior regardless of the base Patchwork version. We already do this for fields in the output, so now extend this to filters in the querystring. Signed-off-by: Stephen Finucane Cc: Daniel Axtens --- patchwork/api/filters.py | 36 +++++++++++++++++++++++++------ patchwork/tests/api/test_patch.py | 9 ++++++++ 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/patchwork/api/filters.py b/patchwork/api/filters.py index 4184ee82..6b4d84c7 100644 --- a/patchwork/api/filters.py +++ b/patchwork/api/filters.py @@ -13,6 +13,7 @@ from django_filters import ModelMultipleChoiceFilter from django.forms import ModelMultipleChoiceField as BaseMultipleChoiceField from django.forms.widgets import MultipleHiddenInput +from patchwork.api import utils from patchwork.compat import NAME_FIELD from patchwork.models import Bundle from patchwork.models import Check @@ -136,14 +137,32 @@ class UserFilter(ModelMultipleChoiceFilter): # filter sets -class TimestampMixin(FilterSet): + +class BaseFilterSet(FilterSet): + + @property + def form(self): + form = super(BaseFilterSet, self).form + + for version in getattr(self.Meta, 'versioned_fields', {}): + if utils.has_version(self.request, version): + continue + + for field in self.Meta.versioned_fields[version]: + if field in form.fields: + del form.fields[field] + + return form + + +class TimestampMixin(BaseFilterSet): # TODO(stephenfin): These should filter on a 'updated_at' field instead before = IsoDateTimeFilter(lookup_expr='lt', **{NAME_FIELD: 'date'}) since = IsoDateTimeFilter(lookup_expr='gte', **{NAME_FIELD: 'date'}) -class SeriesFilterSet(TimestampMixin, FilterSet): +class SeriesFilterSet(TimestampMixin, BaseFilterSet): submitter = PersonFilter(queryset=Person.objects.all()) project = ProjectFilter(queryset=Project.objects.all()) @@ -153,7 +172,7 @@ class SeriesFilterSet(TimestampMixin, FilterSet): fields = ('submitter', 'project') -class CoverLetterFilterSet(TimestampMixin, FilterSet): +class CoverLetterFilterSet(TimestampMixin, BaseFilterSet): project = ProjectFilter(queryset=Project.objects.all()) # NOTE(stephenfin): We disable the select-based HTML widgets for these @@ -167,7 +186,7 @@ class CoverLetterFilterSet(TimestampMixin, FilterSet): fields = ('project', 'series', 'submitter') -class PatchFilterSet(TimestampMixin, FilterSet): +class PatchFilterSet(TimestampMixin, BaseFilterSet): project = ProjectFilter(queryset=Project.objects.all()) # NOTE(stephenfin): We disable the select-based HTML widgets for these @@ -187,9 +206,12 @@ class PatchFilterSet(TimestampMixin, FilterSet): # which seems to rather defeat the point of using django-filters. fields = ('project', 'series', 'submitter', 'delegate', 'state', 'archived', 'hash') + versioned_fields = { + '1.2': ('hash', ), + } -class CheckFilterSet(TimestampMixin, FilterSet): +class CheckFilterSet(TimestampMixin, BaseFilterSet): user = UserFilter(queryset=User.objects.all()) @@ -198,7 +220,7 @@ class CheckFilterSet(TimestampMixin, FilterSet): fields = ('user', 'state', 'context') -class EventFilterSet(TimestampMixin, FilterSet): +class EventFilterSet(TimestampMixin, BaseFilterSet): # NOTE(stephenfin): We disable the select-based HTML widgets for these # filters as the resulting query is _huge_ @@ -217,7 +239,7 @@ class EventFilterSet(TimestampMixin, FilterSet): fields = ('project', 'category', 'series', 'patch', 'cover') -class BundleFilterSet(FilterSet): +class BundleFilterSet(BaseFilterSet): project = ProjectFilter(queryset=Project.objects.all()) owner = UserFilter(queryset=User.objects.all()) diff --git a/patchwork/tests/api/test_patch.py b/patchwork/tests/api/test_patch.py index 4afc15a9..bf3ef9f8 100644 --- a/patchwork/tests/api/test_patch.py +++ b/patchwork/tests/api/test_patch.py @@ -188,6 +188,15 @@ class TestPatchAPI(utils.APITestCase): 'hash': 'da638d0746a115000bf890fada1f02679aa282e8'}) self.assertEqual(0, len(resp.data)) + def test_list_filter_hash_version_1_1(self): + """Filter patches by hash using API v1.1.""" + self._create_patch() + + # we still see the patch since the hash field is ignored + resp = self.client.get(self.api_url(version='1.1'), + {'hash': 'garbagevalue'}) + self.assertEqual(1, len(resp.data)) + @utils.store_samples('patch-list-1-0') def test_list_version_1_0(self): """List patches using API v1.0."""