From nobody Tue May 13 13:06:52 2025 Delivered-To: importer2@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1557925112; cv=none; d=zoho.com; s=zohoarc; b=W1r9239TnTo+qIpoAxLexP6Uho7YKWL/mt3Q+cUUQnk2eyNchqPQsp9q9KzmyM6KkTeqfayWoFeP9FSqU5jt1WwGOzltmU5bQFHqDzgMtyec2qGPFmitUG2DExDzQVwX6yw3On16PuqBAq6DfqCCA8hw9mv3enzslxQS6PSFnmM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557925112; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=awbIx3PhFhyR87Cnz2Hk5VsdLpjI70mcI1aWq9EKsRU=; b=IxherV7eABmeekJgl6jN9mK97p4sgRTTJYPHMHKqOKNrBqCNDw4jpsDA2ieTfACbfjvKtiV6LI16l63AHVGYUZhkyGBRmUoQEeBsm9CNIxCdebcKYU/JA2Fw6Hqn7jnbC8q7OmTW8EGtF1bt50Ot+tig0eTeXJyXY1CG4IuhDF4= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 155792511252036.57355910405738; Wed, 15 May 2019 05:58:32 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 31FFD307CDC1; Wed, 15 May 2019 12:58:31 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 27E8D5D9C3; Wed, 15 May 2019 12:58:31 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1FCBA18089CB; Wed, 15 May 2019 12:58:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x4FCwTZv012650 for ; Wed, 15 May 2019 08:58:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id E85B760CDA; Wed, 15 May 2019 12:58:29 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-34.ams2.redhat.com [10.36.112.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 14E7960E39 for ; Wed, 15 May 2019 12:58:26 +0000 (UTC) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Wed, 15 May 2019 14:58:00 +0200 Message-Id: <20190515125808.27716-4-pbonzini@redhat.com> In-Reply-To: <20190515125808.27716-1-pbonzini@redhat.com> References: <20190515125808.27716-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 03/11] rest: include everything after .../by-name/NAME/ in the redirect location X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 15 May 2019 12:58:31 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This will allow patchew-cli to do a request to project/by-name/QEMU/tester-= get, for example. Signed-off-by: Paolo Bonzini --- api/rest.py | 24 ++++++++++++++++++++---- api/urls.py | 2 +- tests/test_rest.py | 4 ++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/api/rest.py b/api/rest.py index 3b6ab2f..e64c828 100644 --- a/api/rest.py +++ b/api/rest.py @@ -16,7 +16,7 @@ from django.template import loader from mod import dispatch_module_hook from .models import Project, ProjectResult, Message, MessageResult, Result from .search import SearchEngine -from rest_framework import (permissions, serializers, viewsets, filters, +from rest_framework import (permissions, serializers, generics, viewsets, = filters, mixins, renderers, status) from rest_framework.decorators import action from rest_framework.fields import SerializerMethodField, CharField, JSONFi= eld, EmailField, ListField @@ -237,16 +237,32 @@ class ProjectsViewSet(viewsets.ModelViewSet): return Response({"new_head": project.project_head, "count": ret}) =20 =20 -class ProjectsByNameViewSet(viewsets.GenericViewSet): +class ProjectsByNameView(generics.GenericAPIView): + serializer_class =3D ProjectSerializer queryset =3D Project.objects.all() - permission_classes =3D (PatchewPermission,) lookup_field =3D 'name' =20 - def retrieve(self, request, *args, **kwargs): + def _redirect(self, request, *args, **kwargs): instance =3D self.get_object() url =3D reverse_detail(instance, request) + if kwargs['tail']: + tail =3D kwargs['tail'] + if kwargs['tail'][0] =3D=3D '/' and url[-1] =3D=3D '/': + tail =3D tail[1:] + url +=3D tail + params =3D request.query_params.urlencode() + if params: + url +=3D "?" + params return HttpResponseRedirect(url, status=3Dstatus.HTTP_307_TEMPORAR= Y_REDIRECT) =20 + delete =3D _redirect + get =3D _redirect + head =3D _redirect + options =3D _redirect + patch =3D _redirect + post =3D _redirect + put =3D _redirect + =20 # Common classes for series and messages =20 diff --git a/api/urls.py b/api/urls.py index b1e259f..2383f2a 100644 --- a/api/urls.py +++ b/api/urls.py @@ -34,7 +34,6 @@ router =3D DefaultRouter(trailing_slash=3DTrue) router.include_format_suffixes =3D False router.register('users', rest.UsersViewSet) router.register('projects', rest.ProjectsViewSet) -router.register('projects/by-name', rest.ProjectsByNameViewSet) router.register('series', rest.SeriesViewSet, base_name=3D'series') router.register('messages', rest.MessagesViewSet) =20 @@ -51,6 +50,7 @@ results_router.register('results', rest.SeriesResultsView= Set, base_name=3D'results schema_view =3D get_schema_view(title=3D'API schema') =20 urlpatterns =3D _build_urls() + [ + url(r'^v1/projects/by-name/(?P[^/]*)(?P/.*|$)', rest.Proje= ctsByNameView.as_view()), url(r'^v1/users/login/$', LoginView.as_view(), name=3D'rest_login'), url(r'^v1/users/logout/$', LogoutView.as_view(), name=3D'rest_logout'), url(r"^v1/", include(router.urls)), diff --git a/tests/test_rest.py b/tests/test_rest.py index d6cbf62..36ff739 100755 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -91,6 +91,10 @@ class RestTest(PatchewTestCase): self.assertEquals(resp.data['resource_uri'], self.PROJECT_BASE) self.assertEquals(resp.data['name'], "QEMU") self.assertEquals(resp.data['mailing_list'], "qemu-devel@nongnu.or= g") + resp =3D self.api_client.get(self.REST_BASE + 'projects/by-name/QE= MU/?some=3Dthing&foo=3Dbar') + self.assertEquals(resp.status_code, 307) + self.assertIn('some=3Dthing', resp['Location']) + self.assertIn('foo=3Dbar', resp['Location']) =20 def test_project_config_get(self): self.p.config =3D { --=20 2.21.0 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel