From nobody Thu Mar 28 20:21:57 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 153460144720472.36842307715324; Sat, 18 Aug 2018 07:10:47 -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 AB13A3084216; Sat, 18 Aug 2018 14:10:42 +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 981E9709E5; Sat, 18 Aug 2018 14:10:42 +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 7FE3E4A460; Sat, 18 Aug 2018 14:10:42 +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 w7IEAepL020399 for ; Sat, 18 Aug 2018 10:10:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id C137F308BDA2; Sat, 18 Aug 2018 14:10:40 +0000 (UTC) Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B8181308BDA0 for ; Sat, 18 Aug 2018 14:10:38 +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 72943C049E0F for ; Sat, 18 Aug 2018 14:10:37 +0000 (UTC) Received: by mail-wm0-f66.google.com with SMTP id y9-v6so9830596wma.5 for ; Sat, 18 Aug 2018 07:10:37 -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 g2-v6sm13874652wrd.71.2018.08.18.07.10.34 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 18 Aug 2018 07:10:35 -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=lSuokkjRt+cYuItR+EKJPwUD4p1ys6Mu/dAUXdpiOlg=; b=IQT/JzYlCmhD7LWk5XlrHzMAkumFGGYxvKL7U5UN6y3Mmu1lGZ0rdaV08PwLjGKcvJ 7/0bz1IdSJ2Kc9+oF7LuhgPMiDEDhLef3ag0YWl3srKSATaGV3Jebh3XhvKa/hxuK9IU K6+NZzcKvpVnhPeis5NVpuQTpMloeJmXeNAF1CWyDh8TiA2KnCpB5lN5crfbAU6mXQop fnoby/WJEMoDBdevoZhksXxyjXQ8ihA2YL1U8qBn+mgCrdqLl7MA282O2zZxD/VKr4za wAU/s3QQCwOAYIfnCptaIPQm+614fBpz60eMUOydDnU+bx33DTjZ0zE6wilswyLAk3oo iG3g== 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=lSuokkjRt+cYuItR+EKJPwUD4p1ys6Mu/dAUXdpiOlg=; b=p475G1ETzkjC8TyGtvtLm0KRVMZ0DFQJNgnmNm+7klwkesEjJf/n17shKSOS1g276H SxhrMmL4ryPwQONwBJHWt8GIkFpjpC29cSAYSPeCp6I6kV/jXdX9OeGTOaczpoWQkwp1 rUJpKB43IEEGXxKeT2/eFthtYCpcz+eDFupnRgSwjz9I8Q24BHFJCZJdosynGzY/YwOi 8VX/YevIcyIyaarHN/GGsOZxf58uk4JeduGGKy1ZnjtiPi1IdjecPzFz2ZmZYGRTbLZ9 43EEGWOovJfBac14MxLa00SY1IdIhYWiYPoQpSmYw0fzjJrkzq/YuvIuKwsofH6YTfAQ OwoA== X-Gm-Message-State: AOUpUlEu/AT4Q9GutL+7gxM/sFntBFEE510hmpGIik0nInGxhYn0QymY PubWtCkgeN55ZNmuhTRLdbpf04QC X-Google-Smtp-Source: AA+uWPyjyx41ixDmTk2EbPhAyMpFz4edPKYO9A3lX/6DV2yMVtCJ1ZSx/C2LXwnJHmjCYv3pj2kiiQ== X-Received: by 2002:a1c:e043:: with SMTP id x64-v6mr21564753wmg.58.1534601435849; Sat, 18 Aug 2018 07:10:35 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Sat, 18 Aug 2018 16:10:25 +0200 Message-Id: <20180818141033.29752-2-pbonzini@redhat.com> In-Reply-To: <20180818141033.29752-1-pbonzini@redhat.com> References: <20180818141033.29752-1-pbonzini@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sat, 18 Aug 2018 14:10:37 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sat, 18 Aug 2018 14:10:37 +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.31 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.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.40]); Sat, 18 Aug 2018 14:10:42 +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/migrations/0033_auto_20180803_0809.py | 22 ++++++++++++++++++++++ api/models.py | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 api/migrations/0033_auto_20180803_0809.py diff --git a/api/migrations/0033_auto_20180803_0809.py b/api/migrations/003= 3_auto_20180803_0809.py new file mode 100644 index 0000000..12753cd --- /dev/null +++ b/api/migrations/0033_auto_20180803_0809.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.13 on 2018-08-03 08:09 +from __future__ import unicode_literals + +from django.db import migrations +import jsonfield.encoder +import jsonfield.fields + + +class Migration(migrations.Migration): + + dependencies =3D [ + ('api', '0032_fix_git_results'), + ] + + operations =3D [ + migrations.AlterField( + model_name=3D'result', + name=3D'data', + field=3Djsonfield.fields.JSONField(default=3D{}, dump_kwargs= =3D{'cls': jsonfield.encoder.JSONEncoder, 'separators': (',', ':')}, load_k= wargs=3D{}), + ), + ] 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 Thu Mar 28 20:21:57 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 1534601447294706.2174144613205; Sat, 18 Aug 2018 07:10:47 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DDE25461CE; Sat, 18 Aug 2018 14:10:42 +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 C617A308BDA0; Sat, 18 Aug 2018 14:10:42 +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 B36EF18005D0; Sat, 18 Aug 2018 14:10:42 +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 w7IEAfHa020407 for ; Sat, 18 Aug 2018 10:10:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id BB89361F4F; Sat, 18 Aug 2018 14:10:41 +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 B320B5D6AA for ; Sat, 18 Aug 2018 14:10:39 +0000 (UTC) Received: from mail-wm0-f50.google.com (mail-wm0-f50.google.com [74.125.82.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 5F7D48553D for ; Sat, 18 Aug 2018 14:10:38 +0000 (UTC) Received: by mail-wm0-f50.google.com with SMTP id t25-v6so9752060wmi.3 for ; Sat, 18 Aug 2018 07:10:38 -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 g2-v6sm13874652wrd.71.2018.08.18.07.10.35 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 18 Aug 2018 07:10:36 -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=BW+xF5AVJhEilix1RlFcS46OWuyNEBohGjCdrHIRzo0=; b=XGk1AwD2lW1+CPV1ShBajzYtelpdlgmt/aAapEacLtvvNck9lMIPnQKtAeJ5sRlO8v XntJaQ/hA2GeYXyATPHxlShPbUMVjttKHs+myMcT2qTcWBdYqkIupuSisz261hNrUZZd hkdyMSjpJPCkCq18bFv2BnwTFYZTrD+VT9NCELPR4IAsvHd7X/qZhNSuJ9KMJB5MNPmO z8pNOOeA77nsO6/FpFViDTFwxYbIQ/7bR4Xs8efsoW1YSDhJECNq8A2fdRvNRbXb3gsn Gbkbegzc4WILvXtmEHj9hd7SS+F5p3V2TExtG+ircTYSXuQTu45OkhOSPl4yRwSywsgQ gBpw== 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=BW+xF5AVJhEilix1RlFcS46OWuyNEBohGjCdrHIRzo0=; b=pjnAn4qd95lH6LIpcyT0kCb7aHda+IYF1E6zbPs+GZ05AbvnT5tTonjtuNQdYP9hTQ IM09n2Bg4WD1oqB3pF245K6nbsO/+GBYvlzKzFXtARltvvRHFe1maP6VhajslyA3qQ0W dISiVuJhTATd4VzU//Xvs5pqk5Z1+PROqmbzcaLA08DlyIKU8yTLiLc8PcEZPGmSp3BK L+Z2ryB00yEkBag3R0rWLTobWc7bWnNOGCPQ9dZazXwhmkcQazrI0CyV28mQlZxoRzHb XKkEfiEe+5To7PhKL/eHIwiHsESy/RzdBZOgXOzNiNBk3Kzxc5/gKLbznyrfz4yJBMX6 kixw== X-Gm-Message-State: AOUpUlGo5D0cvlwxtuYH30as3jSuGqKxlmNei7zACbBj/uYB/LtHDisk proTIH3y57QOSbJKEbEERRp4ybvV X-Google-Smtp-Source: AA+uWPwmPmsc4+IdIN/+/mT1rys0XPY/rHs/k86HDzOM2NBMCCq41VnVTxJhPAsSqGdI7DA9SrtTAg== X-Received: by 2002:a1c:99c2:: with SMTP id b185-v6mr19795880wme.15.1534601436809; Sat, 18 Aug 2018 07:10:36 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Sat, 18 Aug 2018 16:10:26 +0200 Message-Id: <20180818141033.29752-3-pbonzini@redhat.com> In-Reply-To: <20180818141033.29752-1-pbonzini@redhat.com> References: <20180818141033.29752-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 14:10:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sat, 18 Aug 2018 14:10:38 +0000 (UTC) for IP:'74.125.82.50' DOMAIN:'mail-wm0-f50.google.com' HELO:'mail-wm0-f50.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.50 mail-wm0-f50.google.com 74.125.82.50 mail-wm0-f50.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 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.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sat, 18 Aug 2018 14:10:42 +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 1284498..5b6420a 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 Thu Mar 28 20:21:57 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 1534601449195136.53301416719535; Sat, 18 Aug 2018 07:10:49 -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 0536D317C40C; Sat, 18 Aug 2018 14:10:48 +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 E80342A162; Sat, 18 Aug 2018 14:10:47 +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 DD1534A460; Sat, 18 Aug 2018 14:10:47 +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 w7IEAjAw020439 for ; Sat, 18 Aug 2018 10:10:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7F99A77359; Sat, 18 Aug 2018 14:10:45 +0000 (UTC) Received: from mx1.redhat.com (ext-mx19.extmail.prod.ext.phx2.redhat.com [10.5.110.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 76A62709E5 for ; Sat, 18 Aug 2018 14:10:42 +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 AB412307D912 for ; Sat, 18 Aug 2018 14:10:39 +0000 (UTC) Received: by mail-wm0-f48.google.com with SMTP id o11-v6so10010568wmh.2 for ; Sat, 18 Aug 2018 07:10:39 -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 g2-v6sm13874652wrd.71.2018.08.18.07.10.36 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 18 Aug 2018 07:10:37 -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=YMCe3eblxwvU2ilPzmukLDzW5a17+1yqDZiGPOI8uz+DiCGC7WynYc5unuzkzk7Lfr EfrveewLY0nup4Za5PHfxXfYloxMukCOowmtlF1TQcSROIt0yVMqS/68f2OeletmUHUC 5MPnHZjjKA4opDq0ze8hoz7CTH/KF/3KTdUxTRrDiYWZvWHnR2yHvF/kjZh3meGqIS+E kkXay6YAydbcEPxFLWl2xbhqTKOkiSPVWChBhxE4KJZp/4Obadd9apoxdv4xBsiotaBT 6X/GJEvjGv6ksq42ivZbg9h/SoynDkCYbu34mUeHpGLXGENh9/t+9OAumFfPOISp929e YDCQ== 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=pMETlO/tCjQnOQQYG8WKHom2hFwacSzsZFl4J+pYlgpZRBWJ4aViI/GzSia75M7Ycx m9o2sFKgh5ldEGnSnQbEJMsxrQY5JbmPalKno6gqyjISI8QXEwLev+QFc3u3XUkAF1FI 0VmYDHshgZZwch8xnnXht1KU0hATK2GG+ZxM77dWIP3eOk3wNXjFmH7iMLZkIfxswVEf Qay2FS97AFcUdQUWJY0tTDUQviHqB1eRrW9RmmzY6xyjtAO/k8TxsvrSN7ep2y2w+Civ JM0sfPKds8gWJPjZnT1EZkw3GoliQx63DgdigGeiNKZNlHN1HAZqwe2fynF7UzTswr2J sLug== X-Gm-Message-State: AOUpUlF5J063RMYSyRjodg5Cn9bB/owXO5hzclsqVc81gpjpt4wYqmLU 7XeosSmeOFRMhM6gPk6EJe9JxnYY X-Google-Smtp-Source: AA+uWPyTFNZIMBpJTZGXqHCwOwhoHw8INTxRx/ckUVFWc3UxOmr6cXzh+VeICsUqT/cPmzE6uhaaNg== X-Received: by 2002:a1c:1a52:: with SMTP id a79-v6mr7459777wma.73.1534601438126; Sat, 18 Aug 2018 07:10:38 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Sat, 18 Aug 2018 16:10:27 +0200 Message-Id: <20180818141033.29752-4-pbonzini@redhat.com> In-Reply-To: <20180818141033.29752-1-pbonzini@redhat.com> References: <20180818141033.29752-1-pbonzini@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Sat, 18 Aug 2018 14:10:40 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Sat, 18 Aug 2018 14:10:40 +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.48 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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.41]); Sat, 18 Aug 2018 14:10:48 +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 Thu Mar 28 20:21:57 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 1534601447125347.86185604310754; Sat, 18 Aug 2018 07:10:47 -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 EAFB7308A973; Sat, 18 Aug 2018 14:10:45 +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 D68BE94418; Sat, 18 Aug 2018 14:10:45 +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 C9387180613A; Sat, 18 Aug 2018 14:10:45 +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 w7IEAikn020424 for ; Sat, 18 Aug 2018 10:10:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id 69A9C103BAB5; Sat, 18 Aug 2018 14:10:44 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5FE35100191B for ; Sat, 18 Aug 2018 14:10:42 +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 D0BB136809 for ; Sat, 18 Aug 2018 14:10:40 +0000 (UTC) Received: by mail-wm0-f47.google.com with SMTP id o18-v6so9827730wmc.0 for ; Sat, 18 Aug 2018 07:10:40 -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 g2-v6sm13874652wrd.71.2018.08.18.07.10.38 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 18 Aug 2018 07:10:38 -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=uetVpY7heZ4uuu1f86K+1wS23TBonZ8zcOw8CyhZgsmx0HBe5uKxYkXbJUdBQh9cLG O/azJYu/m7nS3pYLWMj5Oo0uMe7FWaJGoQh4YNS5yDXXwCfwFp//EDnS4I+amGTWHv/6 EPCLRYwFvnyONG8sQehWqJ+r/tM5ihudqLpOMg7T8IT72P74sfbxx7zJQi55vrIu1u+k byjlDlOZ5v8XgUDLwMPqetZ6I++08EqJbNsYkEGEaM9RkK/7aEydxICYvxgNkP9zCngC o2pLFsjLuhvH8bx/OOZ7DJnuxn+9Dz35FE1guP1gkBk+UXs7hYX6/A5n44HsSCUANq4F lcUg== 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=OjwOPP7tcCB2YqT87ZpmEZWsiFmUTNW+edhDlFeeuJUNtX7Bje1imXhApMr9/1BFql P6qotKRu7rGXyzsAn9y3GIzmPTDN1BRp2F+BQXOaJkJxFfXkFpmi0QpVwR1jiakVMzmD WGNrV0dut178MNluAP2E0s7cI+NlMy0D/zGh0HQZAfgzkWfxef17gBh3ZVYNTt+WUiBJ BA52fOpZIWyPJgyuRGDew3MfgVjgAxiSXXtV2UfMLQ/4tzOXVFMV+6OF8HjUtmAviFnE fS1Jz3WRVrVptK/S1OH+EXTmqwJSyxFvEtxGae8mxbpbR4XZEuMpAKLHzY5v1zFUEbHQ PdCw== X-Gm-Message-State: AOUpUlHtzbHWFaNcJ4aFG5gKux4ubRTgfe07WfnZ8Eauq/7OMBlaIj+a 0lLHo4Ijff7NXL4LcCpmmrp8V99P X-Google-Smtp-Source: AA+uWPxpbjzC6o6LuA+JpL464YBJCtNDacAFfiZrnBAA+az7xWk1ktAJjxBr73rFTk4iC9S9n8xBzw== X-Received: by 2002:a1c:85cb:: with SMTP id h194-v6mr18607200wmd.54.1534601439131; Sat, 18 Aug 2018 07:10:39 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Sat, 18 Aug 2018 16:10:28 +0200 Message-Id: <20180818141033.29752-5-pbonzini@redhat.com> In-Reply-To: <20180818141033.29752-1-pbonzini@redhat.com> References: <20180818141033.29752-1-pbonzini@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sat, 18 Aug 2018 14:10:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sat, 18 Aug 2018 14:10:41 +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.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Sat, 18 Aug 2018 14:10:46 +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 Thu Mar 28 20:21:57 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 1534601723141251.1155827792944; Sat, 18 Aug 2018 07:15:23 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CE13E5F7A1; Sat, 18 Aug 2018 14:15:21 +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 BE9C1600C0; Sat, 18 Aug 2018 14:15:21 +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 AD4B4181A12E; Sat, 18 Aug 2018 14:15:21 +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 w7IEAiQG020429 for ; Sat, 18 Aug 2018 10:10:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id BC8CB608EC; Sat, 18 Aug 2018 14:10:44 +0000 (UTC) Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B35B65F7C2 for ; Sat, 18 Aug 2018 14:10:42 +0000 (UTC) Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) (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 A669083F3C for ; Sat, 18 Aug 2018 14:10:41 +0000 (UTC) Received: by mail-wm0-f68.google.com with SMTP id w24-v6so9766670wmc.1 for ; Sat, 18 Aug 2018 07:10:41 -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 g2-v6sm13874652wrd.71.2018.08.18.07.10.39 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 18 Aug 2018 07:10:39 -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=jChpt3onRp3sGZa4w2zGpW7Z5F88Xp6zJIZjQsbsBMV3Ncg6vApKPEWLrJAWzpNC0L o/fhxib1lS5hLvCkLbxgwhWYc9K1D0jgLnPC15xs6sXiqWDhI13aWhrPfsR+RSY0NQuI VSdYHszIfPke0+IwdED3ZROl6jWqAZ+Lw3cjVVi9LJtfMaMhmRgEk6I9mGmeSC2bkXA3 zt1s2i1e/THuMHr26ob9nYM4hDsD5E5D2dYnxYbR28d2qqA9XyUygtLUAtXdkBJzIe/R RCh1tNo8etSrOf3iA83aIeh5wXJrlPwqOqav7/vCTi+7RMbQY82wrvFjAmmYPJl+xS9H 1QhQ== 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=hTzlpaUjgvFNQxdUZMS3sKfW4YoBe9l69YjlR6zvgHaynB3Kd5FMn9Q3hoeEdkvY9q z+IvGf3EiYWoJT/szfSNtMBZff8wZBP6KvcpLWxDdI3q0z1fJXqnxEPhD/rdRU7sKmm0 eHbRQC6UUtbwZ7tEt14LMRv+2JytewGPWweuErAZtUm+LZXleAUSoOrG9K8KrtOYe7jx 3FCC9XgGHnd890hTvjStJ9vbD6Mo0JA2lG9EY0oH1zAJJ/svEIkoT2jJh9JZsRlHLnjb q/xS+5MlP4KGnGGg7EITEMFhlcLyHNvb/bqf1RyaGhyRJ0EhqMwfdGowXdgF4ljm0o5r ko5w== X-Gm-Message-State: AOUpUlEdYAX+OJxDHzWoK2YZcTcdLQ8xBPpcHM9hkPFxZK24vFS3jLT1 kCSPKk/tbp3t7WYieYDmJF2auCSZ X-Google-Smtp-Source: AA+uWPxm+rj1PX5nqeLYyaEzyZ6uoz7AzLCK78rZKnFTghT3NWaVVcdP8QFL2K2R6hH8s41zNzjtVw== X-Received: by 2002:a1c:8a04:: with SMTP id m4-v6mr20693407wmd.137.1534601440114; Sat, 18 Aug 2018 07:10:40 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Sat, 18 Aug 2018 16:10:29 +0200 Message-Id: <20180818141033.29752-6-pbonzini@redhat.com> In-Reply-To: <20180818141033.29752-1-pbonzini@redhat.com> References: <20180818141033.29752-1-pbonzini@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Sat, 18 Aug 2018 14:10:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Sat, 18 Aug 2018 14:10:41 +0000 (UTC) for IP:'74.125.82.68' DOMAIN:'mail-wm0-f68.google.com' HELO:'mail-wm0-f68.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.68 mail-wm0-f68.google.com 74.125.82.68 mail-wm0-f68.google.com X-RedHat-Possible-Forgery: Paolo Bonzini X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 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.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Sat, 18 Aug 2018 14:15:21 +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 Thu Mar 28 20:21:57 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 1534601449358857.7605270234353; Sat, 18 Aug 2018 07:10:49 -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 15D26C057FA6; Sat, 18 Aug 2018 14:10:48 +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 05D1D100191B; Sat, 18 Aug 2018 14:10:48 +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 EF51F4A465; Sat, 18 Aug 2018 14:10:47 +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 w7IEAkpg020465 for ; Sat, 18 Aug 2018 10:10:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id E5A535E7D1; Sat, 18 Aug 2018 14:10:46 +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 DC69B17CE2 for ; Sat, 18 Aug 2018 14:10:43 +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 A73C43082E06 for ; Sat, 18 Aug 2018 14:10:42 +0000 (UTC) Received: by mail-wm0-f52.google.com with SMTP id y2-v6so10080817wma.1 for ; Sat, 18 Aug 2018 07:10:42 -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 g2-v6sm13874652wrd.71.2018.08.18.07.10.40 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 18 Aug 2018 07:10:40 -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=b+5ul3qFtSo2bFl90QZGMJdvzj+9c8Zsx+tNnre9klYU6NUe1Z1rOHRGNjhmEVk4Z8 aev+p4DKvhItHrWm/qjAOOtLjWv+xeZWiTEreWdaHB3ML9w+Hkdpk6o76UwiQnqV5KwR nxlL9OaJXKy3zsVJdF9EJzyG1MJOUm9ssoWZugcVr5dxxtZl9qbNXax2CWHPyT/UQPMB R8nmfuz5gXRVCCHhDJScIEHB8rmiXWdnAw5uqhoh1U1yOjibxfWTYTpq/vuZTd7T/t4g DisF7sv+VvLQ3zVqedekt5JjZO81Y8a80Lj2CMTQsF0jWhqpgKQWtmCLMUajmYkbNaal y6lQ== 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=JvCxkMgm7PWZHsOTh4oi9URu+MqKe21uOCju5uY6osmNw8oUoz0WQPdxBD8LEhHa7d lidgOyjoK9HRSSBuRcu34Bjb9rN+sc1sk4+Pv/QPXe8DljFMmKRw5kiM1gg4zyOqWDAM ydZd+xn2+pv6XYUmsB9GCMOoR9Ls9qVbpOXS+4NEmLpw0xRuB6jjzA5zyGgC8viOUVMg JNzRozujj0OQyg+Z11xMq9Amsqb2+D2f5oYYJcYQnUfkxhnmDXwgFD4Mw05IwhtAPz0J JvUjo4kTYzEyg4UrabXjhiiFAJrxizdSeiLCg56Jt2DCEhK/XgncvLC0Xf5JAyV9YdV/ Hxsw== X-Gm-Message-State: AOUpUlF5dmRGqFYRn3My8vGnccmuLEWFKvxJAa4KOoSgp5PPluUmgIfh GkCzQ74IC4BgS3vM1TqrdBzjAJB+ X-Google-Smtp-Source: AA+uWPwdVfJhOKD60oFQKbkepAz86LZFGQU6/Ya+HV/lMKuxygJjoulEob1dgvCGHo8vuVmMh1rdqg== X-Received: by 2002:a1c:9290:: with SMTP id u138-v6mr22711199wmd.52.1534601441114; Sat, 18 Aug 2018 07:10:41 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Sat, 18 Aug 2018 16:10:30 +0200 Message-Id: <20180818141033.29752-7-pbonzini@redhat.com> In-Reply-To: <20180818141033.29752-1-pbonzini@redhat.com> References: <20180818141033.29752-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 14:10:42 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Sat, 18 Aug 2018 14:10:42 +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.79 on 10.5.11.14 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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sat, 18 Aug 2018 14:10:48 +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 Thu Mar 28 20:21:57 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 1534601723188293.94689630923676; Sat, 18 Aug 2018 07:15:23 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DB66787624; Sat, 18 Aug 2018 14:15:21 +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 CC759309128B; Sat, 18 Aug 2018 14:15:21 +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 BFECD181A12D; Sat, 18 Aug 2018 14:15:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w7IEAjEV020434 for ; Sat, 18 Aug 2018 10:10:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2583E600C2; Sat, 18 Aug 2018 14:10:45 +0000 (UTC) Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1C044600C0 for ; Sat, 18 Aug 2018 14:10:45 +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 B96D9C049E0F for ; Sat, 18 Aug 2018 14:10:43 +0000 (UTC) Received: by mail-wm0-f47.google.com with SMTP id q8-v6so9815560wmq.4 for ; Sat, 18 Aug 2018 07:10:43 -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 g2-v6sm13874652wrd.71.2018.08.18.07.10.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 18 Aug 2018 07:10:41 -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=bXrO8LOjfgasrN5bjLzR5b4n/QYA3jMXS3zHnaFqfZlNj2VGAFZMuDHd3GCpFD2VMX 25FIGMA/OLqr697kNs51Lg9xA10YTh7n+lqbT2Q2+wwz2fF2K5AoAhXZ/kFlwXS9BJ7l CAwmsvYuDjHto6vEiabnDPcptvPqWj06sg1Ce0MIyjK140pB7u6/ONINkmAEGe26ZzXQ CbR54evjICUylmadG7fHwe/VrBNif8ZniUKnKTzvhL73kiOloej92s5EjY4qxcdKjRJA jI93iH3wSKuaeMgejPEOr36MheuGmyRJDN4eAl7RCN9GI+UNerqboSaUoDHzLvMLpZBH 8zfA== 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=cEOv0c3S1hw6QlzIRAJO6oTNmSmozf7BrMylEWtmlOOOqGqxIM2W7DQ4+dZGNMM3Cz giyP8CqyIbdeWH/zBo77BhfKs3gOgRMlQR0FD2R/YKAY2xavCqV3I2neluIZPDEk9opA Mb6dpybMxMSt6DtSzh9kST4sEghZIDsI2/NJQpcmfahBnTZGfpCBs3obS0sSq/qOMYop BiRGnEtyv6BkiWKi1M0nbg1XYkh2Za++S03hTLwNpWUKNymEa9CZgWLRdEShaNT1QlGD W/z/IbqMcx9WYJ+RjOcgDUve+YqUQm/xY/LwSUEmnUQU9yEoc/9o0qNNXmq8FTawEF7y Nnjw== X-Gm-Message-State: AOUpUlELK6MhwWhNdOxFwftShQkkHuG9KgQPey7kPjmoET8Ort+Wa14/ DV0ImMd4jyjDylmnurCrPTnPr6AL X-Google-Smtp-Source: AA+uWPygiVmtwdmuxVaBfo2pc3FezuporeAyWkpFUd+RFX47CcvVsByp0uPQO8X0MO/KFu88vbUiNg== X-Received: by 2002:a1c:c7cb:: with SMTP id x194-v6mr22189414wmf.117.1534601442140; Sat, 18 Aug 2018 07:10:42 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Sat, 18 Aug 2018 16:10:31 +0200 Message-Id: <20180818141033.29752-8-pbonzini@redhat.com> In-Reply-To: <20180818141033.29752-1-pbonzini@redhat.com> References: <20180818141033.29752-1-pbonzini@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sat, 18 Aug 2018 14:10:44 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sat, 18 Aug 2018 14:10:44 +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.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sat, 18 Aug 2018 14:15:21 +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 Thu Mar 28 20:21:57 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 153460144919042.63412837715123; Sat, 18 Aug 2018 07:10:49 -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 0C87A81DF1; Sat, 18 Aug 2018 14:10:48 +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 EF6772A168; Sat, 18 Aug 2018 14:10:47 +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 E33FE180613A; Sat, 18 Aug 2018 14:10:47 +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 w7IEAki9020445 for ; Sat, 18 Aug 2018 10:10:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 11272308BDA3; Sat, 18 Aug 2018 14:10:46 +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 07402308BDA2 for ; Sat, 18 Aug 2018 14:10:45 +0000 (UTC) Received: from mail-wm0-f46.google.com (mail-wm0-f46.google.com [74.125.82.46]) (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 94EDA461CD for ; Sat, 18 Aug 2018 14:10:44 +0000 (UTC) Received: by mail-wm0-f46.google.com with SMTP id q8-v6so9815578wmq.4 for ; Sat, 18 Aug 2018 07:10:44 -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 g2-v6sm13874652wrd.71.2018.08.18.07.10.42 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 18 Aug 2018 07:10:42 -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=Aa0pd0PmIzoh7GowLoOAgq2JwM26yJG3wF0qIegpWef890irjQeERF6MMS4lmOnAfp iMKthrfON4PErRo4cwIftQgXqeyU0IVNSCi4FzlUAapzKGLfCWJx5haVsK4+NaWsmplI PZ5xi7dXPzEgJJLaAtuJ7LAYvRe+Qzu2sR40BW+Yy+HXX7it+nxlh75IofTHWRhNxVJK +OKzIEwIyBvZZwObAeu55Fn01U+qPSs8xRzlKM/t3J+j2ADY268HLBmWKimX9O2LBL3u ACr9+Kt/6rnI4+OVbKO+1xIQQihHsEVEBFuknNcXu65QVFnpKkYwyN9tKZv3Bm5k99Ps IMGQ== 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=WsdjojkteRf61e2IOZoWOKfI9/r39GLPBFVj4h9YVaq9Zv0M6lotk/PXWVZ5D8id3r j0J0ZdZIXibs1OKocul7U+5zNZKapofOyGKCgkjkKcUx9dQAMLwmx3uC6Il+3imOsjiI L3xCK03f5Q3qJgQ6B5Xy1mG6XrLTT1sRfm4ueXzQnlBzRSNFWKFmoEyUgkBZHoykC1gp 185CjEqanPXCDKxEPSWd+LheI0oETiiDjMqu//i79BfkjbUtrdDQGlkaKT6z6XqCiTf5 LA/y1J1l4DXaxYFEPuSMV5GYpJ92VHv6SnXOqUxc0qRKNghnOX+H5U9iHU7HA+954Gwh 9gWw== X-Gm-Message-State: AOUpUlFd4mJ/di+eDbQZjPSNh8TJWaOJln0mFdn6KlkpaPp/QLLOHiBJ SV7Msvw/p5z/u+vxsurW92ke00UD X-Google-Smtp-Source: AA+uWPzT38kAlbaq+o3RXNO+lgO5fGSomXsD6rWiTgdkib1akHp11AO5Iwdq4IYLU6URobP+Z97i/A== X-Received: by 2002:a1c:1f10:: with SMTP id f16-v6mr22464096wmf.112.1534601443023; Sat, 18 Aug 2018 07:10:43 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Sat, 18 Aug 2018 16:10:32 +0200 Message-Id: <20180818141033.29752-9-pbonzini@redhat.com> In-Reply-To: <20180818141033.29752-1-pbonzini@redhat.com> References: <20180818141033.29752-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 14:10:44 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sat, 18 Aug 2018 14:10:44 +0000 (UTC) for IP:'74.125.82.46' DOMAIN:'mail-wm0-f46.google.com' HELO:'mail-wm0-f46.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.46 mail-wm0-f46.google.com 74.125.82.46 mail-wm0-f46.google.com X-RedHat-Possible-Forgery: Paolo Bonzini X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 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.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 14:10:48 +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 Thu Mar 28 20:21:57 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 1534601456423979.7172664889498; Sat, 18 Aug 2018 07:10:56 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 25E893082A2D; Sat, 18 Aug 2018 14:10:55 +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 153F9627D7; Sat, 18 Aug 2018 14:10:55 +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 069D94A460; Sat, 18 Aug 2018 14:10:55 +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 w7IEArmH020485 for ; Sat, 18 Aug 2018 10:10:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7B615608EC; Sat, 18 Aug 2018 14:10:53 +0000 (UTC) Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 73A495F7C2 for ; Sat, 18 Aug 2018 14:10:53 +0000 (UTC) Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.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 D11F66412C for ; Sat, 18 Aug 2018 14:10:51 +0000 (UTC) Received: by mail-wr1-f48.google.com with SMTP id w11-v6so6776167wrc.5 for ; Sat, 18 Aug 2018 07:10: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 g2-v6sm13874652wrd.71.2018.08.18.07.10.43 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 18 Aug 2018 07:10:43 -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=sMqaUzKsTTfKhgEm9M+VFL5FS+6JEUvwWguqJo4K+AmDaTb2BVZ0f/aS3V9t6PZ0l3 BJzvASDR9iG7aXrZRqYpCYmUAr8dhQzOnFUE2NixqA8qoRx1mp1qCPs4iUprYp3Qi//X NmiT6MgJdt5NvfafmtgCdsSSkNqnzrOufvwAhDvG+u3IbRFkBV1RlquTFCrdHpx6GPos +K2ugs9ZtAUrSHNaxxK+IBzrcFk4xXPz9tx6dufEDJhKUyESTh0gJWP2CkrmQAaFRPyp TzhwGfLvZwYY4b/yZjZHxx0vNGkAJqfK/EGybQrjDZRNug6Hs+EB/UGFxnOGYat7K5My M1XQ== 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=U4yTRJivLKT5LPTOBJ4gfGguga4qT10AZt/oIMbrPlQdJguqQUfR6JBkFXBTlkIbsX TUUgTCT82M7+jSP76NcjugUJbvPDIGHUMjRp6phXRYVYTE5eqLMg6qttZM2kCmIu3SPL JNXYuEmwMyOHVuSygkEVgOP5EtSJkXOnH3Y+y+d3C3RWlDbIC6igDo7ibT+uz/GCENoa 0LackVvBmHPFtAUvtF/QGNqXHrmv+2A4eZZg9PPKQRDkEoB2mo1lwX3zAj3XfrpgSnEx o+EvpdYpw4XlcyqOhs9qxyUf3G0jUJYN2Q1Nq+xSgQROhdAlNUxEjvJjOmk2Fom4lSYJ H1CQ== X-Gm-Message-State: APzg51BlN2o/d6tfhxhjwVsMD3xJBIYCCU2DRmi4l0xgAoINYm4V2coO y8ICgGqMJCrsCPBMlaIbb5fnWyhX X-Google-Smtp-Source: ANB0VdZxakxWZMbiIe/Qb5F4aXh468cRv0wA5KivjqCjWo+evrBOgXT6c0LYjflTYllC3cHZvF+MCQ== X-Received: by 2002:adf:a292:: with SMTP id s18-v6mr456403wra.100.1534601450006; Sat, 18 Aug 2018 07:10:50 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Sat, 18 Aug 2018 16:10:33 +0200 Message-Id: <20180818141033.29752-10-pbonzini@redhat.com> In-Reply-To: <20180818141033.29752-1-pbonzini@redhat.com> References: <20180818141033.29752-1-pbonzini@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Sat, 18 Aug 2018 14:10:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Sat, 18 Aug 2018 14:10:52 +0000 (UTC) for IP:'209.85.221.48' DOMAIN:'mail-wr1-f48.google.com' HELO:'mail-wr1-f48.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.48 mail-wr1-f48.google.com 209.85.221.48 mail-wr1-f48.google.com X-RedHat-Possible-Forgery: Paolo Bonzini X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Sat, 18 Aug 2018 14:10:55 +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