From nobody Fri Mar 29 06:55:35 2024 Delivered-To: importer@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; dkim=fail; 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1534581594114287.5235840415744; Sat, 18 Aug 2018 01:39:54 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 90B22308212F; Sat, 18 Aug 2018 08:39:52 +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 8154628DE3; Sat, 18 Aug 2018 08:39:52 +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 6D657180613A; Sat, 18 Aug 2018 08:39:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w7I8dpBl013198 for ; Sat, 18 Aug 2018 04:39:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id D1A63308BDA2; Sat, 18 Aug 2018 08:39:51 +0000 (UTC) Received: from mx1.redhat.com (ext-mx12.extmail.prod.ext.phx2.redhat.com [10.5.110.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C84EA308BDA0 for ; Sat, 18 Aug 2018 08:39:49 +0000 (UTC) Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 106F2308A953 for ; Sat, 18 Aug 2018 08:39:48 +0000 (UTC) Received: by mail-wr1-f50.google.com with SMTP id z96-v6so268157wrb.8 for ; Sat, 18 Aug 2018 01:39:47 -0700 (PDT) Received: from donizetti.lan (dynamic-adsl-78-12-184-244.clienti.tiscali.it. [78.12.184.244]) by smtp.gmail.com with ESMTPSA id j39-v6sm4830677wre.44.2018.08.18.01.39.45 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 18 Aug 2018 01:39:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=9F6iRmCnHZnzs1yZvbNKrcUGMJeOeIVwLfZA7GoFuek=; b=E3XcUIOEOTeI/9bbvRw3FWplyJXuesDu4xYqhz65mYqu04paJ2dQe/EbiRSaIFs2xm 4LMVyTkQHnohhVQAUa4ZO7FpuNdNn7tqENc6fWB+1MK9K76EYqeyIeQuY8PlIDMEXUw6 3uuHFwWN3tk6D+xbaVqEPH5Fk9LbkkBdQ+vtPsh7pXZgutjs+GIOtFgud+ehXEArmbuA Fky7Pdl5eKmRF+H5YvdhW1xHptRFhKakj/UMsKqQXoiRPBT8m7372UnCVhKxIBDrmV5q yCoP4BdjSlIzk9w33hZuJ1H3WLDz9fwZ7g391IADkgUNl5YZo6fi06M1WikxiqwuN+DY N18g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=9F6iRmCnHZnzs1yZvbNKrcUGMJeOeIVwLfZA7GoFuek=; b=byIQaukylymdwlbkOxtgmLjAGWeLZwtloUQ7QFThCTplzVWgE4KzTFpBfThG3vRO3V Uss5m/op3JGp6K0p/S+VJuQM5bvT0hHVh6KdP5LrmNDs08WREIGGRmK+diEQ9RinSQz6 2HsxLPJTWkZAjLo4yg/2viX2YBL6QEV0DfvMbosHscB8/j9WHI9fwULkNcjPZF8ZVKAV 8Gzf2tFyPxpl/zcw7OK0KcVnwjaQrZS12mNOMB9qgRDICucA7ZPnNV+VNoZtexireCJS uka22W8/PA0p0hAtIfsaQ0JbHoK8G8H8ZT93MfPLF6/ShMVlvsB+NAxQq+RmeX11RQ16 H/Mw== X-Gm-Message-State: AOUpUlEbASfzO7kAXUwWmJU5IfIfG5XeM05ia9xla3/BFIDt1OXLmd6t mAnjNzA3Cfp+RVuELWsayHLU0OT5 X-Google-Smtp-Source: AA+uWPwa7db64J8DcYbsZJFWPbgJr+OIv1m7RdD8ARFvp+e6czFVv5GXfwtUmvzLQT8I3GJt+EZWaA== X-Received: by 2002:adf:9a0b:: with SMTP id z11-v6mr22957772wrb.47.1534581586505; Sat, 18 Aug 2018 01:39:46 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Sat, 18 Aug 2018 10:39:36 +0200 Message-Id: <20180818083944.19692-2-pbonzini@redhat.com> In-Reply-To: <20180818083944.19692-1-pbonzini@redhat.com> References: <20180818083944.19692-1-pbonzini@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Sat, 18 Aug 2018 08:39:48 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Sat, 18 Aug 2018 08:39:48 +0000 (UTC) for IP:'209.85.221.50' DOMAIN:'mail-wr1-f50.google.com' HELO:'mail-wr1-f50.google.com' FROM:'paolo.bonzini@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.008 (DKIM_SIGNED, DKIM_VALID, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_PASS) 209.85.221.50 mail-wr1-f50.google.com 209.85.221.50 mail-wr1-f50.google.com X-RedHat-Possible-Forgery: Paolo Bonzini X-Scanned-By: MIMEDefang 2.84 on 10.5.110.41 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 1/9] models: JSONField default should be empty dictionary, not empty string 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Sat, 18 Aug 2018 08:39:52 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_0 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Otherwise, you could have a situation the REST API returns an empty string for a GET request, but JSONField complains when the same empty string is passed as a PUT request. Signed-off-by: Paolo Bonzini --- api/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/models.py b/api/models.py index ad89cf8..eea924f 100644 --- a/api/models.py +++ b/api/models.py @@ -56,7 +56,7 @@ class Result(models.Model): code=3D'invalid')]) log_entry =3D models.OneToOneField(LogEntry, on_delete=3Dmodels.CASCAD= E, null=3DTrue) - data =3D jsonfield.JSONField() + data =3D jsonfield.JSONField(default=3D{}) =20 class Meta: index_together =3D [('status', 'name')] --=20 2.17.1 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel From nobody Fri Mar 29 06:55:35 2024 Delivered-To: importer@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; dkim=fail; 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1534581753557566.1051620544802; Sat, 18 Aug 2018 01:42:33 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 42AE936883; Sat, 18 Aug 2018 08:42:32 +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 2F404951C9; Sat, 18 Aug 2018 08:42:32 +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 23C32181A12D; Sat, 18 Aug 2018 08:42:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w7I8dqHP013203 for ; Sat, 18 Aug 2018 04:39:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4165A103BAB4; Sat, 18 Aug 2018 08:39:52 +0000 (UTC) Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3A0C9101F94C for ; Sat, 18 Aug 2018 08:39:50 +0000 (UTC) Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 56FED81DF0 for ; Sat, 18 Aug 2018 08:39:49 +0000 (UTC) Received: by mail-wr1-f41.google.com with SMTP id a108-v6so6258249wrc.13 for ; Sat, 18 Aug 2018 01:39:49 -0700 (PDT) Received: from donizetti.lan (dynamic-adsl-78-12-184-244.clienti.tiscali.it. [78.12.184.244]) by smtp.gmail.com with ESMTPSA id j39-v6sm4830677wre.44.2018.08.18.01.39.46 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 18 Aug 2018 01:39:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=muV9CxZ15xdB0yZxVfiGz96Pe3EJeHIDadEUntujvzs=; b=Cbkat6EIMubETuIKNFH4SWAbXtGS7k8BPYV1mQ9F/d21v2U3NNQmOsYiuVkXdN8fN0 BLALr/4u23KTgzNC6KYbbbY/S85gsTPETJj1aoORLNrELFlWR2ty5LZyD1h8EfJFlQC4 nrCKzfoBkEVKuRYatTLGj4FwX4KiIHKh6Z4kbNC1ymUYjaBWuro9rsh2FHFa5Pdt9zqq rs7U3TWE9G6ob+7qHk6pMznQ9B/oD6bLGC1Fw5fcFwbw0JbzehIZZBwk3Iya/PuvWXIh F+msBh4F+h9kbttrI4pGBxoG8eywMzUDSDuKJSZhRUVpH1a3c2qWbN3Cj85+8AbEpzHW khvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=muV9CxZ15xdB0yZxVfiGz96Pe3EJeHIDadEUntujvzs=; b=lT2EXU1/7FpEvKHg/9gFsUutRiqRP7Tns2VXdFdMtJqgJt2mxMIvha1nPxcMBB1afa BieH6IepgGQz7N+lpkFNzvE/RhODDhhos3YLcFxkjaW8h+SKs318WDkgireIFoTFYk3e BgNVX/EKGF6tO0f3xvWg1wV5WLanXAC6gDQ+SWzGCMDUzj26ECpH5pBNr2v/nN2Y4GYw IUqY28+Y1h5GgMBIqBR18x3nDKORnzPcg3ZlOY92IwP3xOkySD6Wphst/tQa0IacQCZB yP1NyeEL8BLXhsTNRwkxIw6QJK1+gvboHO+TtZKA3RmicmLrk1vNno0UIEtBhwwUrpY8 NyvQ== X-Gm-Message-State: AOUpUlEJcG0FhoJQI6ZiRNGDNa2F9+Zu4XYQqNChlRFd6lYcJFBcMCgI TwK/BNoHx/hvQfVvdClBOaG/sswg X-Google-Smtp-Source: AA+uWPxVc7nQs6SMOExtr7wkUnRRIYtptn+4Vp+raFii/rA4VRksUlaDrV+Fb2yJeJmLHJ/OJck94Q== X-Received: by 2002:adf:d08c:: with SMTP id y12-v6mr24610782wrh.152.1534581587767; Sat, 18 Aug 2018 01:39:47 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Sat, 18 Aug 2018 10:39:37 +0200 Message-Id: <20180818083944.19692-3-pbonzini@redhat.com> In-Reply-To: <20180818083944.19692-1-pbonzini@redhat.com> References: <20180818083944.19692-1-pbonzini@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Sat, 18 Aug 2018 08:39:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Sat, 18 Aug 2018 08:39:49 +0000 (UTC) for IP:'209.85.221.41' DOMAIN:'mail-wr1-f41.google.com' HELO:'mail-wr1-f41.google.com' FROM:'paolo.bonzini@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.009 (DKIM_SIGNED, DKIM_VALID, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS) 209.85.221.41 mail-wr1-f41.google.com 209.85.221.41 mail-wr1-f41.google.com X-RedHat-Possible-Forgery: Paolo Bonzini X-Scanned-By: MIMEDefang 2.83 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 2/9] testing: use ResultUpdate hook to set global testing properties 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sat, 18 Aug 2018 08:42:32 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_0 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This will ensure that a PUT of a result will also set the properties, and n= ot just the testing-report API. The HEAD that was used for testing is now stored in the result, which is a good idea anyway. This requires a small change in the tests. Signed-off-by: Paolo Bonzini --- mods/testing.py | 15 ++++++++++----- tests/test_testing.py | 7 ++++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/mods/testing.py b/mods/testing.py index ccdd336..0266fb9 100644 --- a/mods/testing.py +++ b/mods/testing.py @@ -123,6 +123,15 @@ class TestingModule(PatchewModule): self.recalc_pending_tests(obj) =20 def on_result_update(self, evt, obj, old_status, result): + if result.name.startswith("testing.") and result.status !=3D old_s= tatus: + if 'tester' in result.data: + po =3D obj if isinstance(obj, Project) else obj.project + _instance.tester_check_in(po, result.data['tester']) + if not self.get_testing_results(obj, + status__in=3D(Result.PENDING, Result.RUNNING)).= exists(): + obj.set_property("testing.done", True) + obj.set_property("testing.tested-head", result.data["head"= ]) + if result.name !=3D "git": return if isinstance(obj, Message) \ @@ -230,14 +239,11 @@ class TestingModule(PatchewModule): r =3D self.get_testing_result(obj, test) r.data =3D {"is_timeout": is_timeout, "user": user.username, + "head": head, "tester": tester or user.username} r.log =3D log r.status =3D Result.SUCCESS if passed else Result.FAILURE r.save() - if not self.get_testing_results(obj, - status__in=3D(Result.PENDING, Result.RUNNING)).exis= ts(): - obj.set_property("testing.done", True) - obj.set_property("testing.tested-head", head) =20 log_url =3D self.reverse_testing_log(obj, test, request=3Drequest) html_log_url =3D self.reverse_testing_log(obj, test, request=3Dreq= uest, html=3DTrue) @@ -476,7 +482,6 @@ class TestingReportView(APILoginRequiredView): def handle(self, request, tester, project, test, head, base, passed, log, identity, is_timeout=3DFalse): - _instance.tester_check_in(project, tester or request.user.username) _instance.add_test_report(request, project, tester, test, head, base, identity, passed, log, is_timeout) diff --git a/tests/test_testing.py b/tests/test_testing.py index 93aaf8b..c9452a4 100755 --- a/tests/test_testing.py +++ b/tests/test_testing.py @@ -38,9 +38,14 @@ class TestingTestCase(PatchewTestCase, metaclass=3Dabc.A= BCMeta): r =3D obj.results.get(name=3D'testing.a') except: r =3D obj.create_result(name=3D'testing.a') - if not 'status' in kwargs: + if 'status' not in kwargs: kwargs['status'] =3D Result.PENDING =20 + if kwargs['status'] =3D=3D Result.SUCCESS or kwargs['status'] =3D= =3D Result.FAILURE: + if 'data' not in kwargs: + kwargs['data'] =3D {} + if 'head' not in kwargs['data']: + kwargs['data']['head'] =3D '0123456789abcdef' if len(kwargs): for k, v in kwargs.items(): setattr(r, k, v) --=20 2.17.1 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel From nobody Fri Mar 29 06:55:35 2024 Delivered-To: importer@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; dkim=fail; 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15345815964891020.3451640947484; Sat, 18 Aug 2018 01:39:56 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E64BD81DE7; Sat, 18 Aug 2018 08:39:54 +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 D2ED016C04; Sat, 18 Aug 2018 08:39:54 +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 C5389180613A; Sat, 18 Aug 2018 08:39:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w7I8dr6j013213 for ; Sat, 18 Aug 2018 04:39:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8121262460; Sat, 18 Aug 2018 08:39:53 +0000 (UTC) Received: from mx1.redhat.com (ext-mx11.extmail.prod.ext.phx2.redhat.com [10.5.110.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 77EDE61F4F for ; Sat, 18 Aug 2018 08:39:51 +0000 (UTC) Received: from mail-wm0-f48.google.com (mail-wm0-f48.google.com [74.125.82.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6228D3084216 for ; Sat, 18 Aug 2018 08:39:50 +0000 (UTC) Received: by mail-wm0-f48.google.com with SMTP id q8-v6so9333883wmq.4 for ; Sat, 18 Aug 2018 01:39:50 -0700 (PDT) Received: from donizetti.lan (dynamic-adsl-78-12-184-244.clienti.tiscali.it. [78.12.184.244]) by smtp.gmail.com with ESMTPSA id j39-v6sm4830677wre.44.2018.08.18.01.39.47 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 18 Aug 2018 01:39:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=qo9nUVUE0DxTq4vgMwBHWbHXYOMFFvsK+wMNRdkY+TM=; b=hiXh8c2v+KJEJHtbgUpn9SRHDySyNkHervqsEe848lbFRJWh5Rk6ZzDPESuVta5z9o NmirEtbbNkCzU9JrLGjzvmQ95BPKpInzn/0CxK/ipW4JUWAIbrSdljoF0fUTegKfXYg6 eUBme9ZOsG7Q5KK76qsatDg/vt+4fWUjtWv1YfE2SN8pA/Oy6CpBmy+3vyQKxZbAe9Qp NucXnGOi87OZtsx7FfWP9mu4EEH1iH9mwqu9uyoc+SxNNCvgSCdyLWgK2+syao/Kvu2n KKEQbN2fFyMYygR5PQP85RP7vU7CZiZofuc9cjLWpk+DL1LaA5lRZqHQvrKx121ndBKk VmhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=qo9nUVUE0DxTq4vgMwBHWbHXYOMFFvsK+wMNRdkY+TM=; b=CEmvAoTJWcHvjxUqjIOSpAsu2yIlZelOQKAaM4Mhzf0KLsXnqmnTp+RgbSKvqGP+SO cFuOeqvW0hUlXzgYQLwoYIr8MLcFpKKoeMqCW41d2bFDwCknX+44krb6gV/IRj5KmgNp NuXgA8q5e5+lfod9DD4xKWbnfswpPYB0L0BhvI0zTfm2wyrbcEiBeP23suF87hhAkgqT S4eTs4Fu6qpEWJBwtp5CwMWWVkwwPNbIIulJNA1WlaU4psZ+h5dnWyw5sb8yYywSeMXJ tUWocQtTbGd7THU3e6Wt3vGekaqjku9Nl4g0cv4PilDDoS/ge4Ew94bpDoIvxZN0B2RU hrmw== X-Gm-Message-State: AOUpUlEig4pdMpKbpnBeQXt2fDD94Y29UllccWBk5+OQpDj9v0lDOzKy 03zyo/VnISYaerWguM0MAOcIsUI4 X-Google-Smtp-Source: AA+uWPy6T8AYoUze45LefDSPA2gM5sHsPaTqEEbmg1/hZD9AxuRKMrrj7IR/ExCwNlkGD1MrirTX4Q== X-Received: by 2002:a1c:9cd3:: with SMTP id f202-v6mr20444542wme.148.1534581588875; Sat, 18 Aug 2018 01:39:48 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Sat, 18 Aug 2018 10:39:38 +0200 Message-Id: <20180818083944.19692-4-pbonzini@redhat.com> In-Reply-To: <20180818083944.19692-1-pbonzini@redhat.com> References: <20180818083944.19692-1-pbonzini@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Sat, 18 Aug 2018 08:39:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Sat, 18 Aug 2018 08:39:50 +0000 (UTC) for IP:'74.125.82.48' DOMAIN:'mail-wm0-f48.google.com' HELO:'mail-wm0-f48.google.com' FROM:'paolo.bonzini@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.028 (DKIM_SIGNED, DKIM_VALID, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 74.125.82.48 mail-wm0-f48.google.com 74.125.82.48 mail-wm0-f48.google.com X-RedHat-Possible-Forgery: Paolo Bonzini X-Scanned-By: MIMEDefang 2.84 on 10.5.110.40 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 3/9] testing: include result URI in testing-get API response 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Sat, 18 Aug 2018 08:39:54 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_0 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This is simpler to use than the "identity" field, if patchew-cli is going to use a PUT request to the REST API instead of testing-report. Signed-off-by: Paolo Bonzini --- api/rest.py | 28 ++++++++++++++++++++++++++++ mods/testing.py | 16 ++++++++++------ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/api/rest.py b/api/rest.py index 9ec0ae8..bd46211 100644 --- a/api/rest.py +++ b/api/rest.py @@ -77,6 +77,34 @@ class PatchewPermission(permissions.BasePermission): class ImportPermission(PatchewPermission): allowed_groups =3D ('importers',) =20 +# utility function to generate REST API URLs + +def reverse_detail(obj, request): + if isinstance(obj, Project): + return rest_framework.reverse.reverse("project-detail", + request=3Drequest, + kwargs=3D{"pk": obj.id}) + if isinstance(obj, Message): + assert obj.is_series_head + return rest_framework.reverse.reverse("series-detail", + request=3Drequest, + kwargs=3D{"projects_pk": obj= .project.id, + "message_id": obj.me= ssage_id}) + if isinstance(obj, ProjectResult): + po =3D obj.obj + return rest_framework.reverse.reverse("results-detail", + request=3Drequest, + kwargs=3D{"projects_pk": po.= id, + "name": obj.name}) + if isinstance(obj, MessageResult): + m =3D obj.obj + return rest_framework.reverse.reverse("results-detail", + request=3Drequest, + kwargs=3D{"projects_pk": m.p= roject.id, + "series_message_id":= m.message_id, + "name": obj.name}), + raise Error("unhandled object type") + # pluggable field for plugin support =20 class PluginMethodField(SerializerMethodField): diff --git a/mods/testing.py b/mods/testing.py index 0266fb9..ecd63d1 100644 --- a/mods/testing.py +++ b/mods/testing.py @@ -20,6 +20,7 @@ import math from api.views import APILoginRequiredView from api.models import (Message, MessageProperty, MessageResult, Project, ProjectResult, Result) +from api.rest import reverse_detail from api.search import SearchEngine from event import emit_event, declare_event, register_handler from patchew.logviewer import LogView @@ -388,17 +389,18 @@ class TestingGetView(APILoginRequiredView): name =3D "testing-get" allowed_groups =3D ["testers"] =20 - def _generate_test_data(self, project, repo, head, base, identity, tes= t): + def _generate_test_data(self, project, repo, head, base, identity, res= ult_uri, test): r =3D {"project": project, "repo": repo, "head": head, "base": base, "test": test, - "identity": identity + "identity": identity, + "result_uri": result_uri, } return r =20 - def _generate_series_test_data(self, s, test): + def _generate_series_test_data(self, request, s, result, test): gr =3D s.git_result assert gr.is_success() return self._generate_test_data(project=3Ds.project.name, @@ -410,15 +412,17 @@ class TestingGetView(APILoginRequiredView): "message-id": s.message_id, "subject": s.subject, }, + result_uri=3Dreverse_detail(result= , request), test=3Dtest) =20 - def _generate_project_test_data(self, project, repo, head, base, test): + def _generate_project_test_data(self, request, project, repo, head, ba= se, result, test): return self._generate_test_data(project=3Dproject, repo=3Drepo, head=3Dhead, base=3Db= ase, identity=3D{ "type": "project", "head": head, }, + result_uri=3Dreverse_detail(result= , request), test=3Dtest) =20 def _find_applicable_test(self, queryset, user, po, tester, capabiliti= es): @@ -448,7 +452,7 @@ class TestingGetView(APILoginRequiredView): candidates =3D self._find_applicable_test(ProjectResult.objects.fi= lter(project=3Dpo), request.user, po, tester, = capabilities) for r, test in candidates: - td =3D self._generate_project_test_data(po.name, repo, head, t= ested, test) + td =3D self._generate_project_test_data(request, po.name, repo= , head, tested, r, test) return r, po, td return None =20 @@ -457,7 +461,7 @@ class TestingGetView(APILoginRequiredView): request.user, po, tester, = capabilities) for r, test in candidates: s =3D r.message - td =3D self._generate_series_test_data(s, test) + td =3D self._generate_series_test_data(request, s, r, test) return r, s, td return None =20 --=20 2.17.1 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel From nobody Fri Mar 29 06:55:35 2024 Delivered-To: importer@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; dkim=fail; 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1534581598312367.3241788904022; Sat, 18 Aug 2018 01:39:58 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 071A281DF0; Sat, 18 Aug 2018 08:39:57 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E9DE416C04; Sat, 18 Aug 2018 08:39:56 +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 D9ED34BB78; Sat, 18 Aug 2018 08:39:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w7I8dtEm013228 for ; Sat, 18 Aug 2018 04:39:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 91BD05F7C2; Sat, 18 Aug 2018 08:39:55 +0000 (UTC) Received: from mx1.redhat.com (ext-mx16.extmail.prod.ext.phx2.redhat.com [10.5.110.45]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8656117F32 for ; Sat, 18 Aug 2018 08:39:52 +0000 (UTC) Received: from mail-wm0-f47.google.com (mail-wm0-f47.google.com [74.125.82.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5921B3082A2C for ; Sat, 18 Aug 2018 08:39:51 +0000 (UTC) Received: by mail-wm0-f47.google.com with SMTP id t25-v6so9271804wmi.3 for ; Sat, 18 Aug 2018 01:39:51 -0700 (PDT) Received: from donizetti.lan (dynamic-adsl-78-12-184-244.clienti.tiscali.it. [78.12.184.244]) by smtp.gmail.com with ESMTPSA id j39-v6sm4830677wre.44.2018.08.18.01.39.48 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 18 Aug 2018 01:39:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=F9Jspp9RQAdHQY2naC4FkTtsTGkxPnroNycr9wGTC20=; b=LwNwpq+ska7n+mn3ZZwrQFRVv5YN2zfrnmScG1wi3Z+61p5UEJnr7laCz9m5yiZjZI +Jl31CC7bOUeIxR+9Q2OANoDt+RANwlzpTmFbURT/t2h2KQYGN6AmUxlf7B2nnBqiFPg DhgRHhOvUaqjCPB6SOCc1GzOdIOLdByVpWFykze5LBoTMK8LHfqYVlSJ0ihaBhG8L6KW eY/ZVZXWa9LGr9ldq7SzPO3cCxLNy2vzFT1QEaTBiEkTrB0ZvRbYFEXLtNSwSgw2nMgW D23eee7HnKClh4PJ8E1NMNSQmCh5C2sr0C/3d3K96JK466jB0OMCJunbSxSc7WLTY0E7 1khA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=F9Jspp9RQAdHQY2naC4FkTtsTGkxPnroNycr9wGTC20=; b=lt2lhOu5CPvgHjRIj6M/H2d/xkpTi9Ud22GXY4yb3JfqsuOVL5r9MlD8iV5nEBe6fu m6gfFR7pI7Kp+zorZtdsIw0T4RWsN4taPMYVqrojzBAAiWeEvEPH0PiiSXeiwBBOpxU6 X6WhpHv04Loh8yFlihOoMw7nIRLI4/zvqBBM+56g37L9hwlvBh6gNIixx1114FRUTwx/ CAQR5BNMkNvW2EhhOVNFZn3bmGn3GcI5mJZ6Br1J264nA/TOzxkbdsDKZlVxEKakOA0Z 888/pbjRLN6H9SIJ00qirpOa1S885JXMxxrq7BgI0j+CG/zxHtfTmuNxh3fM3OqddEaE Ya1Q== X-Gm-Message-State: AOUpUlFPy4nlLeM5o8Pa8BMgL0YT0UkHpx4JNuEAXMf/2eqQ31ogZ/nu u/e0GXM14wY39SzMwyLNK+grVSgr X-Google-Smtp-Source: AA+uWPx3M3vsg63kKH+MexMiGV+tBzXh6vfF6J6eklQ9PhYD3srxj2GfZO3BuspmiJF9v+e4qaTvNw== X-Received: by 2002:a1c:1943:: with SMTP id 64-v6mr19958095wmz.89.1534581589793; Sat, 18 Aug 2018 01:39:49 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Sat, 18 Aug 2018 10:39:39 +0200 Message-Id: <20180818083944.19692-5-pbonzini@redhat.com> In-Reply-To: <20180818083944.19692-1-pbonzini@redhat.com> References: <20180818083944.19692-1-pbonzini@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Sat, 18 Aug 2018 08:39:51 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Sat, 18 Aug 2018 08:39:51 +0000 (UTC) for IP:'74.125.82.47' DOMAIN:'mail-wm0-f47.google.com' HELO:'mail-wm0-f47.google.com' FROM:'paolo.bonzini@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.008 (DKIM_SIGNED, DKIM_VALID, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_PASS) 74.125.82.47 mail-wm0-f47.google.com 74.125.82.47 mail-wm0-f47.google.com X-RedHat-Possible-Forgery: Paolo Bonzini X-Scanned-By: MIMEDefang 2.84 on 10.5.110.45 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 4/9] git: remove prepare_series_hook, include result URI in applier-get reply 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Sat, 18 Aug 2018 08:39:57 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_0 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" api.views.prepare_series is only used in two places, the search and applier-get endpoints. Simplify a bit the code by dropping support for the git properties in the search endpoint, and add a result URI that can be used for patchew-cli's applier mode to switch to the REST API. Signed-off-by: Paolo Bonzini --- api/rest.py | 2 +- api/views.py | 4 ---- mods/git.py | 30 +++++++++++++++++------------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/api/rest.py b/api/rest.py index bd46211..646d6ad 100644 --- a/api/rest.py +++ b/api/rest.py @@ -102,7 +102,7 @@ def reverse_detail(obj, request): request=3Drequest, kwargs=3D{"projects_pk": m.p= roject.id, "series_message_id":= m.message_id, - "name": obj.name}), + "name": obj.name}) raise Error("unhandled object type") =20 # pluggable field for plugin support diff --git a/api/views.py b/api/views.py index 7a37481..f2262b6 100644 --- a/api/views.py +++ b/api/views.py @@ -168,8 +168,6 @@ def prepare_series(request, s, fields=3DNone): r["subject"] =3D s.subject if want_field("project"): r["project"] =3D s.project.name - if want_field("project.git"): - r["project.git"] =3D s.project.git if want_field("message-id"): r["message-id"] =3D s.message_id if want_field("patches"): @@ -178,8 +176,6 @@ def prepare_series(request, s, fields=3DNone): r["properties"] =3D s.get_properties() if want_field("is_complete"): r["is_complete"] =3D s.is_complete - dispatch_module_hook("prepare_series_hook", request=3Drequest, series= =3Ds, - response=3Dr) if fields: r =3D dict([(k, v) for k, v in r.items() if k in fields]) return r diff --git a/mods/git.py b/mods/git.py index 924547a..97db081 100644 --- a/mods/git.py +++ b/mods/git.py @@ -19,7 +19,7 @@ from django.utils.html import format_html from mod import PatchewModule from event import declare_event, register_handler, emit_event from api.models import Message, MessageProperty, Project, Result -from api.rest import PluginMethodField +from api.rest import PluginMethodField, reverse_detail from api.views import APILoginRequiredView, prepare_series from patchew.logviewer import LogView from schema import * @@ -218,16 +218,6 @@ class GitModule(PatchewModule): r =3D base.git_result return r if r and r.data.get("repo") else None =20 - def prepare_series_hook(self, request, series, response): - po =3D series.project - for prop in ["git.push_to", "git.public_repo", "git.url_template"]: - if po.get_property(prop): - response[prop] =3D po.get_property(prop) - base =3D self.get_base(series) - if base: - response["git.repo"] =3D base.data["repo"] - response["git.base"] =3D base.data["tag"] - def _poll_project(self, po): repo, branch =3D self._get_project_repo_and_branch(po) cache_repo =3D self._update_cache_repo(po.name, repo, branch) @@ -263,8 +253,22 @@ class ApplierGetView(APILoginRequiredView): =20 def handle(self, request): m =3D Message.objects.filter(results__name=3D"git", results__statu= s=3D"pending").first() - if m: - return prepare_series(request, m) + if not m: + return None + + response =3D prepare_series(request, m, fields=3D["project", "mess= age-id", "patches", "properties"]) + + po =3D m.project + for prop in ["git.push_to", "git.public_repo", "git.url_template"]: + if po.get_property(prop): + response[prop] =3D po.get_property(prop) + base =3D _instance.get_base(m) + if base: + response["git.repo"] =3D base.data["repo"] + response["git.base"] =3D base.data["tag"] + response["project.git"] =3D po.git + response["result_uri"] =3D reverse_detail(m.git_result, request) + return response =20 class ApplierReportView(APILoginRequiredView): name =3D "applier-report" --=20 2.17.1 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel From nobody Fri Mar 29 06:55:35 2024 Delivered-To: importer@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; dkim=fail; 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1534581598419488.90214853993507; Sat, 18 Aug 2018 01:39:58 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3DA53308A953; Sat, 18 Aug 2018 08:39:57 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 277AF101F94C; Sat, 18 Aug 2018 08:39:57 +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 186DF4BB78; Sat, 18 Aug 2018 08:39:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w7I8dtC6013229 for ; Sat, 18 Aug 2018 04:39:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 918BB17DFB; Sat, 18 Aug 2018 08:39:55 +0000 (UTC) Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8646D608E5 for ; Sat, 18 Aug 2018 08:39:53 +0000 (UTC) Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8B99B3DE3D for ; Sat, 18 Aug 2018 08:39:52 +0000 (UTC) Received: by mail-wm0-f66.google.com with SMTP id i134-v6so3076010wmf.0 for ; Sat, 18 Aug 2018 01:39:52 -0700 (PDT) Received: from donizetti.lan (dynamic-adsl-78-12-184-244.clienti.tiscali.it. [78.12.184.244]) by smtp.gmail.com with ESMTPSA id j39-v6sm4830677wre.44.2018.08.18.01.39.49 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 18 Aug 2018 01:39:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=2bvch3jeGdg3kMKv1GTLzRgVLdheS1DBdveTdYPxmWI=; b=OdvbIXnzDWN37HBPYHERq5ov3zofzYC+q5nWgynIawysE0oN75QFC8paPvQJYulBtO DMzpSVfCcTsedr1c6nRqY7IhNxYBWHysfd7MPL83/yJDlLGgH8LrsiHzDArsIQ0b64eq b2GBmZat7u0StIV7aZeO/X5qtj28Kbf1KIMsOYZVdJIC1hql2QJJ/iheIBq0p754GNS0 rDoaEzQi7zMCObNa2eEMmQuyMKyCUc4405vbw41brHaBDO/pMB43fMG2grq+izrl8qg4 QiHyLNPbfe60j82WppyBCFehcbnfcTMlZgjdx/aHrorD3Nwnxn6VsBwE3Led8966JChA KKsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=2bvch3jeGdg3kMKv1GTLzRgVLdheS1DBdveTdYPxmWI=; b=bAhQBUStYOAYN2BxzC4Vk4S+L+7ny7P7x5tSQxkHFEwmjiyP3HHyFP/WDl00PaVOzg duAPiGBTBAiD6PkjpbhkD+nE0P+oDGB7bir8KgzLG+E2TAR8NggpK+hiisgfsablI9Od aPLeTTuYYDyBmddr91hdvHBCyxQ+/sdaE1GfymMnO641PBRX0IiiTfOX7mgtVoOs2GvN Nk928dmskc0c807f2oyUQjivMw6i3qp2+QG2hjv5us1mRMVuEHJYWcqeK4HIXrqA9mXF 6/84aFgIajbzv2lR5Julzl2R9BKAVX1lTvhjZLgiHIOrY/gXP/iwquiIhxgzdEP8qzPH CIqw== X-Gm-Message-State: AOUpUlGULNeJGlQ4m7OYD0d/rHJWLOEBL6kIK4soDOt9s8spnosJ4fC2 hrUXNP2W1RduMu1jCNeIxLjd+3lv X-Google-Smtp-Source: AA+uWPxkMtbQpDDwhwh+rMShesi3xusAVtPBN+LbZN2wNbsdGdlzh4yTeBFlQNDgopAzwdcI11Eg9g== X-Received: by 2002:a1c:2d54:: with SMTP id t81-v6mr22066792wmt.31.1534581591032; Sat, 18 Aug 2018 01:39:51 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Sat, 18 Aug 2018 10:39:40 +0200 Message-Id: <20180818083944.19692-6-pbonzini@redhat.com> In-Reply-To: <20180818083944.19692-1-pbonzini@redhat.com> References: <20180818083944.19692-1-pbonzini@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sat, 18 Aug 2018 08:39:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sat, 18 Aug 2018 08:39:52 +0000 (UTC) for IP:'74.125.82.66' DOMAIN:'mail-wm0-f66.google.com' HELO:'mail-wm0-f66.google.com' FROM:'paolo.bonzini@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.028 (DKIM_SIGNED, DKIM_VALID, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 74.125.82.66 mail-wm0-f66.google.com 74.125.82.66 mail-wm0-f66.google.com X-RedHat-Possible-Forgery: Paolo Bonzini X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 5/9] rest: simplify PatchewPermission 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Sat, 18 Aug 2018 08:39:57 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_0 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Because has_permission is always invoked before has_object_permission, and both must pass for the request to be allowed, it is not necessary to check obj.project.maintained_by for messages. Signed-off-by: Paolo Bonzini --- api/rest.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/api/rest.py b/api/rest.py index 646d6ad..2b0b611 100644 --- a/api/rest.py +++ b/api/rest.py @@ -48,9 +48,6 @@ class PatchewPermission(permissions.BasePermission): def has_project_permission(self, request, view, obj): return obj.maintained_by(request.user) =20 - def has_message_permission(self, request, view, obj): - return obj.project.maintained_by(request.user) - def has_group_permission(self, request, view): for grp in request.user.groups.all(): if grp.name in self.allowed_groups: @@ -68,11 +65,12 @@ class PatchewPermission(permissions.BasePermission): self.has_project_permission(request, view, view.project)) =20 def has_object_permission(self, request, view, obj): + # For non-project objects, has_project_permission has been evaluat= ed + # already in has_permission, based on the primary key included in = the + # URL. return self.has_generic_permission(request, view) or \ - (isinstance(obj, Message) and \ - self.has_message_permission(request, view, obj)) or \ - (isinstance(obj, Project) and \ - self.has_project_permission(request, view, obj)) + not isinstance(obj, Project) or \ + self.has_project_permission(request, view, obj) =20 class ImportPermission(PatchewPermission): allowed_groups =3D ('importers',) --=20 2.17.1 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel From nobody Fri Mar 29 06:55:35 2024 Delivered-To: importer@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; dkim=fail; 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1534581753626423.8108722407728; Sat, 18 Aug 2018 01:42:33 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 532F65D691; Sat, 18 Aug 2018 08:42:32 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 43783951DB; Sat, 18 Aug 2018 08:42:32 +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 350804A460; Sat, 18 Aug 2018 08:42:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w7I8duLd013244 for ; Sat, 18 Aug 2018 04:39:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id 489883091323; Sat, 18 Aug 2018 08:39:56 +0000 (UTC) Received: from mx1.redhat.com (ext-mx17.extmail.prod.ext.phx2.redhat.com [10.5.110.46]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4121E309128B for ; Sat, 18 Aug 2018 08:39:54 +0000 (UTC) Received: from mail-wm0-f52.google.com (mail-wm0-f52.google.com [74.125.82.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6E3943082DD4 for ; Sat, 18 Aug 2018 08:39:53 +0000 (UTC) Received: by mail-wm0-f52.google.com with SMTP id i134-v6so3076032wmf.0 for ; Sat, 18 Aug 2018 01:39:53 -0700 (PDT) Received: from donizetti.lan (dynamic-adsl-78-12-184-244.clienti.tiscali.it. [78.12.184.244]) by smtp.gmail.com with ESMTPSA id j39-v6sm4830677wre.44.2018.08.18.01.39.51 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 18 Aug 2018 01:39:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=sgwU6plkfp8tyWtmbhkZ43DZJsiBnfRqhGQh8tXFyXA=; b=fm5VuVlQquMLbwUJrDp7SiQkw9XWYuvLH9/Px3apTK8DjXy1dVujGmFtvuuSBiSrCe Co53W1y2u63NSglB1fOO2MPDvRievyYWAmqRJGqm9YNJ6C0gnqxevhy3CUsEwyLl5WHe AL7r4uyJD26A65b5JkwMuZNnIWBqY73DFRlPCNt0W/MPMY2KnLn1mkF/HzaX2d9ajNl3 wZS22HsoQ7holZELOw6W30Sg74gAv/tgnfIek2qszOtVB8nXvHqj7Qg7ktINuGPLGmfu HPdBT82iUZT1hWCP+EtIgN4NM5B2tWILMvBgoPJk7/uRW4VUau4sVjTJNt7RLybGlzd2 3bNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=sgwU6plkfp8tyWtmbhkZ43DZJsiBnfRqhGQh8tXFyXA=; b=Sku5DhEyhu1PmtSKWDDeRchX3ieE4RGvEQfVnY3yOWhrxPXwkThKPNFLBcLb2hnJwt 7zzkAuDWtxq+S3/KPSd9Hqo/2MDzHhs+HyDDafUm37LgFLglBpaXilxq3b2hHhULz7Yi np7517Ia01ihH1Mog2Srco/OGDRG5Ld2jW/82PVx4vVvwoqYF9WpV9jQR3c5XpbrzOJ/ Yv79N133F8b26gZnmQCCLvTKARmMl4N89BOFaF20ZeIW34oyfG7W6AxNVS8VlJig+8te kGwiFTg0QBDG6f1YnbAdD36/RjTwyB7AUDDeyZhCYSwQk//rQCQUhMPkJE0ziqnydSVO GZZQ== X-Gm-Message-State: AOUpUlEz4OJouNm8UnFb0UXFwi45i7GzH3FDnK3ivsAplaeVpuU3NDQ8 SaoIa5NjYn4Yrxpetay2dZN8cBOF X-Google-Smtp-Source: AA+uWPxMji1ZS61wEbZOvI7OvJldqcRXw3bM1VaGLXs3b40kJRm9au6M4fJujCDl+JT1ZlKH3NyBKg== X-Received: by 2002:a1c:e708:: with SMTP id e8-v6mr21233624wmh.134.1534581591933; Sat, 18 Aug 2018 01:39:51 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Sat, 18 Aug 2018 10:39:41 +0200 Message-Id: <20180818083944.19692-7-pbonzini@redhat.com> In-Reply-To: <20180818083944.19692-1-pbonzini@redhat.com> References: <20180818083944.19692-1-pbonzini@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Sat, 18 Aug 2018 08:39:53 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Sat, 18 Aug 2018 08:39:53 +0000 (UTC) for IP:'74.125.82.52' DOMAIN:'mail-wm0-f52.google.com' HELO:'mail-wm0-f52.google.com' FROM:'paolo.bonzini@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.028 (DKIM_SIGNED, DKIM_VALID, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 74.125.82.52 mail-wm0-f52.google.com 74.125.82.52 mail-wm0-f52.google.com X-RedHat-Possible-Forgery: Paolo Bonzini X-Scanned-By: MIMEDefang 2.84 on 10.5.110.46 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 6/9] rest: fix get_serializer_context for /projects/ID/{messages, series} 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Sat, 18 Aug 2018 08:42:32 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_0 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" A raise was exchanged with return here, so that a 404 was not reported. In addition, for cleanliness, base the context on the superclass implementation so that format and view are included in the context. Signed-off-by: Paolo Bonzini --- api/rest.py | 6 ++++-- tests/test_rest.py | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/api/rest.py b/api/rest.py index 2b0b611..df0640a 100644 --- a/api/rest.py +++ b/api/rest.py @@ -251,8 +251,10 @@ class ProjectMessagesViewSetMixin(mixins.RetrieveModel= Mixin): =20 def get_serializer_context(self): if self.project is None: - return Http404 - return {'project': self.project, 'request': self.request} + raise Http404 + context =3D super(ProjectMessagesViewSetMixin, self).get_serialize= r_context() + context['project'] =3D self.project + return context =20 # Series =20 diff --git a/tests/test_rest.py b/tests/test_rest.py index 980d61a..7b035bc 100755 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -230,7 +230,7 @@ class RestTest(PatchewTestCase): self.assertEqual(resp.data['count'], 2) =20 resp =3D self.api_client.get(self.REST_BASE + 'projects/12345/seri= es/') - self.assertEqual(resp.data['count'], 0) + self.assertEqual(resp.status_code, 404) =20 def test_series_results_list(self): resp1 =3D self.apply_and_retrieve('0001-simple-patch.mbox.gz', @@ -263,9 +263,9 @@ class RestTest(PatchewTestCase): self.assertEqual('patches' in resp.data['results'][1], False) =20 resp =3D self.api_client.get(self.REST_BASE + 'projects/12345/seri= es/?q=3Dquorum') - self.assertEqual(resp.data['count'], 0) + self.assertEqual(resp.status_code, 404) resp =3D self.api_client.get(self.REST_BASE + 'projects/12345/seri= es/?q=3Dproject:QEMU') - self.assertEqual(resp.data['count'], 0) + self.assertEqual(resp.status_code, 404) =20 def test_series_delete(self): test_message_id =3D '1469192015-16487-1-git-send-email-berrange@re= dhat.com' --=20 2.17.1 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel From nobody Fri Mar 29 06:55:35 2024 Delivered-To: importer@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; dkim=fail; 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1534581600702151.2525882647285; Sat, 18 Aug 2018 01:40:00 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5D9F0356C1; Sat, 18 Aug 2018 08:39:59 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4BF8F70C58; Sat, 18 Aug 2018 08:39:59 +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 3E10D4BB78; Sat, 18 Aug 2018 08:39:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w7I8duww013245 for ; Sat, 18 Aug 2018 04:39:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id 490E93091324; Sat, 18 Aug 2018 08:39:56 +0000 (UTC) Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 41AD63091322 for ; Sat, 18 Aug 2018 08:39:56 +0000 (UTC) Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A85C44E34A for ; Sat, 18 Aug 2018 08:39:54 +0000 (UTC) Received: by mail-wr1-f52.google.com with SMTP id c13-v6so8924670wrt.1 for ; Sat, 18 Aug 2018 01:39:54 -0700 (PDT) Received: from donizetti.lan (dynamic-adsl-78-12-184-244.clienti.tiscali.it. [78.12.184.244]) by smtp.gmail.com with ESMTPSA id j39-v6sm4830677wre.44.2018.08.18.01.39.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 18 Aug 2018 01:39:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=71f3+hNVbiCnyNatYyasjMJOydujZnAidsHMnMxv6u8=; b=URDYirzOGtuCrj3dBW33MF0zPHWzYjN0T/fleNAEwZlgT4Qd8fPpwBKHaycM21g+PT T5vnlD/cnAKNwZcVnyDlPg8ZCUYUTNEznMAZDnF69M6QQPYYwZQH8UeVpQvP1qSjWbNr oqyAi29A7p8EyyDkVT6C0QVdpxX/yuZwSnXSVzNZ4agmITdk9+jHP/WXrgT4aseH/MWq kDQdhX9KXiXyUJaa3fMjsEOvlmPiTqAA+PK/4aEi4/ptIn/6XiZDP1Hyfzw90QK47KN/ ztnfWiXc3gIAspM9dljLUrjWA9Jc0hlYUBQS4RvwuiZnGxHaOpZKYer0EH6TvzKxOMgZ ajKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=71f3+hNVbiCnyNatYyasjMJOydujZnAidsHMnMxv6u8=; b=DVvdtn2iEz11FobH1LIk9LsfjansUQrv6hOo4igzL5gH1whIwhND9cCjM8RvuggKJI jz2areiY5CjwzBtHUN3XavSXLNHhliM6iAAg64rhRk5M8xTSgq6dbJz3xgVazqyT5eaz vzG8sd1WnPWBgyAO+b5JMVwTiPPmZnrpc2sPYYAxhYKrVE5R/0Uz/8jliKcuO8cf8lnb GRjsPLGelxU52l4BtVwowIepecVxwc21dadxDc8NdYxAfesLl3bdIkI3MakniNyKyCDO DSbD5ojxGrQKuRGJWhcHtXeXfHT/oH9Tw69j6IY8A/LRy2OQeGNTAmaTGxZHcR0hBass vt9g== X-Gm-Message-State: AOUpUlEj9Rgm56K++N1mXZHlC+il3skCRPwO5akz1VHI2zES21a7sNQB DwfjEreOLK3yKgcq5X1G0UWooZ6U X-Google-Smtp-Source: AA+uWPyCtr0Vg0zKN1aRBxfa+2fjpiZSivL17WFvgBcurT2Eo1T199raZ3nkWEAzXfT7rIJC5CPzbA== X-Received: by 2002:adf:8385:: with SMTP id 5-v6mr24057369wre.13.1534581593150; Sat, 18 Aug 2018 01:39:53 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Sat, 18 Aug 2018 10:39:42 +0200 Message-Id: <20180818083944.19692-8-pbonzini@redhat.com> In-Reply-To: <20180818083944.19692-1-pbonzini@redhat.com> References: <20180818083944.19692-1-pbonzini@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Sat, 18 Aug 2018 08:39:55 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Sat, 18 Aug 2018 08:39:55 +0000 (UTC) for IP:'209.85.221.52' DOMAIN:'mail-wr1-f52.google.com' HELO:'mail-wr1-f52.google.com' FROM:'paolo.bonzini@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.009 (DKIM_SIGNED, DKIM_VALID, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS) 209.85.221.52 mail-wr1-f52.google.com 209.85.221.52 mail-wr1-f52.google.com X-RedHat-Possible-Forgery: Paolo Bonzini X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-loop: patchew-devel@redhat.com Cc: Shubham Jain Subject: [Patchew-devel] [PATCH 7/9] rest: add support for PUT of result objects 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: , MIME-Version: 1.0 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sat, 18 Aug 2018 08:39:59 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_0 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Shubham Jain This lets one use the REST API for the functionality of the old testing-rep= ort and applier-report endpoints. Signed-off-by: Shubham Jain Signed-off-by: Paolo Bonzini --- api/rest.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- mods/git.py | 12 +++++++++++- mods/testing.py | 10 +++++++++- 3 files changed, 67 insertions(+), 4 deletions(-) diff --git a/api/rest.py b/api/rest.py index df0640a..22d7c98 100644 --- a/api/rest.py +++ b/api/rest.py @@ -25,6 +25,9 @@ from rest_framework.response import Response import rest_framework from mbox import addr_db_to_rest, MboxMessage from rest_framework.parsers import JSONParser, BaseParser +from rest_framework.exceptions import ValidationError +import re +import mod =20 SEARCH_PARAM =3D 'q' =20 @@ -54,6 +57,12 @@ class PatchewPermission(permissions.BasePermission): return True return False =20 + def has_result_group_permission(self, request, view, result_renderer): + for grp in request.user.groups.all(): + if grp.name in result_renderer.allowed_groups: + return True + return False + def has_generic_permission(self, request, view): return (request.method in permissions.SAFE_METHODS) or \ self.is_superuser(request) or \ @@ -62,7 +71,9 @@ class PatchewPermission(permissions.BasePermission): def has_permission(self, request, view): return self.has_generic_permission(request, view) or \ (hasattr(view, 'project') and view.project and \ - self.has_project_permission(request, view, view.project)) + self.has_project_permission(request, view, view.project)) = or \ + (hasattr(view, 'result_renderer') and view.result_renderer = and \ + self.has_result_group_permission(request, view, view.resul= t_renderer)) =20 def has_object_permission(self, request, view, obj): # For non-project objects, has_project_permission has been evaluat= ed @@ -478,6 +489,7 @@ class ResultSerializer(serializers.ModelSerializer): class Meta: model =3D Result fields =3D ('resource_uri', 'name', 'status', 'last_update', 'data= ', 'log_url') + read_only_fields =3D ('name', 'last_update', ) =20 resource_uri =3D HyperlinkedResultField(view_name=3D'results-detail') log_url =3D SerializerMethodField(required=3DFalse) @@ -487,21 +499,54 @@ class ResultSerializer(serializers.ModelSerializer): request =3D self.context['request'] return obj.get_log_url(request) =20 + def validate(self, data): + data_serializer_class =3D self.context['renderer'].result_data_ser= ializer_class + data_serializer_class(data=3Ddata['data'], + context=3Dself.context).is_valid(raise_excep= tion=3DTrue) + return data + class ResultSerializerFull(ResultSerializer): class Meta: model =3D Result fields =3D ResultSerializer.Meta.fields + ('log',) + read_only_fields =3D ResultSerializer.Meta.read_only_fields =20 # The database field is log_xz, so this is needed here log =3D CharField(required=3DFalse) =20 class ResultsViewSet(mixins.ListModelMixin, mixins.RetrieveModelMixin, - viewsets.GenericViewSet): + mixins.UpdateModelMixin, viewsets.GenericViewSet): lookup_field =3D 'name' lookup_value_regex =3D '[^/]+' filter_backends =3D (filters.OrderingFilter,) ordering_fields =3D ('name',) ordering =3D ('name',) + permission_classes =3D (PatchewPermission, ) + + # for permissions + @property + def project(self): + if hasattr(self, '__project'): + return self.__project + try: + self.__project =3D Project.objects.get(id=3Dself.kwargs['proje= cts_pk']) + except: + self.__project =3D None + return self.__project + + @property + def result_renderer(self): + try: + found =3D re.match("^[^.]*", self.kwargs['name']) + except: + return None + return mod.get_module(found.group(0)) if found else None + + def get_serializer_context(self): + context =3D super(ResultsViewSet, self).get_serializer_context() + if 'name' in self.kwargs: + context['renderer'] =3D self.result_renderer + return context =20 def get_serializer_class(self, *args, **kwargs): if self.lookup_field in self.kwargs: diff --git a/mods/git.py b/mods/git.py index 97db081..267546a 100644 --- a/mods/git.py +++ b/mods/git.py @@ -23,6 +23,8 @@ from api.rest import PluginMethodField, reverse_detail from api.views import APILoginRequiredView, prepare_series from patchew.logviewer import LogView from schema import * +from rest_framework import serializers +from rest_framework.fields import CharField =20 _instance =3D None =20 @@ -42,11 +44,19 @@ class GitLogViewer(LogView): raise Http404("Object not found: " + series) return obj.git_result =20 +class DataSerializer(serializers.Serializer): + base =3D CharField() + + # TODO: should be present iff the result is a success + repo =3D CharField(required=3DFalse) + url =3D CharField(required=3DFalse) + tag =3D CharField(required=3DFalse) =20 class GitModule(PatchewModule): """Git module""" name =3D "git" - + allowed_groups =3D ('importers', ) + result_data_serializer_class =3D DataSerializer project_property_schema =3D \ ArraySchema("git", desc=3D"Configuration for git module", members=3D[ diff --git a/mods/testing.py b/mods/testing.py index ecd63d1..98216d4 100644 --- a/mods/testing.py +++ b/mods/testing.py @@ -25,6 +25,8 @@ from api.search import SearchEngine from event import emit_event, declare_event, register_handler from patchew.logviewer import LogView from schema import * +from rest_framework import serializers +from rest_framework.fields import CharField, BooleanField =20 _instance =3D None =20 @@ -47,12 +49,18 @@ class TestingLogViewer(LogView): raise Http404("Object not found: " + project_or_series) return _instance.get_testing_result(obj, testing_name) =20 +class DataSerializer(serializers.Serializer): + # TODO: is_timeout should be present iff the result is a failure + is_timeout =3D BooleanField(required=3DFalse) + head =3D CharField() + tester =3D CharField(default=3Dserializers.CurrentUserDefault()) =20 class TestingModule(PatchewModule): """Testing module""" =20 name =3D "testing" - + allowed_groups =3D ('testers', ) + result_data_serializer_class =3D DataSerializer test_schema =3D \ ArraySchema("{name}", "Test", desc=3D"Test spec", members=3D[ --=20 2.17.1 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel From nobody Fri Mar 29 06:55:35 2024 Delivered-To: importer@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; dkim=fail; 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 153458160250060.03853359595621; Sat, 18 Aug 2018 01:40:02 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1DC5737E80; Sat, 18 Aug 2018 08:40:01 +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 08510951D5; Sat, 18 Aug 2018 08:40:01 +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 F1C0B180613A; Sat, 18 Aug 2018 08:40:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w7I8dxJK013289 for ; Sat, 18 Aug 2018 04:39:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id E31F017AEA; Sat, 18 Aug 2018 08:39:59 +0000 (UTC) Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D9AC63790 for ; Sat, 18 Aug 2018 08:39:56 +0000 (UTC) Received: from mail-wm0-f41.google.com (mail-wm0-f41.google.com [74.125.82.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C41DA65878 for ; Sat, 18 Aug 2018 08:39:55 +0000 (UTC) Received: by mail-wm0-f41.google.com with SMTP id o18-v6so9346926wmc.0 for ; Sat, 18 Aug 2018 01:39:55 -0700 (PDT) Received: from donizetti.lan (dynamic-adsl-78-12-184-244.clienti.tiscali.it. [78.12.184.244]) by smtp.gmail.com with ESMTPSA id j39-v6sm4830677wre.44.2018.08.18.01.39.53 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 18 Aug 2018 01:39:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=/f/qOregyE5wKBzEPMXHE9OnzUacRSOFN5cQz3bgjjI=; b=pHyiuG4S8Sj1t9HCSZPacpqDpRYe4dls/qu52cN6mhlxsiO1m0kFIOkbZmY75/U1bD eqHv7VlvbzlDxRuAain4D3vVzRIAxmSC5LZxGBGoELIwByHRbseG+bYlopxR1pkl4Glq LLP0VULmx8PiIF8Qx/pgzYOl4BmQ/3gjmOxSSwrnRxTt9An6+Q93SSOhhMPHPTZ7aHkH csNbRC4rKjzysXxTqo4yXiYhY7CBpgDa1LwjiB/VhRMvgfTKOk3eLM+2XPzU2CX8xVMX 0wlzwpWUnTjBO6PrEHJPYC0ZY9har1wY00qLga/zRd7YmVpb6E1kYZEmmZcp0tLHI9aW xU7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=/f/qOregyE5wKBzEPMXHE9OnzUacRSOFN5cQz3bgjjI=; b=sHZaktpanSru7T1mWPz5FcvG09Jt9zeU9YAHywAfuZvqXwiTGDLvibcPmz5foucFRA CmnXxrcKnxwq40T7p7jOYC3S9ThQtysMPgYjcoKfM50Xa2hN65VK3RSA97k3ZzUDie1F LAyagTpsdYUubFmwm1Za9Le0E3oxvTQGsriIFko9STNJEP8IclNR6uSn7QkzOMTg/MZv WLKzYaePqiYVLFuwUhBiB+pQccvLenXwvee0xtg7peOETRtpJ0cWa3Uu61xKntu07/Dz 6L7WBX7tOVVTD+5BO4zM4+Pmch29EO3MaAcZUv/TNpfFNWTl85XNlm/5o4C2uFT6m97s sGHg== X-Gm-Message-State: AOUpUlGk6Voc+xQLyAbBTXwiEEK+p6/1lIJ2R+dOh7N07kZGXiYgIlxm 6S/naeZuQ048eaaTE4RDWGIvGk4C X-Google-Smtp-Source: AA+uWPyIW+GPSKxkz1eh24sKHwJ8vV44aUNSx0nswRKLTAsj0V7AKxrL7sk1V2uHqjnX55rpwGyqrQ== X-Received: by 2002:a1c:1314:: with SMTP id 20-v6mr20212376wmt.55.1534581594214; Sat, 18 Aug 2018 01:39:54 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Sat, 18 Aug 2018 10:39:43 +0200 Message-Id: <20180818083944.19692-9-pbonzini@redhat.com> In-Reply-To: <20180818083944.19692-1-pbonzini@redhat.com> References: <20180818083944.19692-1-pbonzini@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Sat, 18 Aug 2018 08:39:56 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Sat, 18 Aug 2018 08:39:56 +0000 (UTC) for IP:'74.125.82.41' DOMAIN:'mail-wm0-f41.google.com' HELO:'mail-wm0-f41.google.com' FROM:'paolo.bonzini@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.028 (DKIM_SIGNED, DKIM_VALID, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 74.125.82.41 mail-wm0-f41.google.com 74.125.82.41 mail-wm0-f41.google.com X-RedHat-Possible-Forgery: Paolo Bonzini X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 8/9] rest: add testing capabilities to the projects 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sat, 18 Aug 2018 08:40:01 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_0 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- api/rest.py | 7 +++++++ mods/testing.py | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/api/rest.py b/api/rest.py index 22d7c98..4132e38 100644 --- a/api/rest.py +++ b/api/rest.py @@ -173,6 +173,13 @@ class ProjectSerializer(serializers.HyperlinkedModelSe= rializer): series =3D HyperlinkedIdentityField(view_name=3D'series-list', lookup_= field=3D'pk', lookup_url_kwarg=3D'projects_pk') =20 + def get_fields(self): + fields =3D super(ProjectSerializer, self).get_fields() + request =3D self.context['request'] + dispatch_module_hook("rest_project_fields_hook", request=3Drequest, + fields=3Dfields) + return fields + class ProjectsViewSet(viewsets.ModelViewSet): queryset =3D Project.objects.all().order_by('id') serializer_class =3D ProjectSerializer diff --git a/mods/testing.py b/mods/testing.py index 98216d4..e68ab11 100644 --- a/mods/testing.py +++ b/mods/testing.py @@ -20,7 +20,7 @@ import math from api.views import APILoginRequiredView from api.models import (Message, MessageProperty, MessageResult, Project, ProjectResult, Result) -from api.rest import reverse_detail +from api.rest import PluginMethodField, reverse_detail from api.search import SearchEngine from event import emit_event, declare_event, register_handler from patchew.logviewer import LogView @@ -385,6 +385,12 @@ class TestingModule(PatchewModule): ret[name] =3D v return ret =20 + def get_testing_probes(self, project, request, format): + return self.get_capability_probes(project) + + def rest_project_fields_hook(self, request, fields): + fields['testing_probes'] =3D PluginMethodField(obj=3Dself) + def tester_check_in(self, project, tester): assert project assert tester --=20 2.17.1 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel From nobody Fri Mar 29 06:55:35 2024 Delivered-To: importer@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; dkim=fail; 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1534581753704944.7826588831665; Sat, 18 Aug 2018 01:42:33 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 727823082E06; Sat, 18 Aug 2018 08:42:32 +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 603DF2010CBC; Sat, 18 Aug 2018 08:42:32 +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 51F5118005D0; Sat, 18 Aug 2018 08:42:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w7I8dwD5013269 for ; Sat, 18 Aug 2018 04:39:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2E4FD61F4F; Sat, 18 Aug 2018 08:39:58 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2517462460 for ; Sat, 18 Aug 2018 08:39:58 +0000 (UTC) Received: from mail-wm0-f53.google.com (mail-wm0-f53.google.com [74.125.82.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C7DF681104 for ; Sat, 18 Aug 2018 08:39:56 +0000 (UTC) Received: by mail-wm0-f53.google.com with SMTP id t25-v6so9271908wmi.3 for ; Sat, 18 Aug 2018 01:39:56 -0700 (PDT) Received: from donizetti.lan (dynamic-adsl-78-12-184-244.clienti.tiscali.it. [78.12.184.244]) by smtp.gmail.com with ESMTPSA id j39-v6sm4830677wre.44.2018.08.18.01.39.54 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 18 Aug 2018 01:39:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=e6+NcYNJNyz0PrItj1ZM5Zs96sFlnJg4VqCwTGsvlNg=; b=bl7QNv+KcQJ/89XPNuzqogaapDpMYCCIykcpGkFC7nmK6iOuLn6eOkHr0B4/v5hYnD u6nMGY0Peqqf1jZzZWyuhRyRmTFWNBFp5yAm09/gCRgPemAi2Upwdhtp85qFQt67/o6W Xgn8klBwZe/O0JuEvYiqDF6Vk8FR0SUXkgNxq/SoQqiKaG4TIsTaMRKTbbfvbO74u7Rv yRnq9zklJDc2HSo1eloegc5KAoj64sFIihPmP2df43jkLZ5qshoQ3sPjq07BLa0WxFkF fXXI1/rP1cj8dVwKgIPB7Dn457k4z1N/iEePr5a8n7S31H2trSuDaXXPzKNA4RmJ90hF 2A0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=e6+NcYNJNyz0PrItj1ZM5Zs96sFlnJg4VqCwTGsvlNg=; b=P7j2f02EDIubrRcpZYh5GwYyqNPrcvnyWAw8NH2PKw2dz/zLemMxtFJ4IzDgL2CW4Q cSQco+dkUeFmzu3HciEm0u26onep7CKjXZSbzIDt2bfF/iXNj4OEUAvL4aH4As5zX10L QMa2Fby6prQDkdyfSdi5zD+DVK7Gjmixfp9HKrPD4QiadsmVkM+tcUgkw+lh2XAPo3n+ Ew1hpsHvWWI4aOnGaJPxyg1Nn/1nC0EWbOwGqFAyaR5XH1TWy8CZqhk3oE956KQvlClV PtGwlxjcYj9r/W659YQVjhHlSn85nwfEmAyvzW0b2MMcCsH5gXjfejov+J/DuS1rlX7l PdWw== X-Gm-Message-State: AOUpUlFDG6SgzL9KfEfEoMa3k73M5pNQrsgrCuNMiU96b7eqBsHr83+f Qx+9W3IPhX46HJEAe7EPmDI5S7Hu X-Google-Smtp-Source: AA+uWPydWordzsU7Sgp+qH3DZXldt494GAKLkf3jWuVe3rBRPsr+XasOzjL5fnFA/MxdVuk8L653kg== X-Received: by 2002:a1c:8f50:: with SMTP id r77-v6mr21425842wmd.44.1534581595306; Sat, 18 Aug 2018 01:39:55 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Sat, 18 Aug 2018 10:39:44 +0200 Message-Id: <20180818083944.19692-10-pbonzini@redhat.com> In-Reply-To: <20180818083944.19692-1-pbonzini@redhat.com> References: <20180818083944.19692-1-pbonzini@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sat, 18 Aug 2018 08:39:57 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sat, 18 Aug 2018 08:39:57 +0000 (UTC) for IP:'74.125.82.53' DOMAIN:'mail-wm0-f53.google.com' HELO:'mail-wm0-f53.google.com' FROM:'paolo.bonzini@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.028 (DKIM_SIGNED, DKIM_VALID, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 74.125.82.53 mail-wm0-f53.google.com 74.125.82.53 mail-wm0-f53.google.com X-RedHat-Possible-Forgery: Paolo Bonzini X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 9/9] rest: add ability to look up projects by name 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Sat, 18 Aug 2018 08:42:32 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_0 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Compared to Shubham's patch, this uses a redirect instead of a GET argument on the collection. This approach could be extended in the future to request methods other than GET. Signed-off-by: Paolo Bonzini --- api/rest.py | 12 +++++++++++- api/urls.py | 1 + tests/test_rest.py | 8 ++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/api/rest.py b/api/rest.py index 4132e38..bf45125 100644 --- a/api/rest.py +++ b/api/rest.py @@ -10,7 +10,7 @@ =20 from collections import OrderedDict from django.contrib.auth.models import User -from django.http import Http404 +from django.http import Http404, HttpResponseRedirect from django.template import loader =20 from mod import dispatch_module_hook @@ -206,6 +206,16 @@ class ProjectsViewSet(viewsets.ModelViewSet): project.project_head =3D request.data['new_head'] return Response({"new_head": project.project_head, "count": ret}) =20 +class ProjectsByNameViewSet(viewsets.GenericViewSet): + queryset =3D Project.objects.all().order_by('id') + permission_classes =3D (PatchewPermission,) + lookup_field =3D 'name' + + def retrieve(self, request, *args, **kwargs): + instance =3D self.get_object() + url =3D reverse_detail(instance, request) + return HttpResponseRedirect(url, status=3Dstatus.HTTP_307_TEMPORAR= Y_REDIRECT) + # Common classes for series and messages =20 class HyperlinkedMessageField(HyperlinkedIdentityField): diff --git a/api/urls.py b/api/urls.py index 2fd4e0f..2d95328 100644 --- a/api/urls.py +++ b/api/urls.py @@ -30,6 +30,7 @@ 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 diff --git a/tests/test_rest.py b/tests/test_rest.py index 7b035bc..8c86d9d 100755 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -86,6 +86,14 @@ class RestTest(PatchewTestCase): self.assertEquals(resp.data['mailing_list'], "qemu-block@nongnu.or= g") self.assertEquals(resp.data['parent_project'], self.PROJECT_BASE) =20 + def test_project_by_name(self): + resp =3D self.api_client.get(self.REST_BASE + 'projects/by-name/QE= MU/') + self.assertEquals(resp.status_code, 307) + resp =3D self.api_client.get(resp['Location']) + 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") + def test_update_project_head(self): resp =3D self.apply_and_retrieve('0001-simple-patch.mbox.gz', self.p.id, '20160628014747.20971-1-= famz@redhat.com') --=20 2.17.1 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel